libpagemaker_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 libpagemaker 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 __LIBPAGEMAKER_UTILS_H__
11#define __LIBPAGEMAKER_UTILS_H__
12
13#ifdef HAVE_CONFIG_H
14#include "config.h"
15#endif
16
17#include <cmath>
18#include <cstdio>
19#include <memory>
20#include <string>
21
22#include <boost/cstdint.hpp>
23
24#include <librevenge-stream/librevenge-stream.h>
25#include <librevenge/librevenge.h>
26
27#ifndef M_PI
28#define M_PI 3.14159265358979323846
29#endif
30
31#if defined(HAVE_FUNC_ATTRIBUTE_FORMAT)
32# define PMD_ATTRIBUTE_PRINTF(fmt, arg) __attribute__((__format__(__printf__, fmt, arg)))
33#else
34# define PMD_ATTRIBUTE_PRINTF(fmt, arg)
35#endif
36
37#if defined(HAVE_CLANG_ATTRIBUTE_FALLTHROUGH)
38# define PMD_FALLTHROUGH [[clang::fallthrough]]
39#elif defined(HAVE_GCC_ATTRIBUTE_FALLTHROUGH)
40# define PMD_FALLTHROUGH __attribute__((fallthrough))
41#else
42# define PMD_FALLTHROUGH ((void) 0)
43#endif
44
45// do nothing with debug messages in a release compile
46#ifdef DEBUG
47namespace libpagemaker
48{
49void debugPrint(const char *format, ...) PMD_ATTRIBUTE_PRINTF(1, 2);
50}
51#define PMD_DEBUG_MSG(M) libpagemaker::debugPrint M
52#define PMD_DEBUG(M) M
53#define PMD_WARN_MSG(M) std::fprintf(stderr, "PageMaker [WARN] %15s:%d: ", __FILE__, __LINE__); std::fprintf(stderr, M)
54#define PMD_ERR_MSG(M) std::fprintf(stderr, "PageMaker [ERROR] %15s:%d: ", __FILE__, __LINE__); std::fprintf(stderr, M)
55#else
56#define PMD_DEBUG_MSG(M)
57#define PMD_DEBUG(M)
58#define PMD_WARN_MSG(M)
59#define PMD_ERR_MSG(M)
60#endif
61
62#define PMD_NUM_ELEMENTS(array) sizeof(array)/sizeof(array[0])
63
64namespace libpagemaker
65{
66
67typedef librevenge::RVNGInputStream *RVNGInputStreamPtr;
68
70{
71 void operator()(void *) {}
72};
73
74uint8_t readU8(const RVNGInputStreamPtr &input, bool = false);
75int8_t readS8(const RVNGInputStreamPtr &input, bool = false);
76uint16_t readU16(const RVNGInputStreamPtr &input, bool bigEndian=false);
77int16_t readS16(const RVNGInputStreamPtr &input, bool bigEndian=false);
78uint32_t readU32(const RVNGInputStreamPtr &input, bool bigEndian=false);
79int32_t readS32(const RVNGInputStreamPtr &input, bool bigEndian=false);
80uint64_t readU64(const RVNGInputStreamPtr &input, bool bigEndian=false);
81int64_t readS64(const RVNGInputStreamPtr &input, bool bigEndian=false);
82
83const unsigned char *readNBytes(const RVNGInputStreamPtr &input, unsigned long numBytes);
84
85void skip(const RVNGInputStreamPtr &input, unsigned long numBytes);
86
87void seek(const RVNGInputStreamPtr &input, unsigned long pos);
88void seekRelative(const RVNGInputStreamPtr &input, long pos);
89
90unsigned long getLength(const RVNGInputStreamPtr &input);
91
93{
94 virtual ~PMDStreamException() { }
95};
96
98{
100};
101
103{
104};
105
106}
107
108#endif // __LIBPAGEMAKER_UTILS_H__
109
110/* vim:set shiftwidth=2 softtabstop=2 expandtab: */
#define PMD_ATTRIBUTE_PRINTF(fmt, arg)
Definition: libpagemaker_utils.h:34
Definition: geometry.h:23
const unsigned char * readNBytes(const RVNGInputStreamPtr &input, const unsigned long numBytes)
Definition: libpagemaker_utils.cpp:121
void skip(const RVNGInputStreamPtr &input, unsigned long numBytes)
Definition: libpagemaker_utils.cpp:134
void seekRelative(const RVNGInputStreamPtr &input, const long pos)
Definition: libpagemaker_utils.cpp:150
uint16_t readU16(const RVNGInputStreamPtr &input, bool bigEndian)
Definition: libpagemaker_utils.cpp:58
int16_t readS16(const RVNGInputStreamPtr &input, const bool bigEndian)
Definition: libpagemaker_utils.cpp:74
unsigned long getLength(const RVNGInputStreamPtr &input)
Definition: libpagemaker_utils.cpp:159
librevenge::RVNGInputStream * RVNGInputStreamPtr
Definition: libpagemaker_utils.h:67
int8_t readS8(const RVNGInputStreamPtr &input, bool)
Definition: libpagemaker_utils.cpp:53
int32_t readS32(const RVNGInputStreamPtr &input, const bool bigEndian)
Definition: libpagemaker_utils.cpp:95
void seek(const RVNGInputStreamPtr &input, const unsigned long pos)
Definition: libpagemaker_utils.cpp:141
uint8_t readU8(const RVNGInputStreamPtr &input, bool)
Definition: libpagemaker_utils.cpp:41
uint64_t readU64(const RVNGInputStreamPtr &input, bool bigEndian)
Definition: libpagemaker_utils.cpp:100
uint32_t readU32(const RVNGInputStreamPtr &input, bool bigEndian)
Definition: libpagemaker_utils.cpp:79
int64_t readS64(const RVNGInputStreamPtr &input, const bool bigEndian)
Definition: libpagemaker_utils.cpp:116
Definition: libpagemaker_utils.h:98
EndOfStreamException()
Definition: libpagemaker_utils.cpp:185
Definition: libpagemaker_utils.h:103
Definition: libpagemaker_utils.h:70
void operator()(void *)
Definition: libpagemaker_utils.h:71
Definition: libpagemaker_utils.h:93
virtual ~PMDStreamException()
Definition: libpagemaker_utils.h:94

Generated for libpagemaker by doxygen 1.9.6