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

Generated for libpagemaker by doxygen 1.18.0