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
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
54 typedef std::shared_ptr<librevenge::RVNGInputStream> RVNGInputStreamPtr_t;
55
56 struct EBOOKDummyDeleter
57{
58 void operator()(void *) {}
59};
60
61uint8_t readU8(librevenge::RVNGInputStream *input, bool = false);
62uint16_t readU16(librevenge::RVNGInputStream *input, bool bigEndian=false);
63uint32_t readU32(librevenge::RVNGInputStream *input, bool bigEndian=false);
64uint64_t readU64(librevenge::RVNGInputStream *input, bool bigEndian=false);
65
66const unsigned char *readNBytes(librevenge::RVNGInputStream *input, unsigned long numBytes);
67
68std::string readCString(librevenge::RVNGInputStream *input);
69std::string readPascalString(librevenge::RVNGInputStream *input);
70
71void skip(librevenge::RVNGInputStream *input, unsigned long numBytes);
72
73void seek(librevenge::RVNGInputStream *input, unsigned long pos);
74void seekRelative(librevenge::RVNGInputStream *input, long pos);
75
76unsigned long getRemainingLength(librevenge::RVNGInputStream *input);
77
78uint8_t readU8(std::shared_ptr<librevenge::RVNGInputStream> input, bool = false);
79uint16_t readU16(std::shared_ptr<librevenge::RVNGInputStream> input, bool bigEndian=false);
80uint32_t readU32(std::shared_ptr<librevenge::RVNGInputStream> input, bool bigEndian=false);
81uint64_t readU64(std::shared_ptr<librevenge::RVNGInputStream> input, bool bigEndian=false);
82
83const unsigned char *readNBytes(std::shared_ptr<librevenge::RVNGInputStream> input, unsigned long numBytes);
84
85std::string readCString(std::shared_ptr<librevenge::RVNGInputStream> input);
86std::string readPascalString(std::shared_ptr<librevenge::RVNGInputStream> input);
87
88void skip(std::shared_ptr<librevenge::RVNGInputStream> input, unsigned long numBytes);
89
90void seek(std::shared_ptr<librevenge::RVNGInputStream> input, unsigned long pos);
91void seekRelative(std::shared_ptr<librevenge::RVNGInputStream> input, long pos);
92
93unsigned long getRemainingLength(std::shared_ptr<librevenge::RVNGInputStream> input);
94
95bool findSubStreamByExt(const RVNGInputStreamPtr_t &input, const std::string &ext, unsigned &id);
96
97librevenge::RVNGPropertyList getDefaultPageSpanPropList();
98
99 class EndOfStreamException
100{
101public:
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::EndOfStreamException
Definition: libebook_utils.h:100
libebook::EndOfStreamException::EndOfStreamException
EndOfStreamException()
Definition: libebook_utils.cpp:275
libebook::FileAccessError
Definition: libebook_utils.h:112
libebook::GenericException
Definition: libebook_utils.h:106
libebook::PackageError
Definition: libebook_utils.h:116
libebook::ParseError
Definition: libebook_utils.h:120
libebook::PasswordMismatch
Definition: libebook_utils.h:124
libebook::UnsupportedEncryption
Definition: libebook_utils.h:128
libebook::UnsupportedFormat
Definition: libebook_utils.h:132
libebook::EBOOKHTMLToken::input
@ input
Definition: EBOOKHTMLToken.h:89
libebook::EBOOKOPFToken::format
@ format
Definition: EBOOKOPFToken.h:54
libebook
Definition: BBeBCollector.cpp:19
libebook::readCString
string readCString(librevenge::RVNGInputStream *input)
Definition: libebook_utils.cpp:118
libebook::findSubStreamByExt
bool findSubStreamByExt(const RVNGInputStreamPtr_t &input, const std::string &ext, unsigned &id)
Definition: libebook_utils.cpp:245
libebook::getDefaultPageSpanPropList
librevenge::RVNGPropertyList getDefaultPageSpanPropList()
Definition: libebook_utils.cpp:265
libebook::readU8
uint8_t readU8(librevenge::RVNGInputStream *input, bool)
Definition: libebook_utils.cpp:45
libebook::seek
void seek(librevenge::RVNGInputStream *const input, const unsigned long pos)
Definition: libebook_utils.cpp:152
libebook::getRemainingLength
unsigned long getRemainingLength(librevenge::RVNGInputStream *const input)
Definition: libebook_utils.cpp:170
libebook::skip
void skip(librevenge::RVNGInputStream *input, unsigned long numBytes)
Definition: libebook_utils.cpp:145
libebook::RVNGInputStreamPtr_t
std::shared_ptr< librevenge::RVNGInputStream > RVNGInputStreamPtr_t
Definition: libebook_utils.h:54
libebook::readPascalString
string readPascalString(librevenge::RVNGInputStream *input)
Definition: libebook_utils.cpp:133
libebook::readU64
uint64_t readU64(librevenge::RVNGInputStream *input, bool bigEndian)
Definition: libebook_utils.cpp:89
libebook::readU16
uint16_t readU16(librevenge::RVNGInputStream *input, bool bigEndian)
Definition: libebook_utils.cpp:57
libebook::readNBytes
const unsigned char * readNBytes(librevenge::RVNGInputStream *const input, const unsigned long numBytes)
Definition: libebook_utils.cpp:105
libebook::readU32
uint32_t readU32(librevenge::RVNGInputStream *input, bool bigEndian)
Definition: libebook_utils.cpp:73
libebook::seekRelative
void seekRelative(librevenge::RVNGInputStream *const input, const long pos)
Definition: libebook_utils.cpp:161
libebook::EBOOKDummyDeleter
Definition: libebook_utils.h:57
libebook::EBOOKDummyDeleter::operator()
void operator()(void *)
Definition: libebook_utils.h:58