libvisio_utils.h Source File documentation

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
53 struct VSDDummyDeleter
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
87class EndOfStreamException
88{
89};
90
91 class XmlParserException
92{
93};
94
95 class GenericException
96{
97};
98
99} // namespace libvisio
100
101#endif // __LIBVISIO_UTILS_H__
102/* vim:set shiftwidth=2 softtabstop=2 expandtab: */
VSDTypes.h
libvisio::EndOfStreamException
Definition libvisio_utils.h:88
libvisio::GenericException
Definition libvisio_utils.h:96
libvisio::XmlParserException
Definition libvisio_utils.h:92
VSD_ATTRIBUTE_PRINTF
#define VSD_ATTRIBUTE_PRINTF(fmt, arg)
Definition libvisio_utils.h:34
libvisio
Definition libvisio_utils.h:49
libvisio::readU8
uint8_t readU8(librevenge::RVNGInputStream *input)
Definition libvisio_utils.cpp:16
libvisio::RVNGInputStreamPtr_t
std::shared_ptr< librevenge::RVNGInputStream > RVNGInputStreamPtr_t
Definition libvisio_utils.h:51
libvisio::getRemainingLength
unsigned long getRemainingLength(librevenge::RVNGInputStream *input)
Definition libvisio_utils.cpp:110
libvisio::readU64
uint64_t readU64(librevenge::RVNGInputStream *input)
Definition libvisio_utils.cpp:74
libvisio::readS32
int32_t readS32(librevenge::RVNGInputStream *input)
Definition libvisio_utils.cpp:69
libvisio::readU16
uint16_t readU16(librevenge::RVNGInputStream *input)
Definition libvisio_utils.cpp:32
libvisio::readS16
int16_t readS16(librevenge::RVNGInputStream *input)
Definition libvisio_utils.cpp:48
libvisio::readDouble
double readDouble(librevenge::RVNGInputStream *input)
Definition libvisio_utils.cpp:90
libvisio::appendUCS4
void appendUCS4(librevenge::RVNGString &text, UChar32 ucs4Character)
Definition libvisio_utils.cpp:132
libvisio::clone
std::unique_ptr< T > clone(const std::unique_ptr< T > &other)
Definition libvisio_utils.h:65
libvisio::getColourString
const librevenge::RVNGString getColourString(const Colour &c)
Definition libvisio_utils.cpp:103
libvisio::debugPrint
void debugPrint(const char *format,...) VSD_ATTRIBUTE_PRINTF(1
Definition libvisio_utils.cpp:146
libvisio::readU32
uint32_t readU32(librevenge::RVNGInputStream *input)
Definition libvisio_utils.cpp:53
libvisio::make_unique
std::unique_ptr< T > make_unique(Args &&... args)
Definition libvisio_utils.h:59
libvisio::VSDDummyDeleter
Definition libvisio_utils.h:54
libvisio::VSDDummyDeleter::operator()
void operator()(void *)
Definition libvisio_utils.h:55