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