summaryrefslogtreecommitdiff
path: root/src/lib/libsw602_utils.h
blob: 5ffb2236d3885b711c18ea09dafe3389d4f91e25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
 * This file is part of the libsw602 project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#ifndef INCLUDED_LIBSW602_UTILS_H
#define INCLUDED_LIBSW602_UTILS_H

#ifdef DEBUG
#include <cstdio>
#endif

#include <boost/cstdint.hpp>

#include <librevenge-stream/librevenge-stream.h>
#include <librevenge/librevenge.h>

namespace libsw602
{

using boost::uint8_t;
using boost::int8_t;
using boost::uint16_t;
using boost::int16_t;
using boost::uint32_t;
using boost::int32_t;
using boost::uint64_t;
using boost::int64_t;

/** an noop deleter used to transform a librevenge pointer in a false shared_ptr */
template <class T>
struct SW602_shared_ptr_noop_deleter
{
  void operator()(T *) {}
};

}

// debug message includes source file and line number
//#define VERBOSE_DEBUG 1

// do nothing with debug messages in a release compile
#ifdef DEBUG
#ifdef VERBOSE_DEBUG
#define SW602_DEBUG_MSG(M) std::printf("%15s:%5d: ", __FILE__, __LINE__); std::printf M
#define SW602_DEBUG(M) M
#else
#define SW602_DEBUG_MSG(M) std::printf M
#define SW602_DEBUG(M) M
#endif
#else
#define SW602_DEBUG_MSG(M)
#define SW602_DEBUG(M)
#endif

#define SW602_NUM_ELEMENTS(array) sizeof(array)/sizeof(array[0])

namespace libsw602
{

uint8_t readU8(librevenge::RVNGInputStream &input, bool = false);
uint16_t readU16(librevenge::RVNGInputStream &input, bool bigEndian=false);
uint32_t readU32(librevenge::RVNGInputStream &input, bool bigEndian=false);
uint64_t readU64(librevenge::RVNGInputStream &input, bool bigEndian=false);

const unsigned char *readNBytes(librevenge::RVNGInputStream &input, unsigned long numBytes);

void skip(librevenge::RVNGInputStream &input, unsigned long numBytes);

class EndOfStreamException
{
};

class GenericException
{
};

class VersionException
{
};

class FileException
{
};

class ParseException
{
};

class WrongPasswordException
{
};

} // namespace libsw602

#endif // INCLUDED_LIBSW602_UTILS_H

/* vim:set shiftwidth=2 softtabstop=2 expandtab: */