libcdr_utils.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* libcdr
00003  * Version: MPL 1.1 / GPLv2+ / LGPLv2+
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License or as specified alternatively below. You may obtain a copy of
00008  * the License at http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * Major Contributor(s):
00016  * Copyright (C) 2011 Fridrich Strba <fridrich.strba@bluewin.ch>
00017  * Copyright (C) 2011 Eilidh McAdam <tibbylickle@gmail.com>
00018  *
00019  *
00020  * All Rights Reserved.
00021  *
00022  * For minor contributions see the git repository.
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPLv2+"), or
00026  * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
00027  * in which case the provisions of the GPLv2+ or the LGPLv2+ are applicable
00028  * instead of those above.
00029  */
00030 
00031 #ifndef __LIBCDR_UTILS_H__
00032 #define __LIBCDR_UTILS_H__
00033 
00034 #include <stdio.h>
00035 #include <string>
00036 #include <math.h>
00037 #include <vector>
00038 #include <libwpd-stream/libwpd-stream.h>
00039 #include <libwpd/libwpd.h>
00040 
00041 #ifndef M_PI
00042 #define M_PI 3.14159265358979323846
00043 #endif
00044 
00045 #define CDR_EPSILON 1E-6
00046 #define CDR_ALMOST_ZERO(m) (fabs(m) <= CDR_EPSILON)
00047 
00048 #ifdef _MSC_VER
00049 
00050 typedef unsigned char uint8_t;
00051 typedef unsigned short uint16_t;
00052 typedef short int16_t;
00053 typedef unsigned uint32_t;
00054 typedef int int32_t;
00055 typedef unsigned __int64 uint64_t;
00056 typedef __int64 int64_t;
00057 
00058 #else
00059 
00060 #ifdef HAVE_CONFIG_H
00061 
00062 #include <config.h>
00063 
00064 #ifdef HAVE_STDINT_H
00065 #include <stdint.h>
00066 #endif
00067 
00068 #ifdef HAVE_INTTYPES_H
00069 #include <inttypes.h>
00070 #endif
00071 
00072 #else
00073 
00074 // assume that the headers are there inside LibreOffice build when no HAVE_CONFIG_H is defined
00075 #include <stdint.h>
00076 #include <inttypes.h>
00077 
00078 #endif
00079 
00080 #endif
00081 
00082 // debug message includes source file and line number
00083 //#define VERBOSE_DEBUG 1
00084 
00085 // do nothing with debug messages in a release compile
00086 #ifdef DEBUG
00087 #ifdef VERBOSE_DEBUG
00088 #define CDR_DEBUG_MSG(M) printf("%15s:%5d: ", __FILE__, __LINE__); printf M
00089 #define CDR_DEBUG(M) M
00090 #else
00091 #define CDR_DEBUG_MSG(M) printf M
00092 #define CDR_DEBUG(M) M
00093 #endif
00094 #else
00095 #define CDR_DEBUG_MSG(M)
00096 #define CDR_DEBUG(M)
00097 #endif
00098 
00099 namespace libcdr
00100 {
00101 
00102 uint8_t readU8(WPXInputStream *input, bool bigEndian=false);
00103 uint16_t readU16(WPXInputStream *input, bool bigEndian=false);
00104 uint32_t readU32(WPXInputStream *input, bool bigEndian=false);
00105 uint64_t readU64(WPXInputStream *input, bool bigEndian=false);
00106 int32_t readS32(WPXInputStream *input, bool bigEndian=false);
00107 int16_t readS16(WPXInputStream *input, bool bigEndian=false);
00108 
00109 double readDouble(WPXInputStream *input, bool bigEndian=false);
00110 
00111 double readFixedPoint(WPXInputStream *input, bool bigEndian=false);
00112 
00113 int cdr_round(double d);
00114 
00115 void writeU8(WPXBinaryData &buffer, const int value);
00116 void writeU16(WPXBinaryData &buffer, const int value);
00117 void writeU32(WPXBinaryData &buffer, const int value);
00118 void appendCharacters(WPXString &text, std::vector<unsigned char> characters, unsigned short charset);
00119 void appendCharacters(WPXString &text, std::vector<unsigned char> characters);
00120 
00121 #ifdef DEBUG
00122 const char *toFourCC(unsigned value, bool bigEndian=false);
00123 #endif
00124 
00125 class EndOfStreamException
00126 {
00127 };
00128 
00129 class GenericException
00130 {
00131 };
00132 
00133 class UnknownPrecisionException
00134 {
00135 };
00136 
00137 class EncodingException
00138 {
00139 };
00140 
00141 } // namespace libcdr
00142 
00143 #endif // __LIBCDR_UTILS_H__
00144 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */