libetonyek_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 libetonyek 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 LIBETONYEK_UTILS_H_INCLUDED
11 #define LIBETONYEK_UTILS_H_INCLUDED
12 
13 #include <cmath>
14 #include <stdio.h>
15 #include <string>
16 
17 #include <boost/shared_ptr.hpp>
18 
19 #include <librevenge/librevenge.h>
20 #include <librevenge-stream/librevenge-stream.h>
21 
22 #ifdef _MSC_VER
23 
24 typedef unsigned char uint8_t;
25 typedef unsigned short uint16_t;
26 typedef unsigned uint32_t;
27 typedef unsigned __int64 uint64_t;
28 typedef signed char int8_t;
29 typedef short int16_t;
30 typedef int int32_t;
31 typedef __int64 int64_t;
32 
33 #else
34 
35 #ifdef HAVE_CONFIG_H
36 
37 #include <config.h>
38 
39 #ifdef HAVE_STDINT_H
40 #include <stdint.h>
41 #endif
42 
43 #ifdef HAVE_INTTYPES_H
44 #include <inttypes.h>
45 #endif
46 
47 #else
48 
49 // assume that the headers are there inside LibreOffice build when no HAVE_CONFIG_H is defined
50 #include <stdint.h>
51 #include <inttypes.h>
52 
53 #endif
54 
55 #endif
56 
57 #define ETONYEK_EPSILON 1e-9
58 #define ETONYEK_ALMOST_ZERO(x) (std::fabs(x) < ETONYEK_EPSILON)
59 
60 #define ETONYEK_NUM_ELEMENTS(array) (sizeof(array) / sizeof((array)[0]))
61 
62 // debug message includes source file and line number
63 //#define VERBOSE_DEBUG 1
64 
65 // do nothing with debug messages in a release compile
66 #ifdef DEBUG
67 #ifdef VERBOSE_DEBUG
68 #define ETONYEK_DEBUG_MSG(M) printf("%15s:%5d: ", FILE, LINE); printf M
69 #define ETONYEK_DEBUG(M) M
70 #else
71 #define ETONYEK_DEBUG_MSG(M) printf M
72 #define ETONYEK_DEBUG(M) M
73 #endif
74 #else
75 #define ETONYEK_DEBUG_MSG(M)
76 #define ETONYEK_DEBUG(M)
77 #endif
78 
79 namespace libetonyek
80 {
81 
82 struct IWORKColor;
83 struct IWORKStroke;
84 
85 /* Constants */
86 const double etonyek_half_pi(1.57079632679489661923132169163975144209858469968755291048747229615390820314310449931401741267105853399107404326e+00);
87 const double etonyek_third_pi(1.04719755119659774615421446109316762806572313312503527365831486410260546876206966620934494178070568932738269550e+00);
88 const double etonyek_pi(3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651e+00);
89 const double etonyek_two_pi(6.28318530717958647692528676655900576839433879875021164194988918461563281257241799725606965068423413596429617303e+00);
90 
91 const double etonyek_root_three(1.73205080756887729352744634150587236694280525381038062805580697945193301690880003708114618675724857567562614142e+00);
92 const double etonyek_root_two(1.41421356237309504880168872420969807856967187537694807317667973799073247846210703885038753432764157273501384623e+00);
93 
95 {
96  void operator()(void *) {}
97 };
98 
99 typedef boost::shared_ptr<librevenge::RVNGInputStream> RVNGInputStreamPtr_t;
100 
101 uint8_t readU8(const RVNGInputStreamPtr_t &input, bool = false);
102 uint16_t readU16(const RVNGInputStreamPtr_t &input, bool bigEndian=false);
103 uint32_t readU32(const RVNGInputStreamPtr_t &input, bool bigEndian=false);
104 uint64_t readU64(const RVNGInputStreamPtr_t &input, bool bigEndian=false);
105 
112 bool approxEqual(double x, double y, double eps = ETONYEK_EPSILON);
113 
114 template<class T>
115 bool approxEqual(const T &left, const T &right, const double eps = ETONYEK_EPSILON)
116 {
117  assert(left.length() == right.length());
118 
119  for (int i = 0; i != left.length(); ++i)
120  {
121  if (!approxEqual(left[i], right[i], eps))
122  return false;
123  }
124  return true;
125 }
126 
132 double pt2in(double d);
133 
139 double deg2rad(double value);
140 
141 librevenge::RVNGString makeColor(const IWORKColor &color);
142 
143 librevenge::RVNGString makeBorder(const IWORKStroke &stroke);
144 
146 {
147 };
148 
150 {
151 };
152 
153 } // namespace libetonyek
154 
155 #endif // LIBETONYEK_UTILS_H_INCLUDED
156 
157 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
Definition: IWORKBezierElement.cpp:18
const double etonyek_root_two(1.41421356237309504880168872420969807856967187537694807317667973799073247846210703885038753432764157273501384623e+00)
librevenge::RVNGString makeBorder(const IWORKStroke &stroke)
Definition: libetonyek_utils.cpp:123
Definition: IWORKToken.h:178
double deg2rad(double value)
Convert an angle from degrees to radians.
Definition: libetonyek_utils.cpp:97
double y
Definition: IWORKShape.cpp:43
Definition: IWORKToken.h:55
Definition: libetonyek_utils.h:149
Definition: libetonyek_utils.h:145
double pt2in(const double d)
Convert a length from points to inches.
Definition: libetonyek_utils.cpp:92
uint32_t readU32(const RVNGInputStreamPtr_t &input, bool bigEndian)
Definition: libetonyek_utils.cpp:55
const double etonyek_root_three(1.73205080756887729352744634150587236694280525381038062805580697945193301690880003708114618675724857567562614142e+00)
double x
Definition: IWORKShape.cpp:42
Definition: IWORKToken.h:66
Definition: IWORKToken.h:237
uint8_t readU8(const RVNGInputStreamPtr_t &input, bool)
Definition: libetonyek_utils.cpp:27
Definition: IWORKToken.h:246
uint64_t readU64(const RVNGInputStreamPtr_t &input, bool bigEndian)
Definition: libetonyek_utils.cpp:71
void operator()(void *)
Definition: libetonyek_utils.h:96
const double etonyek_two_pi(6.28318530717958647692528676655900576839433879875021164194988918461563281257241799725606965068423413596429617303e+00)
librevenge::RVNGString makeColor(const IWORKColor &color)
Definition: libetonyek_utils.cpp:109
Definition: KEY2Token.h:69
Definition: libetonyek_utils.h:94
boost::shared_ptr< librevenge::RVNGInputStream > RVNGInputStreamPtr_t
Definition: libetonyek_utils.h:99
const double etonyek_half_pi(1.57079632679489661923132169163975144209858469968755291048747229615390820314310449931401741267105853399107404326e+00)
uint16_t readU16(const RVNGInputStreamPtr_t &input, bool bigEndian)
Definition: libetonyek_utils.cpp:39
#define ETONYEK_EPSILON
Definition: libetonyek_utils.h:57
RVNGInputStreamPtr_t input
Definition: EtonyekDocument.cpp:68
bool approxEqual(const IWORKPath &left, const IWORKPath &right, const double eps)
Definition: IWORKPath.cpp:405
const double etonyek_pi(3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651e+00)
const double etonyek_third_pi(1.04719755119659774615421446109316762806572313312503527365831486410260546876206966620934494178070568932738269550e+00)

Generated for libetonyek by doxygen 1.8.8