libmspub_utils.h
Go to the documentation of this file.
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* This file is part of the libmspub project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef INCLUDED_LIBMSPUB_UTILS_H
#define INCLUDED_LIBMSPUB_UTILS_H
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <cmath>
#include <vector>
#include <boost/cstdint.hpp>
#include <librevenge/librevenge.h>
#include <librevenge-stream/librevenge-stream.h>
#include "MSPUBTypes.h"
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#if defined(HAVE_FUNC_ATTRIBUTE_FORMAT)
# define MSPUB_ATTRIBUTE_PRINTF(fmt, arg) __attribute__((__format__(__printf__, fmt, arg)))
#else
# define MSPUB_ATTRIBUTE_PRINTF(fmt, arg)
#endif
#if defined(HAVE_CLANG_ATTRIBUTE_FALLTHROUGH)
# define MSPUB_FALLTHROUGH [[clang::fallthrough]]
#elif defined(HAVE_GCC_ATTRIBUTE_FALLTHROUGH)
# define MSPUB_FALLTHROUGH __attribute__((fallthrough))
#else
# define MSPUB_FALLTHROUGH ((void) 0)
#endif
// do nothing with debug messages in a release compile
#ifdef DEBUG
namespace libmspub
{
void debugPrint(const char *format, ...) MSPUB_ATTRIBUTE_PRINTF(1, 2);
}
#define MSPUB_DEBUG_MSG(M) libmspub::debugPrint M
#define MSPUB_DEBUG(M) M
#else
#define MSPUB_DEBUG_MSG(M)
#define MSPUB_DEBUG(M)
#endif
namespace libmspub
{
const char *mimeByImgType(ImgType type);
const char *windowsCharsetNameByOriginalCharset(const char *name);
uint8_t readU8(librevenge::RVNGInputStream *input);
uint16_t readU16(librevenge::RVNGInputStream *input);
uint32_t readU32(librevenge::RVNGInputStream *input);
uint64_t readU64(librevenge::RVNGInputStream *input);
int8_t readS8(librevenge::RVNGInputStream *input);
int16_t readS16(librevenge::RVNGInputStream *input);
int32_t readS32(librevenge::RVNGInputStream *input);
double readFixedPoint(librevenge::RVNGInputStream *input);
double toFixedPoint(int fp);
void readNBytes(librevenge::RVNGInputStream *input, unsigned long length, std::vector<unsigned char> &out);
unsigned long getLength(librevenge::RVNGInputStream *input);
void appendCharacters(librevenge::RVNGString &text, const std::vector<unsigned char> &characters, const char *encoding);
bool stillReading(librevenge::RVNGInputStream *input, unsigned long until);
void rotateCounter(double &x, double &y, double centerX, double centerY, short rotation);
void flipIfNecessary(double &x, double &y, double centerX, double centerY, bool flipVertical, bool flipHorizontal);
unsigned correctModulo(int x, unsigned n);
double doubleModulo(double x, double y);
template <class MapT> typename MapT::mapped_type *getIfExists(MapT &map, const typename MapT::key_type &key)
{
auto i = map.find(key);
return i == map.end() ? nullptr : &(i->second);
}
template <class MapT> const typename MapT::mapped_type *getIfExists_const(MapT &map, const typename MapT::key_type &key)
{
auto i = map.find(key);
return i == map.end() ? nullptr : &(i->second);
}
template <class MapT> typename MapT::mapped_type ptr_getIfExists(MapT &map, const typename MapT::key_type &key)
{
typename MapT::iterator i = map.find(key);
return i == map.end() ? NULL : i->second;
}
class EndOfStreamException
{
};
class GenericException
{
};
librevenge::RVNGBinaryData inflateData(librevenge::RVNGBinaryData);
} // namespace libmspub
#endif // INCLUDED_LIBMSPUB_UTILS_H
/* vim:set shiftwidth=2 softtabstop=2 expandtab: */
MSPUBTypes.h
libmspub::EndOfStreamException
Definition libmspub_utils.h:106
libmspub::GenericException
Definition libmspub_utils.h:110
MSPUB_ATTRIBUTE_PRINTF
#define MSPUB_ATTRIBUTE_PRINTF(fmt, arg)
Definition libmspub_utils.h:35
libmspub
Definition Arrow.h:14
libmspub::readS16
int16_t readS16(librevenge::RVNGInputStream *input)
Definition libmspub_utils.cpp:306
libmspub::getLength
unsigned long getLength(librevenge::RVNGInputStream *const input)
Definition libmspub_utils.cpp:349
libmspub::readU16
uint16_t readU16(librevenge::RVNGInputStream *input)
Definition libmspub_utils.cpp:285
libmspub::correctModulo
unsigned correctModulo(int x, unsigned n)
Definition libmspub_utils.cpp:151
libmspub::readFixedPoint
double readFixedPoint(librevenge::RVNGInputStream *input)
Definition libmspub_utils.cpp:132
libmspub::ptr_getIfExists
MapT::mapped_type ptr_getIfExists(MapT &map, const typename MapT::key_type &key)
Definition libmspub_utils.h:99
libmspub::readU8
uint8_t readU8(librevenge::RVNGInputStream *input)
Definition libmspub_utils.cpp:266
libmspub::readS32
int32_t readS32(librevenge::RVNGInputStream *input)
Definition libmspub_utils.cpp:311
libmspub::readS8
int8_t readS8(librevenge::RVNGInputStream *input)
Definition libmspub_utils.cpp:301
libmspub::inflateData
librevenge::RVNGBinaryData inflateData(librevenge::RVNGBinaryData deflated)
Definition libmspub_utils.cpp:167
libmspub::getIfExists_const
const MapT::mapped_type * getIfExists_const(MapT &map, const typename MapT::key_type &key)
Definition libmspub_utils.h:93
libmspub::rotateCounter
void rotateCounter(double &x, double &y, double centerX, double centerY, short rotation)
Definition libmspub_utils.cpp:96
libmspub::mimeByImgType
const char * mimeByImgType(ImgType type)
Definition libmspub_utils.cpp:72
libmspub::toFixedPoint
double toFixedPoint(int fp)
Definition libmspub_utils.cpp:125
libmspub::readU64
uint64_t readU64(librevenge::RVNGInputStream *input)
Definition libmspub_utils.cpp:316
libmspub::doubleModulo
double doubleModulo(double x, double y)
Definition libmspub_utils.cpp:108
libmspub::flipIfNecessary
void flipIfNecessary(double &x, double &y, double centerX, double centerY, bool flipVertical, bool flipHorizontal)
Definition libmspub_utils.cpp:137
libmspub::appendCharacters
void appendCharacters(librevenge::RVNGString &text, const std::vector< unsigned char > &characters, const char *encoding)
Definition libmspub_utils.cpp:383
libmspub::windowsCharsetNameByOriginalCharset
const char * windowsCharsetNameByOriginalCharset(const char *name)
Definition libmspub_utils.cpp:39
libmspub::readU32
uint32_t readU32(librevenge::RVNGInputStream *input)
Definition libmspub_utils.cpp:292
libmspub::readNBytes
void readNBytes(librevenge::RVNGInputStream *input, unsigned long length, std::vector< unsigned char > &out)
Definition libmspub_utils.cpp:329
libmspub::getIfExists
MapT::mapped_type * getIfExists(MapT &map, const typename MapT::key_type &key)
Definition libmspub_utils.h:87
libmspub::stillReading
bool stillReading(librevenge::RVNGInputStream *input, unsigned long until)
Definition libmspub_utils.cpp:416
libmspub::ImgType
ImgType
Definition MSPUBTypes.h:214