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 /* libcdr
3  * Version: MPL 1.1 / GPLv2+ / LGPLv2+
4  *
5  * The contents of this file are subject to the Mozilla Public License Version
6  * 1.1 (the "License"); you may not use this file except in compliance with
7  * the License or as specified alternatively below. You may obtain a copy of
8  * the License at http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12  * for the specific language governing rights and limitations under the
13  * License.
14  *
15  * Major Contributor(s):
16  * Copyright (C) 2011 Fridrich Strba <fridrich.strba@bluewin.ch>
17  * Copyright (C) 2011 Eilidh McAdam <tibbylickle@gmail.com>
18  *
19  *
20  * All Rights Reserved.
21  *
22  * For minor contributions see the git repository.
23  *
24  * Alternatively, the contents of this file may be used under the terms of
25  * either the GNU General Public License Version 2 or later (the "GPLv2+"), or
26  * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
27  * in which case the provisions of the GPLv2+ or the LGPLv2+ are applicable
28  * instead of those above.
29  */
30 
31 #ifndef __LIBCDR_UTILS_H__
32 #define __LIBCDR_UTILS_H__
33 
34 #include <stdio.h>
35 #include <string>
36 #include <math.h>
37 #include <vector>
38 #include <libwpd-stream/libwpd-stream.h>
39 #include <libwpd/libwpd.h>
40 
41 #ifndef M_PI
42 #define M_PI 3.14159265358979323846
43 #endif
44 
45 #define CDR_EPSILON 1E-6
46 #define CDR_ALMOST_ZERO(m) (fabs(m) <= CDR_EPSILON)
47 
48 #ifdef _MSC_VER
49 
50 typedef unsigned char uint8_t;
51 typedef unsigned short uint16_t;
52 typedef short int16_t;
53 typedef unsigned uint32_t;
54 typedef int int32_t;
55 typedef unsigned __int64 uint64_t;
56 typedef __int64 int64_t;
57 
58 #else
59 
60 #ifdef HAVE_CONFIG_H
61 
62 #include <config.h>
63 
64 #ifdef HAVE_STDINT_H
65 #include <stdint.h>
66 #endif
67 
68 #ifdef HAVE_INTTYPES_H
69 #include <inttypes.h>
70 #endif
71 
72 #else
73 
74 // assume that the headers are there inside LibreOffice build when no HAVE_CONFIG_H is defined
75 #include <stdint.h>
76 #include <inttypes.h>
77 
78 #endif
79 
80 #endif
81 
82 // debug message includes source file and line number
83 //#define VERBOSE_DEBUG 1
84 
85 // do nothing with debug messages in a release compile
86 #ifdef DEBUG
87 #ifdef VERBOSE_DEBUG
88 #define CDR_DEBUG_MSG(M) printf("%15s:%5d: ", __FILE__, __LINE__); printf M
89 #define CDR_DEBUG(M) M
90 #else
91 #define CDR_DEBUG_MSG(M) printf M
92 #define CDR_DEBUG(M) M
93 #endif
94 #else
95 #define CDR_DEBUG_MSG(M)
96 #define CDR_DEBUG(M)
97 #endif
98 
99 namespace libcdr
100 {
101 
102 uint8_t readU8(WPXInputStream *input, bool bigEndian=false);
103 uint16_t readU16(WPXInputStream *input, bool bigEndian=false);
104 uint32_t readU32(WPXInputStream *input, bool bigEndian=false);
105 uint64_t readU64(WPXInputStream *input, bool bigEndian=false);
106 int32_t readS32(WPXInputStream *input, bool bigEndian=false);
107 int16_t readS16(WPXInputStream *input, bool bigEndian=false);
108 
109 double readDouble(WPXInputStream *input, bool bigEndian=false);
110 
111 double readFixedPoint(WPXInputStream *input, bool bigEndian=false);
112 
113 int cdr_round(double d);
114 
115 void writeU8(WPXBinaryData &buffer, const int value);
116 void writeU16(WPXBinaryData &buffer, const int value);
117 void writeU32(WPXBinaryData &buffer, const int value);
118 void appendCharacters(WPXString &text, std::vector<unsigned char> characters, unsigned short charset);
119 void appendCharacters(WPXString &text, std::vector<unsigned char> characters);
120 
121 #ifdef DEBUG
122 const char *toFourCC(unsigned value, bool bigEndian=false);
123 #endif
124 
126 {
127 };
128 
130 {
131 };
132 
134 {
135 };
136 
138 {
139 };
140 
141 } // namespace libcdr
142 
143 #endif // __LIBCDR_UTILS_H__
144 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */

Generated for libcdr by doxygen 1.8.1.2