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 #ifdef DEBUG
14 #include <cstdio>
15 #endif
16 
17 #include <string>
18 
19 #include <boost/shared_ptr.hpp>
20 
21 #include <librevenge-stream/librevenge-stream.h>
22 #include <librevenge/librevenge.h>
23 
24 #ifdef _MSC_VER
25 
26 typedef unsigned char uint8_t;
27 typedef unsigned short uint16_t;
28 typedef short int16_t;
29 typedef unsigned uint32_t;
30 typedef int int32_t;
31 typedef unsigned __int64 uint64_t;
32 typedef __int64 int64_t;
33 
34 #else
35 
36 #ifdef HAVE_CONFIG_H
37 
38 #include <config.h>
39 
40 #ifdef HAVE_STDINT_H
41 #include <stdint.h>
42 #endif
43 
44 #ifdef HAVE_INTTYPES_H
45 #include <inttypes.h>
46 #endif
47 
48 #else
49 
50 // assume that the headers are there inside LibreOffice build when no HAVE_CONFIG_H is defined
51 #include <stdint.h>
52 #include <inttypes.h>
53 
54 #endif
55 
56 #endif
57 
58 // debug message includes source file and line number
59 //#define VERBOSE_DEBUG 1
60 
61 // do nothing with debug messages in a release compile
62 #ifdef DEBUG
63 #ifdef VERBOSE_DEBUG
64 #define EBOOK_DEBUG_MSG(M) std::printf("%15s:%5d: ", __FILE__, __LINE__); std::printf M
65 #define EBOOK_DEBUG(M) M
66 #else
67 #define EBOOK_DEBUG_MSG(M) std::printf M
68 #define EBOOK_DEBUG(M) M
69 #endif
70 #else
71 #define EBOOK_DEBUG_MSG(M)
72 #define EBOOK_DEBUG(M)
73 #endif
74 
75 #define EBOOK_NUM_ELEMENTS(array) sizeof(array)/sizeof(array[0])
76 
77 namespace libebook
78 {
79 
80 typedef boost::shared_ptr<librevenge::RVNGInputStream> RVNGInputStreamPtr_t;
81 
83 {
84  void operator()(void *) {}
85 };
86 
87 uint8_t readU8(librevenge::RVNGInputStream *input, bool = false);
88 uint16_t readU16(librevenge::RVNGInputStream *input, bool bigEndian=false);
89 uint32_t readU32(librevenge::RVNGInputStream *input, bool bigEndian=false);
90 uint64_t readU64(librevenge::RVNGInputStream *input, bool bigEndian=false);
91 
92 const unsigned char *readNBytes(librevenge::RVNGInputStream *input, unsigned long numBytes);
93 
94 std::string readCString(librevenge::RVNGInputStream *input);
95 std::string readPascalString(librevenge::RVNGInputStream *input);
96 
97 void skip(librevenge::RVNGInputStream *input, unsigned long numBytes);
98 
99 void seek(librevenge::RVNGInputStream *input, unsigned long pos);
100 void seekRelative(librevenge::RVNGInputStream *input, long pos);
101 
102 unsigned long getLength(librevenge::RVNGInputStream *input);
103 
104 uint8_t readU8(boost::shared_ptr<librevenge::RVNGInputStream> input, bool = false);
105 uint16_t readU16(boost::shared_ptr<librevenge::RVNGInputStream> input, bool bigEndian=false);
106 uint32_t readU32(boost::shared_ptr<librevenge::RVNGInputStream> input, bool bigEndian=false);
107 uint64_t readU64(boost::shared_ptr<librevenge::RVNGInputStream> input, bool bigEndian=false);
108 
109 const unsigned char *readNBytes(boost::shared_ptr<librevenge::RVNGInputStream> input, unsigned long numBytes);
110 
111 std::string readCString(boost::shared_ptr<librevenge::RVNGInputStream> input);
112 std::string readPascalString(boost::shared_ptr<librevenge::RVNGInputStream> input);
113 
114 void skip(boost::shared_ptr<librevenge::RVNGInputStream> input, unsigned long numBytes);
115 
116 void seek(boost::shared_ptr<librevenge::RVNGInputStream> input, unsigned long pos);
117 void seekRelative(boost::shared_ptr<librevenge::RVNGInputStream> input, long pos);
118 
119 unsigned long getLength(boost::shared_ptr<librevenge::RVNGInputStream> input);
120 
122 {
123 public:
125 };
126 
128 {
129 };
130 
131 // parser exceptions
132 
134 {
135 };
136 
138 {
139 };
140 
142 {
143 };
144 
146 {
147 };
148 
150 {
151 };
152 
154 {
155 };
156 
157 } // namespace libebook
158 
159 #endif // LIBEBOOK_UTILS_H_INCLUDED
160 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
uint16_t readU16(librevenge::RVNGInputStream *input, bool bigEndian)
Definition: libebook_utils.cpp:44
Definition: EBOOKHTMLToken.h:91
void skip(librevenge::RVNGInputStream *input, unsigned long numBytes)
Definition: libebook_utils.cpp:132
Definition: libebook_utils.h:153
Definition: libebook_utils.h:127
boost::shared_ptr< librevenge::RVNGInputStream > RVNGInputStreamPtr_t
Definition: libebook_utils.h:80
Definition: libebook_utils.h:121
uint32_t readU32(librevenge::RVNGInputStream *input, bool bigEndian)
Definition: libebook_utils.cpp:60
string readCString(librevenge::RVNGInputStream *input)
Definition: libebook_utils.cpp:105
const unsigned char * readNBytes(librevenge::RVNGInputStream *const input, const unsigned long numBytes)
Definition: libebook_utils.cpp:92
Definition: libebook_utils.h:137
uint8_t readU8(librevenge::RVNGInputStream *input, bool)
Definition: libebook_utils.cpp:32
EndOfStreamException()
Definition: libebook_utils.cpp:237
uint64_t readU64(librevenge::RVNGInputStream *input, bool bigEndian)
Definition: libebook_utils.cpp:76
Definition: libebook_utils.h:82
unsigned long getLength(librevenge::RVNGInputStream *const input)
Definition: libebook_utils.cpp:157
Definition: libebook_utils.h:145
Definition: libebook_utils.h:133
string readPascalString(librevenge::RVNGInputStream *input)
Definition: libebook_utils.cpp:120
Definition: libebook_utils.h:141
void seek(librevenge::RVNGInputStream *const input, const unsigned long pos)
Definition: libebook_utils.cpp:139
void seekRelative(librevenge::RVNGInputStream *const input, const long pos)
Definition: libebook_utils.cpp:148
Definition: CHMParser.cpp:20
Definition: libebook_utils.h:149
void operator()(void *)
Definition: libebook_utils.h:84

Generated for libe-book by doxygen 1.8.8