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 unsigned uint32_t;
00053 typedef int int32_t;
00054 typedef unsigned __int64 uint64_t;
00055 
00056 #else
00057 
00058 #ifdef HAVE_CONFIG_H
00059 
00060 #include <config.h>
00061 
00062 #ifdef HAVE_STDINT_H
00063 #include <stdint.h>
00064 #endif
00065 
00066 #ifdef HAVE_INTTYPES_H
00067 #include <inttypes.h>
00068 #endif
00069 
00070 #else
00071 
00072 // assume that the headers are there inside LibreOffice build when no HAVE_CONFIG_H is defined
00073 #include <stdint.h>
00074 #include <inttypes.h>
00075 
00076 #endif
00077 
00078 #endif
00079 
00080 // debug message includes source file and line number
00081 //#define VERBOSE_DEBUG 1
00082 
00083 // do nothing with debug messages in a release compile
00084 #ifdef DEBUG
00085 #ifdef VERBOSE_DEBUG
00086 #define CDR_DEBUG_MSG(M) printf("%15s:%5d: ", __FILE__, __LINE__); printf M
00087 #define CDR_DEBUG(M) M
00088 #else
00089 #define CDR_DEBUG_MSG(M) printf M
00090 #define CDR_DEBUG(M) M
00091 #endif
00092 #else
00093 #define CDR_DEBUG_MSG(M)
00094 #define CDR_DEBUG(M)
00095 #endif
00096 
00097 namespace libcdr
00098 {
00099 
00100 uint8_t readU8(WPXInputStream *input, bool bigEndian=false);
00101 uint16_t readU16(WPXInputStream *input, bool bigEndian=false);
00102 uint32_t readU32(WPXInputStream *input, bool bigEndian=false);
00103 uint64_t readU64(WPXInputStream *input, bool bigEndian=false);
00104 int32_t readS32(WPXInputStream *input, bool bigEndian=false);
00105 int16_t readS16(WPXInputStream *input, bool bigEndian=false);
00106 
00107 double readDouble(WPXInputStream *input, bool bigEndian=false);
00108 
00109 double readFixedPoint(WPXInputStream *input, bool bigEndian=false);
00110 
00111 int cdr_round(double d);
00112 
00113 void writeU8(WPXBinaryData &buffer, const int value);
00114 void writeU16(WPXBinaryData &buffer, const int value);
00115 void writeU32(WPXBinaryData &buffer, const int value);
00116 void appendCharacters(WPXString &text, std::vector<unsigned char> characters, unsigned short charset);
00117 void appendCharacters(WPXString &text, std::vector<unsigned char> characters);
00118 
00119 #ifdef DEBUG
00120 const char *toFourCC(unsigned value, bool bigEndian=false);
00121 #endif
00122 
00123 class EndOfStreamException
00124 {
00125 };
00126 
00127 class GenericException
00128 {
00129 };
00130 
00131 class UnknownPrecisionException
00132 {
00133 };
00134 
00135 } // namespace libcdr
00136 
00137 #endif // __LIBCDR_UTILS_H__
00138 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */