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 #include <cmath>
14 #include <cstdio>
15 
16 #include <string>
17 
18 #include <boost/shared_ptr.hpp>
19 
20 #include <librevenge-stream/librevenge-stream.h>
21 #include <librevenge/librevenge.h>
22 
23 #ifndef M_PI
24 #define M_PI 3.14159265358979323846
25 #endif
26 
27 #ifdef _MSC_VER
28 
29 typedef unsigned char uint8_t;
30 typedef signed char int8_t;
31 typedef unsigned short uint16_t;
32 typedef short int16_t;
33 typedef unsigned uint32_t;
34 typedef int int32_t;
35 typedef unsigned __int64 uint64_t;
36 typedef __int64 int64_t;
37 
38 #else
39 
40 #ifdef HAVE_CONFIG_H
41 
42 #include <config.h>
43 
44 #ifdef HAVE_STDINT_H
45 #include <stdint.h>
46 #endif
47 
48 #ifdef HAVE_INTTYPES_H
49 #include <inttypes.h>
50 #endif
51 
52 #else
53 
54 // assume that the headers are there inside LibreOffice build when no HAVE_CONFIG_H is defined
55 #include <stdint.h>
56 #include <inttypes.h>
57 
58 #endif
59 
60 #endif
61 
62 #if defined(__clang__) || defined(__GNUC__)
63 # define PMD_ATTRIBUTE_PRINTF(fmt, arg) __attribute__((__format__(__printf__, fmt, arg)))
64 #else
65 # define PMD_ATTRIBUTE_PRINTF(fmt, arg)
66 #endif
67 
68 // debug message includes source file and line number
69 //#define VERBOSE_DEBUG 1
70 
71 // do nothing with debug messages in a release compile
72 #ifdef DEBUG
73 namespace libpagemaker
74 {
75 void debugPrint(const char *format, ...) PMD_ATTRIBUTE_PRINTF(1, 2);
76 }
77 #ifdef VERBOSE_DEBUG
78 #define PMD_DEBUG_MSG(M) libpagemaker::debugPrint("%15s:%5d: ", __FILE__, __LINE__); libpagemaker::debugPrint M
79 #define PMD_DEBUG(M) M
80 #else
81 #define PMD_DEBUG_MSG(M) libpagemaker::debugPrint M
82 #define PMD_DEBUG(M) M
83 #endif
84 
85 #define PMD_WARN_MSG(M) std::fprintf(stderr, "PageMaker [WARN] %15s:%d: ", __FILE__, __LINE__); std::fprintf(stderr, M)
86 #define PMD_ERR_MSG(M) std::fprintf(stderr, "PageMaker [ERROR] %15s:%d: ", __FILE__, __LINE__); std::fprintf(stderr, M)
87 #else
88 #define PMD_DEBUG_MSG(M)
89 #define PMD_DEBUG(M)
90 #define PMD_WARN_MSG(M)
91 #define PMD_ERR_MSG(M)
92 #endif
93 
94 #define PMD_NUM_ELEMENTS(array) sizeof(array)/sizeof(array[0])
95 
96 namespace libpagemaker
97 {
98 
99 typedef librevenge::RVNGInputStream *RVNGInputStreamPtr;
100 
102 {
103  void operator()(void *) {}
104 };
105 
106 uint8_t readU8(const RVNGInputStreamPtr &input, bool = false);
107 int8_t readS8(const RVNGInputStreamPtr &input, bool = false);
108 uint16_t readU16(const RVNGInputStreamPtr &input, bool bigEndian=false);
109 int16_t readS16(const RVNGInputStreamPtr &input, bool bigEndian=false);
110 uint32_t readU32(const RVNGInputStreamPtr &input, bool bigEndian=false);
111 int32_t readS32(const RVNGInputStreamPtr &input, bool bigEndian=false);
112 uint64_t readU64(const RVNGInputStreamPtr &input, bool bigEndian=false);
113 int64_t readS64(const RVNGInputStreamPtr &input, bool bigEndian=false);
114 
115 const unsigned char *readNBytes(const RVNGInputStreamPtr &input, unsigned long numBytes);
116 
117 void skip(const RVNGInputStreamPtr &input, unsigned long numBytes);
118 
119 void seek(const RVNGInputStreamPtr &input, unsigned long pos);
120 void seekRelative(const RVNGInputStreamPtr &input, long pos);
121 
122 unsigned long getLength(const RVNGInputStreamPtr &input);
123 
125 {
126  virtual ~PMDStreamException() { }
127 };
128 
130 {
132 };
133 
135 {
136 };
137 
138 }
139 
140 #endif // __LIBPAGEMAKER_UTILS_H__
141 
142 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
int8_t readS8(const RVNGInputStreamPtr &input, bool)
Definition: libpagemaker_utils.cpp:53
int64_t readS64(const RVNGInputStreamPtr &input, const bool bigEndian)
Definition: libpagemaker_utils.cpp:116
void skip(const RVNGInputStreamPtr &input, unsigned long numBytes)
Definition: libpagemaker_utils.cpp:134
unsigned long getLength(const RVNGInputStreamPtr &input)
Definition: libpagemaker_utils.cpp:159
int32_t readS32(const RVNGInputStreamPtr &input, const bool bigEndian)
Definition: libpagemaker_utils.cpp:95
uint8_t readU8(const RVNGInputStreamPtr &input, bool)
Definition: libpagemaker_utils.cpp:41
librevenge::RVNGInputStream * RVNGInputStreamPtr
Definition: libpagemaker_utils.h:99
void seek(const RVNGInputStreamPtr &input, const unsigned long pos)
Definition: libpagemaker_utils.cpp:141
Definition: libpagemaker_utils.h:134
Definition: libpagemaker_utils.h:129
Definition: libpagemaker_utils.h:124
#define PMD_ATTRIBUTE_PRINTF(fmt, arg)
Definition: libpagemaker_utils.h:65
Definition: libpagemaker_utils.h:101
int16_t readS16(const RVNGInputStreamPtr &input, const bool bigEndian)
Definition: libpagemaker_utils.cpp:74
virtual ~PMDStreamException()
Definition: libpagemaker_utils.h:126
void seekRelative(const RVNGInputStreamPtr &input, const long pos)
Definition: libpagemaker_utils.cpp:150
const unsigned char * readNBytes(const RVNGInputStreamPtr &input, const unsigned long numBytes)
Definition: libpagemaker_utils.cpp:121
Definition: geometry.h:20
uint16_t readU16(const RVNGInputStreamPtr &input, bool bigEndian)
Definition: libpagemaker_utils.cpp:58
uint64_t readU64(const RVNGInputStreamPtr &input, bool bigEndian)
Definition: libpagemaker_utils.cpp:100
void operator()(void *)
Definition: libpagemaker_utils.h:103
uint32_t readU32(const RVNGInputStreamPtr &input, bool bigEndian)
Definition: libpagemaker_utils.cpp:79

Generated for libpagemaker by doxygen 1.8.11