libebook_utils.h Source File documentation

libebook_utils.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /*
3 * This file is part of the libe-book project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9
10 #ifndef LIBEBOOK_UTILS_H_INCLUDED
11 #define LIBEBOOK_UTILS_H_INCLUDED
12
13 #include <string>
14
15 #include <boost/shared_ptr.hpp>
16
17 #include <librevenge-stream/librevenge-stream.h>
18 #include <librevenge/librevenge.h>
19
20 #ifdef _MSC_VER
21
22 typedef unsigned char uint8_t;
23 typedef unsigned short uint16_t;
24 typedef short int16_t;
25 typedef unsigned uint32_t;
26 typedef int int32_t;
27 typedef unsigned __int64 uint64_t;
28 typedef __int64 int64_t;
29
30 #else
31
32 #ifdef HAVE_CONFIG_H
33
34 #include <config.h>
35
36 #ifdef HAVE_STDINT_H
37 #include <stdint.h>
38 #endif
39
40 #ifdef HAVE_INTTYPES_H
41 #include <inttypes.h>
42 #endif
43
44 #else
45
46 // assume that the headers are there inside LibreOffice build when no HAVE_CONFIG_H is defined
47 #include <stdint.h>
48 #include <inttypes.h>
49
50 #endif
51
52 #endif
53
54 // debug message includes source file and line number
55 //#define VERBOSE_DEBUG 1
56
57 // do nothing with debug messages in a release compile
58 #ifdef DEBUG
59
60 namespace libebook
61 {
62 void debugPrint(const char *format, ...);
63 }
64
65 #ifdef VERBOSE_DEBUG
66 #define EBOOK_DEBUG_MSG(M) libebook::debugPrint("%15s:%5d: ", __FILE__, __LINE__); libebook::debugPrint M
67 #define EBOOK_DEBUG(M) M
68 #else
69 #define EBOOK_DEBUG_MSG(M) libebook::debugPrint M
70 #define EBOOK_DEBUG(M) M
71 #endif
72 #else
73 #define EBOOK_DEBUG_MSG(M)
74 #define EBOOK_DEBUG(M)
75 #endif
76
77 #define EBOOK_NUM_ELEMENTS(array) sizeof(array)/sizeof(array[0])
78
79 namespace libebook
80 {
81
82 typedef boost::shared_ptr<librevenge::RVNGInputStream> RVNGInputStreamPtr_t;
83
84 struct EBOOKDummyDeleter
85 {
86 void operator()(void *) {}
87 };
88
89 uint8_t readU8(librevenge::RVNGInputStream *input, bool = false);
90 uint16_t readU16(librevenge::RVNGInputStream *input, bool bigEndian=false);
91 uint32_t readU32(librevenge::RVNGInputStream *input, bool bigEndian=false);
92 uint64_t readU64(librevenge::RVNGInputStream *input, bool bigEndian=false);
93
94 const unsigned char *readNBytes(librevenge::RVNGInputStream *input, unsigned long numBytes);
95
96 std::string readCString(librevenge::RVNGInputStream *input);
97 std::string readPascalString(librevenge::RVNGInputStream *input);
98
99 void skip(librevenge::RVNGInputStream *input, unsigned long numBytes);
100
101 void seek(librevenge::RVNGInputStream *input, unsigned long pos);
102 void seekRelative(librevenge::RVNGInputStream *input, long pos);
103
104 unsigned long getRemainingLength(librevenge::RVNGInputStream *input);
105
106 uint8_t readU8(boost::shared_ptr<librevenge::RVNGInputStream> input, bool = false);
107 uint16_t readU16(boost::shared_ptr<librevenge::RVNGInputStream> input, bool bigEndian=false);
108 uint32_t readU32(boost::shared_ptr<librevenge::RVNGInputStream> input, bool bigEndian=false);
109 uint64_t readU64(boost::shared_ptr<librevenge::RVNGInputStream> input, bool bigEndian=false);
110
111 const unsigned char *readNBytes(boost::shared_ptr<librevenge::RVNGInputStream> input, unsigned long numBytes);
112
113 std::string readCString(boost::shared_ptr<librevenge::RVNGInputStream> input);
114 std::string readPascalString(boost::shared_ptr<librevenge::RVNGInputStream> input);
115
116 void skip(boost::shared_ptr<librevenge::RVNGInputStream> input, unsigned long numBytes);
117
118 void seek(boost::shared_ptr<librevenge::RVNGInputStream> input, unsigned long pos);
119 void seekRelative(boost::shared_ptr<librevenge::RVNGInputStream> input, long pos);
120
121 unsigned long getRemainingLength(boost::shared_ptr<librevenge::RVNGInputStream> input);
122
123 bool findSubStreamByExt(const RVNGInputStreamPtr_t &input, const std::string &ext, unsigned &id);
124
125 class EndOfStreamException
126 {
127 public:
128 EndOfStreamException();
129 };
130
131 class GenericException
132 {
133 };
134
135 // parser exceptions
136
137 class FileAccessError
138 {
139 };
140
141 class PackageError
142 {
143 };
144
145 class ParseError
146 {
147 };
148
149 class PasswordMismatch
150 {
151 };
152
153 class UnsupportedEncryption
154 {
155 };
156
157 class UnsupportedFormat
158 {
159 };
160
161 } // namespace libebook
162
163 #endif // LIBEBOOK_UTILS_H_INCLUDED
164 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
libebook::readU16
uint16_t readU16(librevenge::RVNGInputStream *input, bool bigEndian)
Definition: libebook_utils.cpp:55
libebook::EBOOKHTMLToken::input
Definition: EBOOKHTMLToken.h:91
libebook::skip
void skip(librevenge::RVNGInputStream *input, unsigned long numBytes)
Definition: libebook_utils.cpp:143
libebook::UnsupportedFormat
Definition: libebook_utils.h:157
libebook::GenericException
Definition: libebook_utils.h:131
libebook::RVNGInputStreamPtr_t
boost::shared_ptr< librevenge::RVNGInputStream > RVNGInputStreamPtr_t
Definition: libebook_utils.h:82
libebook::EndOfStreamException
Definition: libebook_utils.h:125
libebook::readU32
uint32_t readU32(librevenge::RVNGInputStream *input, bool bigEndian)
Definition: libebook_utils.cpp:71
libebook::readCString
string readCString(librevenge::RVNGInputStream *input)
Definition: libebook_utils.cpp:116
libebook::readNBytes
const unsigned char * readNBytes(librevenge::RVNGInputStream *const input, const unsigned long numBytes)
Definition: libebook_utils.cpp:103
libebook::PackageError
Definition: libebook_utils.h:141
libebook::readU8
uint8_t readU8(librevenge::RVNGInputStream *input, bool)
Definition: libebook_utils.cpp:43
libebook::readU64
uint64_t readU64(librevenge::RVNGInputStream *input, bool bigEndian)
Definition: libebook_utils.cpp:87
libebook::EBOOKDummyDeleter
Definition: libebook_utils.h:84
libebook::getRemainingLength
unsigned long getRemainingLength(librevenge::RVNGInputStream *const input)
Definition: libebook_utils.cpp:168
libebook::PasswordMismatch
Definition: libebook_utils.h:149
libebook::FileAccessError
Definition: libebook_utils.h:137
libebook::findSubStreamByExt
bool findSubStreamByExt(const RVNGInputStreamPtr_t &input, const std::string &ext, unsigned &id)
Definition: libebook_utils.cpp:250
libebook::readPascalString
string readPascalString(librevenge::RVNGInputStream *input)
Definition: libebook_utils.cpp:131
libebook::ParseError
Definition: libebook_utils.h:145
libebook::debugPrint
void debugPrint(const char *format,...)
Definition: libebook_utils.cpp:35
libebook::seek
void seek(librevenge::RVNGInputStream *const input, const unsigned long pos)
Definition: libebook_utils.cpp:150
libebook::EBOOKOPFToken::format
Definition: EBOOKOPFToken.h:56
libebook::seekRelative
void seekRelative(librevenge::RVNGInputStream *const input, const long pos)
Definition: libebook_utils.cpp:159
libebook
Definition: CHMParser.cpp:20
libebook::UnsupportedEncryption
Definition: libebook_utils.h:153
libebook::EBOOKDummyDeleter::operator()
void operator()(void *)
Definition: libebook_utils.h:86