libpagemaker_utils.h Source File documentation

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
67 typedef librevenge::RVNGInputStream *RVNGInputStreamPtr;
68
69 struct PMDDummyDeleter
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
92 struct PMDStreamException
93{
94 virtual ~PMDStreamException() { }
95};
96
97 struct EndOfStreamException : public PMDStreamException
98{
99 EndOfStreamException();
100};
101
102 struct GenericException
103{
104};
105
106}
107
108#endif // __LIBPAGEMAKER_UTILS_H__
109
110/* vim:set shiftwidth=2 softtabstop=2 expandtab: */
PMD_ATTRIBUTE_PRINTF
#define PMD_ATTRIBUTE_PRINTF(fmt, arg)
Definition libpagemaker_utils.h:34
libpagemaker
Definition geometry.h:23
libpagemaker::readNBytes
const unsigned char * readNBytes(const RVNGInputStreamPtr &input, const unsigned long numBytes)
Definition libpagemaker_utils.cpp:121
libpagemaker::skip
void skip(const RVNGInputStreamPtr &input, unsigned long numBytes)
Definition libpagemaker_utils.cpp:134
libpagemaker::seekRelative
void seekRelative(const RVNGInputStreamPtr &input, const long pos)
Definition libpagemaker_utils.cpp:150
libpagemaker::readU16
uint16_t readU16(const RVNGInputStreamPtr &input, bool bigEndian)
Definition libpagemaker_utils.cpp:58
libpagemaker::readS16
int16_t readS16(const RVNGInputStreamPtr &input, const bool bigEndian)
Definition libpagemaker_utils.cpp:74
libpagemaker::getLength
unsigned long getLength(const RVNGInputStreamPtr &input)
Definition libpagemaker_utils.cpp:159
libpagemaker::RVNGInputStreamPtr
librevenge::RVNGInputStream * RVNGInputStreamPtr
Definition libpagemaker_utils.h:67
libpagemaker::readS8
int8_t readS8(const RVNGInputStreamPtr &input, bool)
Definition libpagemaker_utils.cpp:53
libpagemaker::readS32
int32_t readS32(const RVNGInputStreamPtr &input, const bool bigEndian)
Definition libpagemaker_utils.cpp:95
libpagemaker::seek
void seek(const RVNGInputStreamPtr &input, const unsigned long pos)
Definition libpagemaker_utils.cpp:141
libpagemaker::readU8
uint8_t readU8(const RVNGInputStreamPtr &input, bool)
Definition libpagemaker_utils.cpp:41
libpagemaker::readU64
uint64_t readU64(const RVNGInputStreamPtr &input, bool bigEndian)
Definition libpagemaker_utils.cpp:100
libpagemaker::readU32
uint32_t readU32(const RVNGInputStreamPtr &input, bool bigEndian)
Definition libpagemaker_utils.cpp:79
libpagemaker::readS64
int64_t readS64(const RVNGInputStreamPtr &input, const bool bigEndian)
Definition libpagemaker_utils.cpp:116
libpagemaker::EndOfStreamException::EndOfStreamException
EndOfStreamException()
Definition libpagemaker_utils.cpp:185
libpagemaker::GenericException
Definition libpagemaker_utils.h:103
libpagemaker::PMDDummyDeleter
Definition libpagemaker_utils.h:70
libpagemaker::PMDDummyDeleter::operator()
void operator()(void *)
Definition libpagemaker_utils.h:71
libpagemaker::PMDStreamException
Definition libpagemaker_utils.h:93
libpagemaker::PMDStreamException::~PMDStreamException
virtual ~PMDStreamException()
Definition libpagemaker_utils.h:94