/src/libcdr/src/lib/libcdr_utils.h
Line | Count | Source |
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 <math.h> |
18 | | #include <memory> |
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 | 23.2M | #define CDR_EPSILON 1E-6 |
31 | 40.1M | #define CDR_ALMOST_ZERO(m) (fabs(m) <= CDR_EPSILON) |
32 | 539k | #define CDR_ALMOST_EQUAL(m, n) CDR_ALMOST_ZERO(m-n) |
33 | | |
34 | | #if defined(HAVE_FUNC_ATTRIBUTE_FORMAT) |
35 | | # define CDR_ATTRIBUTE_PRINTF(fmt, arg) __attribute__((__format__(__printf__, fmt, arg))) |
36 | | #else |
37 | | # define CDR_ATTRIBUTE_PRINTF(fmt, arg) |
38 | | #endif |
39 | | |
40 | | #if defined(HAVE_CLANG_ATTRIBUTE_FALLTHROUGH) |
41 | | # define CDR_FALLTHROUGH [[clang::fallthrough]] |
42 | | #elif defined(HAVE_GCC_ATTRIBUTE_FALLTHROUGH) |
43 | 12.9k | # define CDR_FALLTHROUGH __attribute__((fallthrough)) |
44 | | #else |
45 | | # define CDR_FALLTHROUGH ((void) 0) |
46 | | #endif |
47 | | |
48 | | // do nothing with debug messages in a release compile |
49 | | #ifdef DEBUG |
50 | | namespace libcdr |
51 | | { |
52 | | void debugPrint(const char *format, ...) CDR_ATTRIBUTE_PRINTF(1, 2); |
53 | | } |
54 | | #define CDR_DEBUG_MSG(M) libcdr::debugPrint M |
55 | | #define CDR_DEBUG(M) M |
56 | | #else |
57 | | #define CDR_DEBUG_MSG(M) |
58 | | #define CDR_DEBUG(M) |
59 | | #endif |
60 | | |
61 | | namespace libcdr |
62 | | { |
63 | | |
64 | | struct CDRDummyDeleter |
65 | | { |
66 | 17.9k | void operator()(void *) const {} |
67 | | }; |
68 | | |
69 | | template<typename T, typename... Args> |
70 | | std::unique_ptr<T> make_unique(Args &&... args) |
71 | 62.3M | { |
72 | 62.3M | return std::unique_ptr<T>(new T(std::forward<Args>(args)...)); |
73 | 62.3M | } std::__1::unique_ptr<libcdr::CDRMoveToElement, std::__1::default_delete<libcdr::CDRMoveToElement> > libcdr::make_unique<libcdr::CDRMoveToElement, double&, double&>(double&, double&) Line | Count | Source | 71 | 44.5M | { | 72 | 44.5M | return std::unique_ptr<T>(new T(std::forward<Args>(args)...)); | 73 | 44.5M | } |
std::__1::unique_ptr<libcdr::CDRLineToElement, std::__1::default_delete<libcdr::CDRLineToElement> > libcdr::make_unique<libcdr::CDRLineToElement, double&, double&>(double&, double&) Line | Count | Source | 71 | 10.3M | { | 72 | 10.3M | return std::unique_ptr<T>(new T(std::forward<Args>(args)...)); | 73 | 10.3M | } |
std::__1::unique_ptr<libcdr::CDRCubicBezierToElement, std::__1::default_delete<libcdr::CDRCubicBezierToElement> > libcdr::make_unique<libcdr::CDRCubicBezierToElement, double&, double&, double&, double&, double&, double&>(double&, double&, double&, double&, double&, double&) Line | Count | Source | 71 | 582k | { | 72 | 582k | return std::unique_ptr<T>(new T(std::forward<Args>(args)...)); | 73 | 582k | } |
std::__1::unique_ptr<libcdr::CDRQuadraticBezierToElement, std::__1::default_delete<libcdr::CDRQuadraticBezierToElement> > libcdr::make_unique<libcdr::CDRQuadraticBezierToElement, double&, double&, double&, double&>(double&, double&, double&, double&) Line | Count | Source | 71 | 52.0k | { | 72 | 52.0k | return std::unique_ptr<T>(new T(std::forward<Args>(args)...)); | 73 | 52.0k | } |
Unexecuted instantiation: std::__1::unique_ptr<libcdr::CDRSplineToElement, std::__1::default_delete<libcdr::CDRSplineToElement> > libcdr::make_unique<libcdr::CDRSplineToElement, std::__1::vector<std::__1::pair<double, double>, std::__1::allocator<std::__1::pair<double, double> > >&>(std::__1::vector<std::__1::pair<double, double>, std::__1::allocator<std::__1::pair<double, double> > >&) std::__1::unique_ptr<libcdr::CDRArcToElement, std::__1::default_delete<libcdr::CDRArcToElement> > libcdr::make_unique<libcdr::CDRArcToElement, double&, double&, double&, bool&, bool&, double&, double&>(double&, double&, double&, bool&, bool&, double&, double&) Line | Count | Source | 71 | 837k | { | 72 | 837k | return std::unique_ptr<T>(new T(std::forward<Args>(args)...)); | 73 | 837k | } |
std::__1::unique_ptr<libcdr::CDRClosePathElement, std::__1::default_delete<libcdr::CDRClosePathElement> > libcdr::make_unique<libcdr::CDRClosePathElement>() Line | Count | Source | 71 | 6.06M | { | 72 | 6.06M | return std::unique_ptr<T>(new T(std::forward<Args>(args)...)); | 73 | 6.06M | } |
std::__1::unique_ptr<libcdr::CDRSplineToElement, std::__1::default_delete<libcdr::CDRSplineToElement> > libcdr::make_unique<libcdr::CDRSplineToElement, std::__1::vector<std::__1::pair<double, double>, std::__1::allocator<std::__1::pair<double, double> > > const&>(std::__1::vector<std::__1::pair<double, double>, std::__1::allocator<std::__1::pair<double, double> > > const&) Line | Count | Source | 71 | 1.22k | { | 72 | 1.22k | return std::unique_ptr<T>(new T(std::forward<Args>(args)...)); | 73 | 1.22k | } |
Unexecuted instantiation: std::__1::unique_ptr<libcdr::CDRPath, std::__1::default_delete<libcdr::CDRPath> > libcdr::make_unique<libcdr::CDRPath, libcdr::CDRPath&>(libcdr::CDRPath&) |
74 | | |
75 | | uint8_t readU8(librevenge::RVNGInputStream *input, bool bigEndian=false); |
76 | | uint16_t readU16(librevenge::RVNGInputStream *input, bool bigEndian=false); |
77 | | uint32_t readU32(librevenge::RVNGInputStream *input, bool bigEndian=false); |
78 | | uint64_t readU64(librevenge::RVNGInputStream *input, bool bigEndian=false); |
79 | | int32_t readS32(librevenge::RVNGInputStream *input, bool bigEndian=false); |
80 | | int16_t readS16(librevenge::RVNGInputStream *input, bool bigEndian=false); |
81 | | |
82 | | double readDouble(librevenge::RVNGInputStream *input, bool bigEndian=false); |
83 | | |
84 | | double readFixedPoint(librevenge::RVNGInputStream *input, bool bigEndian=false); |
85 | | |
86 | | unsigned long getLength(librevenge::RVNGInputStream *input); |
87 | | unsigned long getRemainingLength(librevenge::RVNGInputStream *input); |
88 | | |
89 | | int cdr_round(double d); |
90 | | |
91 | | void writeU16(librevenge::RVNGBinaryData &buffer, const int value); |
92 | | void writeU32(librevenge::RVNGBinaryData &buffer, const int value); |
93 | | void appendCharacters(librevenge::RVNGString &text, std::vector<unsigned char> characters, unsigned short charset); |
94 | | void appendCharacters(librevenge::RVNGString &text, std::vector<unsigned char> characters); |
95 | | void appendUTF8Characters(librevenge::RVNGString &text, std::vector<unsigned char> characters); |
96 | | |
97 | | #ifdef DEBUG |
98 | | const char *toFourCC(unsigned value, bool bigEndian=false); |
99 | | #endif |
100 | | |
101 | | class EndOfStreamException |
102 | | { |
103 | | }; |
104 | | |
105 | | class GenericException |
106 | | { |
107 | | }; |
108 | | |
109 | | class UnknownPrecisionException |
110 | | { |
111 | | }; |
112 | | |
113 | | class EncodingException |
114 | | { |
115 | | }; |
116 | | |
117 | | } // namespace libcdr |
118 | | |
119 | | #endif // __LIBCDR_UTILS_H__ |
120 | | /* vim:set shiftwidth=2 softtabstop=2 expandtab: */ |