libetonyek_utils.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /*
00003  * This file is part of the libetonyek project.
00004  *
00005  * This Source Code Form is subject to the terms of the Mozilla Public
00006  * License, v. 2.0. If a copy of the MPL was not distributed with this
00007  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
00008  */
00009 
00010 #ifndef LIBETONYEK_UTILS_H_INCLUDED
00011 #define LIBETONYEK_UTILS_H_INCLUDED
00012 
00013 #include <cmath>
00014 #include <stdio.h>
00015 #include <string>
00016 
00017 #include <boost/shared_ptr.hpp>
00018 
00019 #include <libwpd/libwpd.h>
00020 #include <libwpd-stream/libwpd-stream.h>
00021 
00022 #ifdef _MSC_VER
00023 
00024 typedef unsigned char uint8_t;
00025 typedef unsigned short uint16_t;
00026 typedef unsigned uint32_t;
00027 typedef unsigned __int64 uint64_t;
00028 typedef signed char int8_t;
00029 typedef short int16_t;
00030 typedef int int32_t;
00031 typedef __int64 int64_t;
00032 
00033 #else
00034 
00035 #ifdef HAVE_CONFIG_H
00036 
00037 #include <config.h>
00038 
00039 #ifdef HAVE_STDINT_H
00040 #include <stdint.h>
00041 #endif
00042 
00043 #ifdef HAVE_INTTYPES_H
00044 #include <inttypes.h>
00045 #endif
00046 
00047 #else
00048 
00049 // assume that the headers are there inside LibreOffice build when no HAVE_CONFIG_H is defined
00050 #include <stdint.h>
00051 #include <inttypes.h>
00052 
00053 #endif
00054 
00055 #endif
00056 
00057 #define KEY_EPSILON 1e-9
00058 #define KEY_ALMOST_ZERO(x) (std::fabs(x) < KEY_EPSILON)
00059 
00060 #define KEY_NUM_ELEMENTS(array) (sizeof(array) / sizeof((array)[0]))
00061 
00062 // debug message includes source file and line number
00063 //#define VERBOSE_DEBUG 1
00064 
00065 #undef DEBUG
00066 // do nothing with debug messages in a release compile
00067 #ifdef DEBUG
00068 #ifdef VERBOSE_DEBUG
00069 #define KEY_DEBUG_MSG(M) printf("%15s:%5d: ", FILE, LINE); printf M
00070 #define KEY_DEBUG(M) M
00071 #else
00072 #define KEY_DEBUG_MSG(M) printf M
00073 #define KEY_DEBUG(M) M
00074 #endif
00075 #else
00076 #define KEY_DEBUG_MSG(M)
00077 #define KEY_DEBUG(M)
00078 #endif
00079 
00080 namespace libetonyek
00081 {
00082 
00083 struct KEYDummyDeleter
00084 {
00085   void operator()(void *) {}
00086 };
00087 
00088 typedef boost::shared_ptr<WPXInputStream> WPXInputStreamPtr_t;
00089 
00090 uint8_t readU8(const WPXInputStreamPtr_t &input, bool = false);
00091 uint16_t readU16(const WPXInputStreamPtr_t &input, bool bigEndian=false);
00092 uint32_t readU32(const WPXInputStreamPtr_t &input, bool bigEndian=false);
00093 uint64_t readU64(const WPXInputStreamPtr_t &input, bool bigEndian=false);
00094 
00101 bool approxEqual(double x, double y, double eps = KEY_EPSILON);
00102 
00108 double pt2in(double d);
00109 
00110 class EndOfStreamException
00111 {
00112 };
00113 
00114 class GenericException
00115 {
00116 };
00117 
00118 } // namespace libetonyek
00119 
00120 #endif // LIBETONYEK_UTILS_H_INCLUDED
00121 
00122 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */