libcdr_utils.h Source File documentation

libcdr_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 libcdr 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 __LIBCDR_UTILS_H__
11 #define __LIBCDR_UTILS_H__
12
13 #ifdef HAVE_CONFIG_H
14 #include "config.h"
15 #endif
16
17 #include <string>
18 #include <math.h>
19 #include <vector>
20
21 #include <boost/cstdint.hpp>
22
23 #include <librevenge-stream/librevenge-stream.h>
24 #include <librevenge/librevenge.h>
25
26 #ifndef M_PI
27 #define M_PI 3.14159265358979323846
28 #endif
29
30 #define CDR_EPSILON 1E-6
31 #define CDR_ALMOST_ZERO(m) (fabs(m) <= CDR_EPSILON)
32
33 #if defined(HAVE_FUNC_ATTRIBUTE_FORMAT)
34 # define CDR_ATTRIBUTE_PRINTF(fmt, arg) __attribute__((__format__(__printf__, fmt, arg)))
35 #else
36 # define CDR_ATTRIBUTE_PRINTF(fmt, arg)
37 #endif
38
39 #if defined(HAVE_CLANG_ATTRIBUTE_FALLTHROUGH)
40 # define CDR_FALLTHROUGH [[clang::fallthrough]]
41 #elif defined(HAVE_GCC_ATTRIBUTE_FALLTHROUGH)
42 # define CDR_FALLTHROUGH __attribute__((fallthrough))
43 #else
44 # define CDR_FALLTHROUGH ((void) 0)
45 #endif
46
47 // do nothing with debug messages in a release compile
48 #ifdef DEBUG
49 namespace libcdr
50 {
51 void debugPrint(const char *format, ...) CDR_ATTRIBUTE_PRINTF(1, 2);
52 }
53 #define CDR_DEBUG_MSG(M) libcdr::debugPrint M
54 #define CDR_DEBUG(M) M
55 #else
56 #define CDR_DEBUG_MSG(M)
57 #define CDR_DEBUG(M)
58 #endif
59
60 namespace libcdr
61 {
62
63 struct CDRDummyDeleter
64 {
65 void operator()(void *) const {}
66 };
67
68 uint8_t readU8(librevenge::RVNGInputStream *input, bool bigEndian=false);
69 uint16_t readU16(librevenge::RVNGInputStream *input, bool bigEndian=false);
70 uint32_t readU32(librevenge::RVNGInputStream *input, bool bigEndian=false);
71 uint64_t readU64(librevenge::RVNGInputStream *input, bool bigEndian=false);
72 int32_t readS32(librevenge::RVNGInputStream *input, bool bigEndian=false);
73 int16_t readS16(librevenge::RVNGInputStream *input, bool bigEndian=false);
74
75 double readDouble(librevenge::RVNGInputStream *input, bool bigEndian=false);
76
77 double readFixedPoint(librevenge::RVNGInputStream *input, bool bigEndian=false);
78
79 unsigned long getLength(librevenge::RVNGInputStream *input);
80 unsigned long getRemainingLength(librevenge::RVNGInputStream *input);
81
82 int cdr_round(double d);
83
84 void writeU16(librevenge::RVNGBinaryData &buffer, const int value);
85 void writeU32(librevenge::RVNGBinaryData &buffer, const int value);
86 void appendCharacters(librevenge::RVNGString &text, std::vector<unsigned char> characters, unsigned short charset);
87 void appendCharacters(librevenge::RVNGString &text, std::vector<unsigned char> characters);
88
89 #ifdef DEBUG
90 const char *toFourCC(unsigned value, bool bigEndian=false);
91 #endif
92
93 class EndOfStreamException
94 {
95 };
96
97 class GenericException
98 {
99 };
100
101 class UnknownPrecisionException
102 {
103 };
104
105 class EncodingException
106 {
107 };
108
109 } // namespace libcdr
110
111 #endif // __LIBCDR_UTILS_H__
112 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
libcdr::EndOfStreamException
Definition: libcdr_utils.h:93
libcdr::CDRDummyDeleter::operator()
void operator()(void *) const
Definition: libcdr_utils.h:65
libcdr::UnknownPrecisionException
Definition: libcdr_utils.h:101
CDR_ATTRIBUTE_PRINTF
#define CDR_ATTRIBUTE_PRINTF(fmt, arg)
Definition: libcdr_utils.h:36
libcdr::readFixedPoint
double readFixedPoint(librevenge::RVNGInputStream *input, bool bigEndian=false)
Definition: libcdr_utils.cpp:262
libcdr::readU16
uint16_t readU16(librevenge::RVNGInputStream *input, bool bigEndian=false)
Definition: libcdr_utils.cpp:179
libcdr::cdr_round
int cdr_round(double d)
Definition: libcdr_utils.cpp:306
libcdr::getLength
unsigned long getLength(librevenge::RVNGInputStream *input)
Definition: libcdr_utils.cpp:270
libcdr::readS16
int16_t readS16(librevenge::RVNGInputStream *input, bool bigEndian=false)
Definition: libcdr_utils.cpp:199
libcdr::GenericException
Definition: libcdr_utils.h:97
libcdr::writeU32
void writeU32(librevenge::RVNGBinaryData &buffer, const int value)
Definition: libcdr_utils.cpp:317
libcdr
Definition: CDRCollector.h:29
libcdr::appendCharacters
void appendCharacters(librevenge::RVNGString &text, std::vector< unsigned char > characters, unsigned short charset)
Definition: libcdr_utils.cpp:325
libcdr::readS32
int32_t readS32(librevenge::RVNGInputStream *input, bool bigEndian=false)
Definition: libcdr_utils.cpp:224
libcdr::EncodingException
Definition: libcdr_utils.h:105
libcdr::readDouble
double readDouble(librevenge::RVNGInputStream *input, bool bigEndian=false)
Definition: libcdr_utils.cpp:249
libcdr::readU64
uint64_t readU64(librevenge::RVNGInputStream *input, bool bigEndian=false)
Definition: libcdr_utils.cpp:229
libcdr::readU8
uint8_t readU8(librevenge::RVNGInputStream *input, bool bigEndian=false)
Definition: libcdr_utils.cpp:163
libcdr::writeU16
void writeU16(librevenge::RVNGBinaryData &buffer, const int value)
Definition: libcdr_utils.cpp:311
libcdr::CDRDummyDeleter
Definition: libcdr_utils.h:63
libcdr::getRemainingLength
unsigned long getRemainingLength(librevenge::RVNGInputStream *input)
Definition: libcdr_utils.cpp:301
libcdr::readU32
uint32_t readU32(librevenge::RVNGInputStream *input, bool bigEndian=false)
Definition: libcdr_utils.cpp:204