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 // debug message includes source file and line number
63 //#define VERBOSE_DEBUG 1
64 
65 // do nothing with debug messages in a release compile
66 #ifdef DEBUG
67 #ifdef VERBOSE_DEBUG
68 #define PMD_DEBUG_MSG(M) std::printf("%15s:%5d: ", __FILE__, __LINE__); std::printf M
69 #define PMD_DEBUG(M) M
70 #else
71 #define PMD_DEBUG_MSG(M) std::printf M
72 #define PMD_DEBUG(M) M
73 #endif
74 #else
75 #define PMD_DEBUG_MSG(M)
76 #define PMD_DEBUG(M)
77 #endif
78 
79 // Log Warnings and Errors, even for a release compile.
80 #define PMD_WARN_MSG(M) std::fprintf(stderr, "PageMaker [WARN] %15s:%d: ", __FILE__, __LINE__); std::fprintf(stderr, M)
81 #define PMD_ERR_MSG(M) std::fprintf(stderr, "PageMaker [ERROR] %15s:%d: ", __FILE__, __LINE__); std::fprintf(stderr, M)
82 
83 
84 #define PMD_NUM_ELEMENTS(array) sizeof(array)/sizeof(array[0])
85 
86 namespace libpagemaker
87 {
88 
89 typedef librevenge::RVNGInputStream *RVNGInputStreamPtr;
90 
92 {
93  void operator()(void *) {}
94 };
95 
96 uint8_t readU8(const RVNGInputStreamPtr &input, bool = false);
97 int8_t readS8(const RVNGInputStreamPtr &input, bool = false);
98 uint16_t readU16(const RVNGInputStreamPtr &input, bool bigEndian=false);
99 int16_t readS16(const RVNGInputStreamPtr &input, bool bigEndian=false);
100 uint32_t readU32(const RVNGInputStreamPtr &input, bool bigEndian=false);
101 int32_t readS32(const RVNGInputStreamPtr &input, bool bigEndian=false);
102 uint64_t readU64(const RVNGInputStreamPtr &input, bool bigEndian=false);
103 int64_t readS64(const RVNGInputStreamPtr &input, bool bigEndian=false);
104 
105 const unsigned char *readNBytes(const RVNGInputStreamPtr &input, unsigned long numBytes);
106 
107 void skip(const RVNGInputStreamPtr &input, unsigned long numBytes);
108 
109 void seek(const RVNGInputStreamPtr &input, unsigned long pos);
110 void seekRelative(const RVNGInputStreamPtr &input, long pos);
111 
112 unsigned long getLength(const RVNGInputStreamPtr &input);
113 
115 {
116  virtual ~PMDStreamException() { }
117 };
118 
120 {
122 };
123 
125 {
126 };
127 
128 }
129 
130 #endif // __LIBPAGEMAKER_UTILS_H__
131 
132 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
int8_t readS8(const RVNGInputStreamPtr &input, bool)
Definition: libpagemaker_utils.cpp:42
int64_t readS64(const RVNGInputStreamPtr &input, const bool bigEndian)
Definition: libpagemaker_utils.cpp:105
void skip(const RVNGInputStreamPtr &input, unsigned long numBytes)
Definition: libpagemaker_utils.cpp:123
unsigned long getLength(const RVNGInputStreamPtr &input)
Definition: libpagemaker_utils.cpp:148
int32_t readS32(const RVNGInputStreamPtr &input, const bool bigEndian)
Definition: libpagemaker_utils.cpp:84
uint8_t readU8(const RVNGInputStreamPtr &input, bool)
Definition: libpagemaker_utils.cpp:30
librevenge::RVNGInputStream * RVNGInputStreamPtr
Definition: libpagemaker_utils.h:89
void seek(const RVNGInputStreamPtr &input, const unsigned long pos)
Definition: libpagemaker_utils.cpp:130
Definition: libpagemaker_utils.h:124
Definition: libpagemaker_utils.h:119
Definition: libpagemaker_utils.h:114
Definition: libpagemaker_utils.h:91
int16_t readS16(const RVNGInputStreamPtr &input, const bool bigEndian)
Definition: libpagemaker_utils.cpp:63
virtual ~PMDStreamException()
Definition: libpagemaker_utils.h:116
void seekRelative(const RVNGInputStreamPtr &input, const long pos)
Definition: libpagemaker_utils.cpp:139
EndOfStreamException()
Definition: libpagemaker_utils.cpp:179
const unsigned char * readNBytes(const RVNGInputStreamPtr &input, const unsigned long numBytes)
Definition: libpagemaker_utils.cpp:110
Definition: geometry.h:20
uint16_t readU16(const RVNGInputStreamPtr &input, bool bigEndian)
Definition: libpagemaker_utils.cpp:47
uint64_t readU64(const RVNGInputStreamPtr &input, bool bigEndian)
Definition: libpagemaker_utils.cpp:89
void operator()(void *)
Definition: libpagemaker_utils.h:93
uint32_t readU32(const RVNGInputStreamPtr &input, bool bigEndian)
Definition: libpagemaker_utils.cpp:68

Generated for libpagemaker by doxygen 1.8.10