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
48namespace libvisio
49{
50
51typedef std::shared_ptr<librevenge::RVNGInputStream> RVNGInputStreamPtr_t;
52
54{
55 void operator()(void *) {}
56};
57
58template<typename T, typename... Args>
59std::unique_ptr<T> make_unique(Args &&... args)
60{
61 return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
62}
63
64template<typename T>
65std::unique_ptr<T> clone(const std::unique_ptr<T> &other)
66{
67 return std::unique_ptr<T>(other->clone());
68}
69
70uint8_t readU8(librevenge::RVNGInputStream *input);
71uint16_t readU16(librevenge::RVNGInputStream *input);
72int16_t readS16(librevenge::RVNGInputStream *input);
73uint32_t readU32(librevenge::RVNGInputStream *input);
74int32_t readS32(librevenge::RVNGInputStream *input);
75uint64_t readU64(librevenge::RVNGInputStream *input);
76
77double readDouble(librevenge::RVNGInputStream *input);
78
79const librevenge::RVNGString getColourString(const Colour &c);
80
81unsigned long getRemainingLength(librevenge::RVNGInputStream *input);
82
83void appendUCS4(librevenge::RVNGString &text, UChar32 ucs4Character);
84
85void 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: */
Definition libvisio_utils.h:88
Definition libvisio_utils.h:96
Definition libvisio_utils.h:92
#define VSD_ATTRIBUTE_PRINTF(fmt, arg)
Definition libvisio_utils.h:34
Definition libvisio_utils.h:49
uint8_t readU8(librevenge::RVNGInputStream *input)
Definition libvisio_utils.cpp:16
std::shared_ptr< librevenge::RVNGInputStream > RVNGInputStreamPtr_t
Definition libvisio_utils.h:51
unsigned long getRemainingLength(librevenge::RVNGInputStream *input)
Definition libvisio_utils.cpp:110
uint64_t readU64(librevenge::RVNGInputStream *input)
Definition libvisio_utils.cpp:74
int32_t readS32(librevenge::RVNGInputStream *input)
Definition libvisio_utils.cpp:69
uint16_t readU16(librevenge::RVNGInputStream *input)
Definition libvisio_utils.cpp:32
int16_t readS16(librevenge::RVNGInputStream *input)
Definition libvisio_utils.cpp:48
double readDouble(librevenge::RVNGInputStream *input)
Definition libvisio_utils.cpp:90
void appendUCS4(librevenge::RVNGString &text, UChar32 ucs4Character)
Definition libvisio_utils.cpp:132
std::unique_ptr< T > clone(const std::unique_ptr< T > &other)
Definition libvisio_utils.h:65
const librevenge::RVNGString getColourString(const Colour &c)
Definition libvisio_utils.cpp:103
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
std::unique_ptr< T > make_unique(Args &&... args)
Definition libvisio_utils.h:59
Definition libvisio_utils.h:54
void operator()(void *)
Definition libvisio_utils.h:55

Generated for libvisio by doxygen 1.14.0