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 /* libe-book
3  * Version: MPL 2.0 / LGPLv2.1+
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  * Alternatively, the contents of this file may be used under the terms
10  * of the GNU Lesser General Public License Version 2.1 or later
11  * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
12  * applicable instead of those above.
13  *
14  * For further information visit http://libebook.sourceforge.net
15  */
16 
17 #ifndef LIBEBOOK_UTILS_H_INCLUDED
18 #define LIBEBOOK_UTILS_H_INCLUDED
19 
20 #ifdef DEBUG
21 #include <cstdio>
22 #endif
23 
24 #include <string>
25 
26 #include <boost/shared_ptr.hpp>
27 
28 #include <libwpd-stream/libwpd-stream.h>
29 #include <libwpd/libwpd.h>
30 
31 #ifdef _MSC_VER
32 
33 typedef unsigned char uint8_t;
34 typedef unsigned short uint16_t;
35 typedef short int16_t;
36 typedef unsigned uint32_t;
37 typedef int int32_t;
38 typedef unsigned __int64 uint64_t;
39 typedef __int64 int64_t;
40 
41 #else
42 
43 #ifdef HAVE_CONFIG_H
44 
45 #include <config.h>
46 
47 #ifdef HAVE_STDINT_H
48 #include <stdint.h>
49 #endif
50 
51 #ifdef HAVE_INTTYPES_H
52 #include <inttypes.h>
53 #endif
54 
55 #else
56 
57 // assume that the headers are there inside LibreOffice build when no HAVE_CONFIG_H is defined
58 #include <stdint.h>
59 #include <inttypes.h>
60 
61 #endif
62 
63 #endif
64 
65 // debug message includes source file and line number
66 //#define VERBOSE_DEBUG 1
67 
68 // do nothing with debug messages in a release compile
69 #ifdef DEBUG
70 #ifdef VERBOSE_DEBUG
71 #define EBOOK_DEBUG_MSG(M) std::printf("%15s:%5d: ", __FILE__, __LINE__); std::printf M
72 #define EBOOK_DEBUG(M) M
73 #else
74 #define EBOOK_DEBUG_MSG(M) std::printf M
75 #define EBOOK_DEBUG(M) M
76 #endif
77 #else
78 #define EBOOK_DEBUG_MSG(M)
79 #define EBOOK_DEBUG(M)
80 #endif
81 
82 #define EBOOK_NUM_ELEMENTS(array) sizeof(array)/sizeof(array[0])
83 
84 namespace libebook
85 {
86 
87 uint8_t readU8(WPXInputStream *input, bool = false);
88 uint16_t readU16(WPXInputStream *input, bool bigEndian=false);
89 uint32_t readU32(WPXInputStream *input, bool bigEndian=false);
90 uint64_t readU64(WPXInputStream *input, bool bigEndian=false);
91 
92 const unsigned char *readNBytes(WPXInputStream *input, unsigned long numBytes);
93 
94 std::string readCString(WPXInputStream *input);
95 std::string readPascalString(WPXInputStream *input);
96 
97 void skip(WPXInputStream *input, unsigned long numBytes);
98 
99 void seek(WPXInputStream *input, unsigned long pos);
100 void seekRelative(WPXInputStream *input, long pos);
101 
102 unsigned long getLength(WPXInputStream *input);
103 
104 uint8_t readU8(boost::shared_ptr<WPXInputStream> input, bool = false);
105 uint16_t readU16(boost::shared_ptr<WPXInputStream> input, bool bigEndian=false);
106 uint32_t readU32(boost::shared_ptr<WPXInputStream> input, bool bigEndian=false);
107 uint64_t readU64(boost::shared_ptr<WPXInputStream> input, bool bigEndian=false);
108 
109 const unsigned char *readNBytes(boost::shared_ptr<WPXInputStream> input, unsigned long numBytes);
110 
111 std::string readCString(boost::shared_ptr<WPXInputStream> input);
112 std::string readPascalString(boost::shared_ptr<WPXInputStream> input);
113 
114 void skip(boost::shared_ptr<WPXInputStream> input, unsigned long numBytes);
115 
116 void seek(boost::shared_ptr<WPXInputStream> input, unsigned long pos);
117 void seekRelative(boost::shared_ptr<WPXInputStream> input, long pos);
118 
119 unsigned long getLength(boost::shared_ptr<WPXInputStream> input);
120 
122 {
123 public:
125 };
126 
128 {
129 };
130 
131 } // namespace libebook
132 
133 #endif // LIBEBOOK_UTILS_H_INCLUDED
134 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
Definition: libebook_utils.h:127
Definition: libebook_utils.h:121
unsigned long getLength(WPXInputStream *const input)
Definition: libebook_utils.cpp:162
void seekRelative(WPXInputStream *const input, const long pos)
Definition: libebook_utils.cpp:154
uint64_t readU64(WPXInputStream *input, bool bigEndian)
Definition: libebook_utils.cpp:83
EndOfStreamException()
Definition: libebook_utils.cpp:241
string readCString(WPXInputStream *input)
Definition: libebook_utils.cpp:112
uint32_t readU32(WPXInputStream *input, bool bigEndian)
Definition: libebook_utils.cpp:67
const unsigned char * readNBytes(WPXInputStream *const input, const unsigned long numBytes)
Definition: libebook_utils.cpp:99
uint16_t readU16(WPXInputStream *input, bool bigEndian)
Definition: libebook_utils.cpp:51
void skip(WPXInputStream *input, unsigned long numBytes)
Definition: libebook_utils.cpp:139
void seek(WPXInputStream *const input, const unsigned long pos)
Definition: libebook_utils.cpp:146
uint8_t readU8(WPXInputStream *input, bool)
Definition: libebook_utils.cpp:39
string readPascalString(WPXInputStream *input)
Definition: libebook_utils.cpp:127

Generated for libe-book by doxygen 1.8.5