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 #ifdef HAVE_CONFIG_H
14 #include "config.h"
15 #endif
16
17 #include <memory>
18 #include <string>
19
20 #include <boost/cstdint.hpp>
21
22 #include <librevenge-stream/librevenge-stream.h>
23 #include <librevenge/librevenge.h>
24
25 // do nothing with debug messages in a release compile
26 #ifdef DEBUG
27
28 #if defined(HAVE_FUNC_ATTRIBUTE_FORMAT)
29 #define EBOOK_ATTRIBUTE_PRINTF(fmt, arg) __attribute__((format(printf, fmt, arg)))
30 #else
31 #define EBOOK_ATTRIBUTE_PRINTF(fmt, arg)
32 #endif
33
34 namespace libebook
35 {
36 void debugPrint(const char *format, ...) EBOOK_ATTRIBUTE_PRINTF(1, 2);
37 }
38
39 #define EBOOK_DEBUG_MSG(M) libebook::debugPrint M
40 #define EBOOK_DEBUG(M) M
41
42 #else
43
44 #define EBOOK_DEBUG_MSG(M)
45 #define EBOOK_DEBUG(M)
46
47 #endif
48
49 #define EBOOK_NUM_ELEMENTS(array) sizeof(array)/sizeof(array[0])
50
51 namespace libebook
52 {
53
54 typedef std::shared_ptr<librevenge::RVNGInputStream> RVNGInputStreamPtr_t;
55
56 struct EBOOKDummyDeleter
57 {
58 void operator()(void *) {}
59 };
60
61 uint8_t readU8(librevenge::RVNGInputStream *input, bool = false);
62 uint16_t readU16(librevenge::RVNGInputStream *input, bool bigEndian=false);
63 uint32_t readU32(librevenge::RVNGInputStream *input, bool bigEndian=false);
64 uint64_t readU64(librevenge::RVNGInputStream *input, bool bigEndian=false);
65
66 const unsigned char *readNBytes(librevenge::RVNGInputStream *input, unsigned long numBytes);
67
68 std::string readCString(librevenge::RVNGInputStream *input);
69 std::string readPascalString(librevenge::RVNGInputStream *input);
70
71 void skip(librevenge::RVNGInputStream *input, unsigned long numBytes);
72
73 void seek(librevenge::RVNGInputStream *input, unsigned long pos);
74 void seekRelative(librevenge::RVNGInputStream *input, long pos);
75
76 unsigned long getRemainingLength(librevenge::RVNGInputStream *input);
77
78 uint8_t readU8(std::shared_ptr<librevenge::RVNGInputStream> input, bool = false);
79 uint16_t readU16(std::shared_ptr<librevenge::RVNGInputStream> input, bool bigEndian=false);
80 uint32_t readU32(std::shared_ptr<librevenge::RVNGInputStream> input, bool bigEndian=false);
81 uint64_t readU64(std::shared_ptr<librevenge::RVNGInputStream> input, bool bigEndian=false);
82
83 const unsigned char *readNBytes(std::shared_ptr<librevenge::RVNGInputStream> input, unsigned long numBytes);
84
85 std::string readCString(std::shared_ptr<librevenge::RVNGInputStream> input);
86 std::string readPascalString(std::shared_ptr<librevenge::RVNGInputStream> input);
87
88 void skip(std::shared_ptr<librevenge::RVNGInputStream> input, unsigned long numBytes);
89
90 void seek(std::shared_ptr<librevenge::RVNGInputStream> input, unsigned long pos);
91 void seekRelative(std::shared_ptr<librevenge::RVNGInputStream> input, long pos);
92
93 unsigned long getRemainingLength(std::shared_ptr<librevenge::RVNGInputStream> input);
94
95 bool findSubStreamByExt(const RVNGInputStreamPtr_t &input, const std::string &ext, unsigned &id);
96
97 librevenge::RVNGPropertyList getDefaultPageSpanPropList();
98
99 class EndOfStreamException
100 {
101 public:
102 EndOfStreamException();
103 };
104
105 class GenericException
106 {
107 };
108
109 // parser exceptions
110
111 class FileAccessError
112 {
113 };
114
115 class PackageError
116 {
117 };
118
119 class ParseError
120 {
121 };
122
123 class PasswordMismatch
124 {
125 };
126
127 class UnsupportedEncryption
128 {
129 };
130
131 class UnsupportedFormat
132 {
133 };
134
135 } // namespace libebook
136
137 #endif // LIBEBOOK_UTILS_H_INCLUDED
138 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
libebook::readPascalString
string readPascalString(librevenge::RVNGInputStream *input)
Definition: libebook_utils.cpp:133
libebook::seekRelative
void seekRelative(librevenge::RVNGInputStream *const input, const long pos)
Definition: libebook_utils.cpp:161
libebook::getRemainingLength
unsigned long getRemainingLength(librevenge::RVNGInputStream *const input)
Definition: libebook_utils.cpp:170
libebook::RVNGInputStreamPtr_t
std::shared_ptr< librevenge::RVNGInputStream > RVNGInputStreamPtr_t
Definition: libebook_utils.h:54
libebook::EBOOKDummyDeleter
Definition: libebook_utils.h:57
libebook
Definition: BBeBCollector.cpp:19
libebook::EndOfStreamException::EndOfStreamException
EndOfStreamException()
Definition: libebook_utils.cpp:275
libebook_utils.h
libebook::getDefaultPageSpanPropList
librevenge::RVNGPropertyList getDefaultPageSpanPropList()
Definition: libebook_utils.cpp:265
libebook::readNBytes
const unsigned char * readNBytes(librevenge::RVNGInputStream *const input, const unsigned long numBytes)
Definition: libebook_utils.cpp:105
libebook::EBOOKDummyDeleter::operator()
void operator()(void *)
Definition: libebook_utils.h:58
libebook::EBOOKHTMLToken::i
@ i
Definition: EBOOKHTMLToken.h:86
libebook::PackageError
Definition: libebook_utils.h:116
libebook::seek
void seek(librevenge::RVNGInputStream *const input, const unsigned long pos)
Definition: libebook_utils.cpp:152
libebook::FileAccessError
Definition: libebook_utils.h:112
libebook::UnsupportedFormat
Definition: libebook_utils.h:132
str
const char * str
Definition: EBOOKHTMLParser.cpp:46
libebook::EBOOKHTMLToken::input
@ input
Definition: EBOOKHTMLToken.h:89
libebook::readU16
uint16_t readU16(librevenge::RVNGInputStream *input, bool bigEndian)
Definition: libebook_utils.cpp:57
libebook::EBOOKHTMLToken::p
@ p
Definition: EBOOKHTMLToken.h:116
libebook::readU8
uint8_t readU8(librevenge::RVNGInputStream *input, bool)
Definition: libebook_utils.cpp:45
libebook::EndOfStreamException
Definition: libebook_utils.h:100
libebook::readU32
uint32_t readU32(librevenge::RVNGInputStream *input, bool bigEndian)
Definition: libebook_utils.cpp:73
name
string name
Definition: HTMLHelpStream.cpp:80
libebook::PasswordMismatch
Definition: libebook_utils.h:124
libebook::ParseError
Definition: libebook_utils.h:120
libebook::EBOOKOPFToken::format
@ format
Definition: EBOOKOPFToken.h:54
EBOOK_DEBUG_MSG
#define EBOOK_DEBUG_MSG(M)
Definition: libebook_utils.h:44
libebook::UnsupportedEncryption
Definition: libebook_utils.h:128
libebook::EBOOKHTMLToken::s
@ s
Definition: EBOOKHTMLToken.h:125
libebook::skip
void skip(librevenge::RVNGInputStream *input, unsigned long numBytes)
Definition: libebook_utils.cpp:145
libebook::findSubStreamByExt
bool findSubStreamByExt(const RVNGInputStreamPtr_t &input, const std::string &ext, unsigned &id)
Definition: libebook_utils.cpp:245
libebook::GenericException
Definition: libebook_utils.h:106
libebook::readU64
uint64_t readU64(librevenge::RVNGInputStream *input, bool bigEndian)
Definition: libebook_utils.cpp:89
length
unsigned length
Definition: SoftBookParser.cpp:73
libebook::readCString
string readCString(librevenge::RVNGInputStream *input)
Definition: libebook_utils.cpp:118