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
34namespace libebook
35{
36void 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
51namespace libebook
52{
53
54typedef std::shared_ptr<librevenge::RVNGInputStream> RVNGInputStreamPtr_t;
55
57{
58 void operator()(void *) {}
59};
60
61// The result points at input but owns nothing, so the caller keeps input alive.
62inline RVNGInputStreamPtr_t makeUnownedStreamPtr(librevenge::RVNGInputStream *const input)
63{
65}
66
67uint8_t readU8(librevenge::RVNGInputStream *input, bool = false);
68uint16_t readU16(librevenge::RVNGInputStream *input, bool bigEndian=false);
69uint32_t readU32(librevenge::RVNGInputStream *input, bool bigEndian=false);
70uint64_t readU64(librevenge::RVNGInputStream *input, bool bigEndian=false);
71
72const unsigned char *readNBytes(librevenge::RVNGInputStream *input, unsigned long numBytes);
73
74std::string readCString(librevenge::RVNGInputStream *input);
75std::string readPascalString(librevenge::RVNGInputStream *input);
76
77void skip(librevenge::RVNGInputStream *input, unsigned long numBytes);
78
79void seek(librevenge::RVNGInputStream *input, unsigned long pos);
80void seekRelative(librevenge::RVNGInputStream *input, long pos);
81
82unsigned long getRemainingLength(librevenge::RVNGInputStream *input);
83
84uint8_t readU8(std::shared_ptr<librevenge::RVNGInputStream> input, bool = false);
85uint16_t readU16(std::shared_ptr<librevenge::RVNGInputStream> input, bool bigEndian=false);
86uint32_t readU32(std::shared_ptr<librevenge::RVNGInputStream> input, bool bigEndian=false);
87uint64_t readU64(std::shared_ptr<librevenge::RVNGInputStream> input, bool bigEndian=false);
88
89const unsigned char *readNBytes(std::shared_ptr<librevenge::RVNGInputStream> input, unsigned long numBytes);
90
91std::string readCString(std::shared_ptr<librevenge::RVNGInputStream> input);
92std::string readPascalString(std::shared_ptr<librevenge::RVNGInputStream> input);
93
94void skip(std::shared_ptr<librevenge::RVNGInputStream> input, unsigned long numBytes);
95
96void seek(std::shared_ptr<librevenge::RVNGInputStream> input, unsigned long pos);
97void seekRelative(std::shared_ptr<librevenge::RVNGInputStream> input, long pos);
98
99unsigned long getRemainingLength(std::shared_ptr<librevenge::RVNGInputStream> input);
100
101bool findSubStreamByExt(const RVNGInputStreamPtr_t &input, const std::string &ext, unsigned &id);
102
103librevenge::RVNGPropertyList getDefaultPageSpanPropList();
104
106{
107public:
109};
110
112{
113};
114
115// parser exceptions
116
118{
119};
120
122{
123};
124
126{
127};
128
130{
131};
132
134{
135};
136
138{
139};
140
141} // namespace libebook
142
143#endif // LIBEBOOK_UTILS_H_INCLUDED
144/* vim:set shiftwidth=2 softtabstop=2 expandtab: */
EndOfStreamException()
Definition libebook_utils.cpp:275
Definition libebook_utils.h:118
Definition libebook_utils.h:112
Definition libebook_utils.h:122
Definition libebook_utils.h:126
Definition libebook_utils.h:130
Definition libebook_utils.h:134
Definition libebook_utils.h:138
@ input
Definition EBOOKHTMLToken.h:89
@ format
Definition EBOOKOPFToken.h:54
Definition BBeBCollector.cpp:20
string readCString(librevenge::RVNGInputStream *input)
Definition libebook_utils.cpp:118
bool findSubStreamByExt(const RVNGInputStreamPtr_t &input, const std::string &ext, unsigned &id)
Definition libebook_utils.cpp:245
librevenge::RVNGPropertyList getDefaultPageSpanPropList()
Definition libebook_utils.cpp:265
uint8_t readU8(librevenge::RVNGInputStream *input, bool)
Definition libebook_utils.cpp:45
RVNGInputStreamPtr_t makeUnownedStreamPtr(librevenge::RVNGInputStream *const input)
Definition libebook_utils.h:62
void seek(librevenge::RVNGInputStream *const input, const unsigned long pos)
Definition libebook_utils.cpp:152
unsigned long getRemainingLength(librevenge::RVNGInputStream *const input)
Definition libebook_utils.cpp:170
void skip(librevenge::RVNGInputStream *input, unsigned long numBytes)
Definition libebook_utils.cpp:145
std::shared_ptr< librevenge::RVNGInputStream > RVNGInputStreamPtr_t
Definition libebook_utils.h:54
string readPascalString(librevenge::RVNGInputStream *input)
Definition libebook_utils.cpp:133
uint64_t readU64(librevenge::RVNGInputStream *input, bool bigEndian)
Definition libebook_utils.cpp:89
uint16_t readU16(librevenge::RVNGInputStream *input, bool bigEndian)
Definition libebook_utils.cpp:57
const unsigned char * readNBytes(librevenge::RVNGInputStream *const input, const unsigned long numBytes)
Definition libebook_utils.cpp:105
uint32_t readU32(librevenge::RVNGInputStream *input, bool bigEndian)
Definition libebook_utils.cpp:73
void seekRelative(librevenge::RVNGInputStream *const input, const long pos)
Definition libebook_utils.cpp:161
Definition libebook_utils.h:57
void operator()(void *)
Definition libebook_utils.h:58

Generated for libe-book by doxygen 1.18.0