libcdr_utils.h Source File documentation

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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 #include <stdio.h>
14 #include <string>
15 #include <math.h>
16 #include <vector>
17 #include <librevenge-stream/librevenge-stream.h>
18 #include <librevenge/librevenge.h>
19
20 #ifndef M_PI
21 #define M_PI 3.14159265358979323846
22 #endif
23
24 #define CDR_EPSILON 1E-6
25 #define CDR_ALMOST_ZERO(m) (fabs(m) <= CDR_EPSILON)
26
27 #ifdef _MSC_VER
28
29 typedef unsigned char uint8_t;
30 typedef unsigned short uint16_t;
31 typedef short int16_t;
32 typedef unsigned uint32_t;
33 typedef int int32_t;
34 typedef unsigned __int64 uint64_t;
35 typedef __int64 int64_t;
36
37 #else
38
39 #ifdef HAVE_CONFIG_H
40
41 #include <config.h>
42
43 #ifdef HAVE_STDINT_H
44 #include <stdint.h>
45 #endif
46
47 #ifdef HAVE_INTTYPES_H
48 #include <inttypes.h>
49 #endif
50
51 #else
52
53 // assume that the headers are there inside LibreOffice build when no HAVE_CONFIG_H is defined
54 #include <stdint.h>
55 #include <inttypes.h>
56
57 #endif
58
59 #endif
60
61 // debug message includes source file and line number
62 //#define VERBOSE_DEBUG 1
63
64 // do nothing with debug messages in a release compile
65 #ifdef DEBUG
66 #ifdef VERBOSE_DEBUG
67 #define CDR_DEBUG_MSG(M) printf("%15s:%5d: ", __FILE__, __LINE__); printf M
68 #define CDR_DEBUG(M) M
69 #else
70 #define CDR_DEBUG_MSG(M) printf M
71 #define CDR_DEBUG(M) M
72 #endif
73 #else
74 #define CDR_DEBUG_MSG(M)
75 #define CDR_DEBUG(M)
76 #endif
77
78 namespace libcdr
79 {
80
81 uint8_t readU8(librevenge::RVNGInputStream *input, bool bigEndian=false);
82 uint16_t readU16(librevenge::RVNGInputStream *input, bool bigEndian=false);
83 uint32_t readU32(librevenge::RVNGInputStream *input, bool bigEndian=false);
84 uint64_t readU64(librevenge::RVNGInputStream *input, bool bigEndian=false);
85 int32_t readS32(librevenge::RVNGInputStream *input, bool bigEndian=false);
86 int16_t readS16(librevenge::RVNGInputStream *input, bool bigEndian=false);
87
88 double readDouble(librevenge::RVNGInputStream *input, bool bigEndian=false);
89
90 double readFixedPoint(librevenge::RVNGInputStream *input, bool bigEndian=false);
91
92 int cdr_round(double d);
93
94 void writeU16(librevenge::RVNGBinaryData &buffer, const int value);
95 void writeU32(librevenge::RVNGBinaryData &buffer, const int value);
96 void appendCharacters(librevenge::RVNGString &text, std::vector<unsigned char> characters, unsigned short charset);
97 void appendCharacters(librevenge::RVNGString &text, std::vector<unsigned char> characters);
98
99 #ifdef DEBUG
100 const char *toFourCC(unsigned value, bool bigEndian=false);
101 #endif
102
103 class EndOfStreamException
104 {
105 };
106
107 class GenericException
108 {
109 };
110
111 class UnknownPrecisionException
112 {
113 };
114
115 class EncodingException
116 {
117 };
118
119 } // namespace libcdr
120
121 #endif // __LIBCDR_UTILS_H__
122 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
libcdr::EndOfStreamException
Definition: libcdr_utils.h:103
libcdr::UnknownPrecisionException
Definition: libcdr_utils.h:111
libcdr::readFixedPoint
double readFixedPoint(librevenge::RVNGInputStream *input, bool bigEndian=false)
Definition: libcdr_utils.cpp:258
libcdr::readU16
uint16_t readU16(librevenge::RVNGInputStream *input, bool bigEndian=false)
Definition: libcdr_utils.cpp:175
libcdr::cdr_round
int cdr_round(double d)
Definition: libcdr_utils.cpp:266
libcdr::readS16
int16_t readS16(librevenge::RVNGInputStream *input, bool bigEndian=false)
Definition: libcdr_utils.cpp:195
libcdr::GenericException
Definition: libcdr_utils.h:107
libcdr::writeU32
void writeU32(librevenge::RVNGBinaryData &buffer, const int value)
Definition: libcdr_utils.cpp:277
libcdr
Definition: CDRCollector.h:29
libcdr::appendCharacters
void appendCharacters(librevenge::RVNGString &text, std::vector< unsigned char > characters, unsigned short charset)
Definition: libcdr_utils.cpp:285
libcdr::readS32
int32_t readS32(librevenge::RVNGInputStream *input, bool bigEndian=false)
Definition: libcdr_utils.cpp:220
libcdr::EncodingException
Definition: libcdr_utils.h:115
libcdr::readDouble
double readDouble(librevenge::RVNGInputStream *input, bool bigEndian=false)
Definition: libcdr_utils.cpp:245
libcdr::readU64
uint64_t readU64(librevenge::RVNGInputStream *input, bool bigEndian=false)
Definition: libcdr_utils.cpp:225
libcdr::readU8
uint8_t readU8(librevenge::RVNGInputStream *input, bool bigEndian=false)
Definition: libcdr_utils.cpp:159
libcdr::writeU16
void writeU16(librevenge::RVNGBinaryData &buffer, const int value)
Definition: libcdr_utils.cpp:271
libcdr::readU32
uint32_t readU32(librevenge::RVNGInputStream *input, bool bigEndian=false)
Definition: libcdr_utils.cpp:200