libebook_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 libe-book 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 LIBEBOOK_UTILS_H_INCLUDED
00011 #define LIBEBOOK_UTILS_H_INCLUDED
00012 
00013 #include <string>
00014 
00015 #include <boost/shared_ptr.hpp>
00016 
00017 #include <librevenge-stream/librevenge-stream.h>
00018 #include <librevenge/librevenge.h>
00019 
00020 #ifdef _MSC_VER
00021 
00022 typedef unsigned char uint8_t;
00023 typedef unsigned short uint16_t;
00024 typedef short int16_t;
00025 typedef unsigned uint32_t;
00026 typedef int int32_t;
00027 typedef unsigned __int64 uint64_t;
00028 typedef __int64 int64_t;
00029 
00030 #else
00031 
00032 #ifdef HAVE_CONFIG_H
00033 
00034 #include <config.h>
00035 
00036 #ifdef HAVE_STDINT_H
00037 #include <stdint.h>
00038 #endif
00039 
00040 #ifdef HAVE_INTTYPES_H
00041 #include <inttypes.h>
00042 #endif
00043 
00044 #else
00045 
00046 // assume that the headers are there inside LibreOffice build when no HAVE_CONFIG_H is defined
00047 #include <stdint.h>
00048 #include <inttypes.h>
00049 
00050 #endif
00051 
00052 #endif
00053 
00054 // debug message includes source file and line number
00055 //#define VERBOSE_DEBUG 1
00056 
00057 // do nothing with debug messages in a release compile
00058 #ifdef DEBUG
00059 
00060 namespace libebook
00061 {
00062 void debugPrint(const char *format, ...);
00063 }
00064 
00065 #ifdef VERBOSE_DEBUG
00066 #define EBOOK_DEBUG_MSG(M) libebook::debugPrint("%15s:%5d: ", __FILE__, __LINE__); libebook::debugPrint M
00067 #define EBOOK_DEBUG(M) M
00068 #else
00069 #define EBOOK_DEBUG_MSG(M) libebook::debugPrint M
00070 #define EBOOK_DEBUG(M) M
00071 #endif
00072 #else
00073 #define EBOOK_DEBUG_MSG(M)
00074 #define EBOOK_DEBUG(M)
00075 #endif
00076 
00077 #define EBOOK_NUM_ELEMENTS(array) sizeof(array)/sizeof(array[0])
00078 
00079 namespace libebook
00080 {
00081 
00082 typedef boost::shared_ptr<librevenge::RVNGInputStream> RVNGInputStreamPtr_t;
00083 
00084 struct EBOOKDummyDeleter
00085 {
00086   void operator()(void *) {}
00087 };
00088 
00089 uint8_t readU8(librevenge::RVNGInputStream *input, bool = false);
00090 uint16_t readU16(librevenge::RVNGInputStream *input, bool bigEndian=false);
00091 uint32_t readU32(librevenge::RVNGInputStream *input, bool bigEndian=false);
00092 uint64_t readU64(librevenge::RVNGInputStream *input, bool bigEndian=false);
00093 
00094 const unsigned char *readNBytes(librevenge::RVNGInputStream *input, unsigned long numBytes);
00095 
00096 std::string readCString(librevenge::RVNGInputStream *input);
00097 std::string readPascalString(librevenge::RVNGInputStream *input);
00098 
00099 void skip(librevenge::RVNGInputStream *input, unsigned long numBytes);
00100 
00101 void seek(librevenge::RVNGInputStream *input, unsigned long pos);
00102 void seekRelative(librevenge::RVNGInputStream *input, long pos);
00103 
00104 unsigned long getRemainingLength(librevenge::RVNGInputStream *input);
00105 
00106 uint8_t readU8(boost::shared_ptr<librevenge::RVNGInputStream> input, bool = false);
00107 uint16_t readU16(boost::shared_ptr<librevenge::RVNGInputStream> input, bool bigEndian=false);
00108 uint32_t readU32(boost::shared_ptr<librevenge::RVNGInputStream> input, bool bigEndian=false);
00109 uint64_t readU64(boost::shared_ptr<librevenge::RVNGInputStream> input, bool bigEndian=false);
00110 
00111 const unsigned char *readNBytes(boost::shared_ptr<librevenge::RVNGInputStream> input, unsigned long numBytes);
00112 
00113 std::string readCString(boost::shared_ptr<librevenge::RVNGInputStream> input);
00114 std::string readPascalString(boost::shared_ptr<librevenge::RVNGInputStream> input);
00115 
00116 void skip(boost::shared_ptr<librevenge::RVNGInputStream> input, unsigned long numBytes);
00117 
00118 void seek(boost::shared_ptr<librevenge::RVNGInputStream> input, unsigned long pos);
00119 void seekRelative(boost::shared_ptr<librevenge::RVNGInputStream> input, long pos);
00120 
00121 unsigned long getRemainingLength(boost::shared_ptr<librevenge::RVNGInputStream> input);
00122 
00123 bool findSubStreamByExt(const RVNGInputStreamPtr_t &input, const std::string &ext, unsigned &id);
00124 
00125 class EndOfStreamException
00126 {
00127 public:
00128   EndOfStreamException();
00129 };
00130 
00131 class GenericException
00132 {
00133 };
00134 
00135 // parser exceptions
00136 
00137 class FileAccessError
00138 {
00139 };
00140 
00141 class PackageError
00142 {
00143 };
00144 
00145 class ParseError
00146 {
00147 };
00148 
00149 class PasswordMismatch
00150 {
00151 };
00152 
00153 class UnsupportedEncryption
00154 {
00155 };
00156 
00157 class UnsupportedFormat
00158 {
00159 };
00160 
00161 } // namespace libebook
00162 
00163 #endif // LIBEBOOK_UTILS_H_INCLUDED
00164 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */