libvisio_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 libvisio 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 __LIBVISIO_UTILS_H__
11 #define __LIBVISIO_UTILS_H__
12 
13 #ifdef HAVE_CONFIG_H
14 #include "config.h"
15 #endif
16 
17 #include <memory>
18 
19 #include <boost/cstdint.hpp>
20 
21 #include "VSDTypes.h"
22 
23 #define VSD_EPSILON 1E-6
24 #define VSD_ALMOST_ZERO(m) (fabs(m) <= VSD_EPSILON)
25 #define VSD_APPROX_EQUAL(x, y) VSD_ALMOST_ZERO((x) - (y))
26 
27 #include <librevenge/librevenge.h>
28 #include <librevenge-stream/librevenge-stream.h>
29 #include <unicode/utypes.h>
30 
31 #if defined(HAVE_FUNC_ATTRIBUTE_FORMAT)
32 #define VSD_ATTRIBUTE_PRINTF(fmt, arg) __attribute__((format(printf, fmt, arg)))
33 #else
34 #define VSD_ATTRIBUTE_PRINTF(fmt, arg)
35 #endif
36 
37 // do nothing with debug messages in a release compile
38 #ifdef DEBUG
39 #define VSD_DEBUG_MSG(M) libvisio::debugPrint M
40 #define VSD_DEBUG(M) M
41 #else
42 #define VSD_DEBUG_MSG(M)
43 #define VSD_DEBUG(M)
44 #endif
45 
46 #define VSD_NUM_ELEMENTS(array) (sizeof(array)/sizeof((array)[0]))
47 
48 namespace libvisio
49 {
50 
51 typedef std::shared_ptr<librevenge::RVNGInputStream> RVNGInputStreamPtr_t;
52 
54 {
55  void operator()(void *) {}
56 };
57 
58 template<typename T, typename... Args>
59 std::unique_ptr<T> make_unique(Args &&... args)
60 {
61  return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
62 }
63 
64 template<typename T>
65 std::unique_ptr<T> clone(const std::unique_ptr<T> &other)
66 {
67  return std::unique_ptr<T>(other->clone());
68 }
69 
70 uint8_t readU8(librevenge::RVNGInputStream *input);
71 uint16_t readU16(librevenge::RVNGInputStream *input);
72 int16_t readS16(librevenge::RVNGInputStream *input);
73 uint32_t readU32(librevenge::RVNGInputStream *input);
74 int32_t readS32(librevenge::RVNGInputStream *input);
75 uint64_t readU64(librevenge::RVNGInputStream *input);
76 
77 double readDouble(librevenge::RVNGInputStream *input);
78 
79 const librevenge::RVNGString getColourString(const Colour &c);
80 
81 unsigned long getRemainingLength(librevenge::RVNGInputStream *input);
82 
83 void appendUCS4(librevenge::RVNGString &text, UChar32 ucs4Character);
84 
85 void debugPrint(const char *format, ...) VSD_ATTRIBUTE_PRINTF(1, 2);
86 
88 {
89 };
90 
92 {
93 };
94 
96 {
97 };
98 
99 } // namespace libvisio
100 
101 #endif // __LIBVISIO_UTILS_H__
102 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
std::unique_ptr< T > make_unique(Args &&...args)
Definition: libvisio_utils.h:59
unsigned long getRemainingLength(librevenge::RVNGInputStream *input)
Definition: libvisio_utils.cpp:110
Definition: libvisio_utils.h:87
void appendUCS4(librevenge::RVNGString &text, UChar32 ucs4Character)
Definition: libvisio_utils.cpp:132
const librevenge::RVNGString getColourString(const Colour &c)
Definition: libvisio_utils.cpp:103
int16_t readS16(librevenge::RVNGInputStream *input)
Definition: libvisio_utils.cpp:48
void operator()(void *)
Definition: libvisio_utils.h:55
int32_t readS32(librevenge::RVNGInputStream *input)
Definition: libvisio_utils.cpp:69
std::unique_ptr< T > clone(const std::unique_ptr< T > &other)
Definition: libvisio_utils.h:65
double readDouble(librevenge::RVNGInputStream *input)
Definition: libvisio_utils.cpp:90
#define VSD_ATTRIBUTE_PRINTF(fmt, arg)
Definition: libvisio_utils.h:34
std::shared_ptr< librevenge::RVNGInputStream > RVNGInputStreamPtr_t
Definition: libvisio_utils.h:51
Definition: libvisio_utils.h:91
Definition: libvisio_utils.h:48
Definition: libvisio_utils.h:95
void debugPrint(const char *format,...) VSD_ATTRIBUTE_PRINTF(1
Definition: libvisio_utils.cpp:146
uint32_t readU32(librevenge::RVNGInputStream *input)
Definition: libvisio_utils.cpp:53
uint8_t readU8(librevenge::RVNGInputStream *input)
Definition: libvisio_utils.cpp:16
uint16_t readU16(librevenge::RVNGInputStream *input)
Definition: libvisio_utils.cpp:32
Definition: libvisio_utils.h:53
uint64_t readU64(librevenge::RVNGInputStream *input)
Definition: libvisio_utils.cpp:74

Generated for libvisio by doxygen 1.8.10