libqxp_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 libqxp 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 INCLUDED_LIBQXP_UTILS_H
11 #define INCLUDED_LIBQXP_UTILS_H
12 
13 #ifdef HAVE_CONFIG_H
14 #include "config.h"
15 #endif
16 
17 #include <cmath>
18 #include <memory>
19 #include <string>
20 
21 #include <boost/cstdint.hpp>
22 
23 #include <librevenge-stream/librevenge-stream.h>
24 #include <librevenge/librevenge.h>
25 
26 #define QXP_EPSILON 1E-6
27 #define QXP_ALMOST_ZERO(m) (std::fabs(m) <= QXP_EPSILON)
28 
29 #if defined(HAVE_FUNC_ATTRIBUTE_FORMAT)
30 #define QXP_ATTRIBUTE_PRINTF(fmt, arg) __attribute__((format(printf, fmt, arg)))
31 #else
32 #define QXP_ATTRIBUTE_PRINTF(fmt, arg)
33 #endif
34 
35 #if defined(HAVE_CLANG_ATTRIBUTE_FALLTHROUGH)
36 # define QXP_FALLTHROUGH [[clang::fallthrough]]
37 #elif defined(HAVE_GCC_ATTRIBUTE_FALLTHROUGH)
38 # define QXP_FALLTHROUGH __attribute__((fallthrough))
39 #else
40 # define QXP_FALLTHROUGH ((void) 0)
41 #endif
42 
43 // do nothing with debug messages in a release compile
44 #ifdef DEBUG
45 namespace libqxp
46 {
47 void debugPrint(const char *format, ...) QXP_ATTRIBUTE_PRINTF(1, 2);
48 }
49 
50 #define QXP_DEBUG_MSG(M) libqxp::debugPrint M
51 #define QXP_DEBUG(M) M
52 #else
53 #define QXP_DEBUG_MSG(M)
54 #define QXP_DEBUG(M)
55 #endif
56 
57 #define QXP_NUM_ELEMENTS(array) (sizeof(array) / sizeof(array[0]))
58 
59 namespace libqxp
60 {
61 
63 {
64  void operator()(void *) {}
65 };
66 
67 template<typename T, typename... Args>
68 std::unique_ptr<T> make_unique(Args &&... args)
69 {
70  return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
71 }
72 
73 uint8_t readU8(librevenge::RVNGInputStream *input, bool = false);
74 uint16_t readU16(librevenge::RVNGInputStream *input, bool bigEndian=false);
75 uint32_t readU32(librevenge::RVNGInputStream *input, bool bigEndian=false);
76 uint64_t readU64(librevenge::RVNGInputStream *input, bool bigEndian=false);
77 int16_t readS16(librevenge::RVNGInputStream *input, bool bigEndian=false);
78 int32_t readS32(librevenge::RVNGInputStream *input, bool bigEndian=false);
79 double readFloat16(librevenge::RVNGInputStream *input, bool bigEndian=false);
80 double readFraction(librevenge::RVNGInputStream *input, bool bigEndian=false);
81 
82 const unsigned char *readNBytes(librevenge::RVNGInputStream *input, unsigned long numBytes);
83 
84 std::string readCString(librevenge::RVNGInputStream *input);
85 std::string readPascalString(librevenge::RVNGInputStream *input);
86 std::string readString(librevenge::RVNGInputStream *input, const unsigned length);
87 std::string readPlatformString(librevenge::RVNGInputStream *input, bool bigEndian=false);
88 
89 void skip(librevenge::RVNGInputStream *input, unsigned long numBytes);
90 
91 void seek(librevenge::RVNGInputStream *input, unsigned long pos);
92 void seekRelative(librevenge::RVNGInputStream *input, long pos);
93 
94 unsigned long getRemainingLength(librevenge::RVNGInputStream *input);
95 
96 uint8_t readU8(std::shared_ptr<librevenge::RVNGInputStream> input, bool = false);
97 uint16_t readU16(std::shared_ptr<librevenge::RVNGInputStream> input, bool bigEndian=false);
98 uint32_t readU32(std::shared_ptr<librevenge::RVNGInputStream> input, bool bigEndian=false);
99 uint64_t readU64(std::shared_ptr<librevenge::RVNGInputStream> input, bool bigEndian=false);
100 int16_t readS16(std::shared_ptr<librevenge::RVNGInputStream> input, bool bigEndian=false);
101 int32_t readS32(std::shared_ptr<librevenge::RVNGInputStream> input, bool bigEndian=false);
102 double readFloat16(std::shared_ptr<librevenge::RVNGInputStream> input, bool bigEndian=false);
103 double readFraction(std::shared_ptr<librevenge::RVNGInputStream> input, bool bigEndian=false);
104 
105 const unsigned char *readNBytes(std::shared_ptr<librevenge::RVNGInputStream> input, unsigned long numBytes);
106 
107 std::string readCString(std::shared_ptr<librevenge::RVNGInputStream> input);
108 std::string readPascalString(std::shared_ptr<librevenge::RVNGInputStream> input);
109 std::string readString(std::shared_ptr<librevenge::RVNGInputStream> input, const unsigned length);
110 std::string readPlatformString(std::shared_ptr<librevenge::RVNGInputStream> input, bool bigEndian=false);
111 
112 void skip(std::shared_ptr<librevenge::RVNGInputStream> input, unsigned long numBytes);
113 
114 void seek(std::shared_ptr<librevenge::RVNGInputStream> input, unsigned long pos);
115 void seekRelative(std::shared_ptr<librevenge::RVNGInputStream> input, long pos);
116 
117 unsigned long getRemainingLength(const std::shared_ptr<librevenge::RVNGInputStream> &input);
118 
119 double deg2rad(double value);
120 double normalizeDegAngle(double degAngle);
121 double normalizeRadAngle(double radAngle);
122 
123 void appendCharacters(librevenge::RVNGString &text, const char *characters, const size_t size,
124  const char *encoding);
125 
127 {
128 public:
130 };
131 
133 {
134 };
135 
136 // parser exceptions
137 
139 {
140 };
141 
143 {
144 };
145 
147 {
148 };
149 
150 } // namespace libqxp
151 
152 #endif // INCLUDED_LIBQXP_UTILS_H
153 
154 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
libqxp::FileAccessError
Definition: libqxp_utils.h:138
libqxp::readS32
int32_t readS32(librevenge::RVNGInputStream *input, bool bigEndian)
Definition: libqxp_utils.cpp:164
libqxp::EndOfStreamException::EndOfStreamException
EndOfStreamException()
Definition: libqxp_utils.cpp:369
libqxp::readU16
uint16_t readU16(librevenge::RVNGInputStream *input, bool bigEndian)
Definition: libqxp_utils.cpp:111
libqxp::readU64
uint64_t readU64(librevenge::RVNGInputStream *input, bool bigEndian)
Definition: libqxp_utils.cpp:143
libqxp
Definition: libqxp_utils.cpp:24
libqxp::readFloat16
double readFloat16(librevenge::RVNGInputStream *input, bool bigEndian)
Definition: libqxp_utils.cpp:169
libqxp::readS16
int16_t readS16(librevenge::RVNGInputStream *input, bool bigEndian)
Definition: libqxp_utils.cpp:159
libqxp::seek
void seek(librevenge::RVNGInputStream *const input, const unsigned long pos)
Definition: libqxp_utils.cpp:241
libqxp::readPlatformString
std::string readPlatformString(librevenge::RVNGInputStream *input, bool bigEndian)
Definition: libqxp_utils.cpp:229
libqxp::QXPDummyDeleter::operator()
void operator()(void *)
Definition: libqxp_utils.h:64
libqxp_utils.h
libqxp::EndOfStreamException
Definition: libqxp_utils.h:126
libqxp::readU32
uint32_t readU32(librevenge::RVNGInputStream *input, bool bigEndian)
Definition: libqxp_utils.cpp:127
libqxp::UnsupportedFormat
Definition: libqxp_utils.h:146
libqxp::normalizeDegAngle
double normalizeDegAngle(double degAngle)
Definition: libqxp_utils.cpp:390
libqxp::readFraction
double readFraction(librevenge::RVNGInputStream *input, bool bigEndian)
Definition: libqxp_utils.cpp:174
QXP_DEBUG_MSG
#define QXP_DEBUG_MSG(M)
Definition: libqxp_utils.h:53
libqxp::seekRelative
void seekRelative(librevenge::RVNGInputStream *const input, const long pos)
Definition: libqxp_utils.cpp:250
libqxp::readCString
string readCString(librevenge::RVNGInputStream *input)
Definition: libqxp_utils.cpp:193
libqxp::normalizeRadAngle
double normalizeRadAngle(double radAngle)
Definition: libqxp_utils.cpp:381
libqxp::QXPDummyDeleter
Definition: libqxp_utils.h:62
libqxp::readU8
uint8_t readU8(librevenge::RVNGInputStream *input, bool)
Definition: libqxp_utils.cpp:99
libqxp::readPascalString
string readPascalString(librevenge::RVNGInputStream *input)
Definition: libqxp_utils.cpp:208
libqxp::readNBytes
const unsigned char * readNBytes(librevenge::RVNGInputStream *const input, const unsigned long numBytes)
Definition: libqxp_utils.cpp:180
libqxp::make_unique
std::unique_ptr< T > make_unique(Args &&... args)
Definition: libqxp_utils.h:68
libqxp::appendCharacters
void appendCharacters(librevenge::RVNGString &text, const char *characters, const size_t size, const char *encoding)
Definition: libqxp_utils.cpp:398
libqxp::deg2rad
double deg2rad(double value)
Definition: libqxp_utils.cpp:374
libqxp::readString
std::string readString(librevenge::RVNGInputStream *input, const unsigned length)
Definition: libqxp_utils.cpp:217
libqxp::skip
void skip(librevenge::RVNGInputStream *input, unsigned long numBytes)
Definition: libqxp_utils.cpp:234
libqxp::ParseError
Definition: libqxp_utils.h:142
QXP_ATTRIBUTE_PRINTF
#define QXP_ATTRIBUTE_PRINTF(fmt, arg)
Definition: libqxp_utils.h:32
libqxp::GenericException
Definition: libqxp_utils.h:132
libqxp::getRemainingLength
unsigned long getRemainingLength(librevenge::RVNGInputStream *const input)
Definition: libqxp_utils.cpp:259

Generated for libqxp by doxygen 1.8.16