Coverage Report

Created: 2026-03-12 06:42

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libqxp/src/lib/libqxp_utils.h
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/*
3
 * This file is part of the libqxp project.
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
 */
9
10
#ifndef INCLUDED_LIBQXP_UTILS_H
11
#define INCLUDED_LIBQXP_UTILS_H
12
13
#ifdef HAVE_CONFIG_H
14
#include "config.h"
15
#endif
16
17
#include <cmath>
18
#include <memory>
19
#include <string>
20
21
#include <boost/cstdint.hpp>
22
23
#include <librevenge-stream/librevenge-stream.h>
24
#include <librevenge/librevenge.h>
25
26
750k
#define QXP_EPSILON 1E-6
27
778k
#define QXP_ALMOST_ZERO(m) (std::fabs(m) <= QXP_EPSILON)
28
29
#if defined(HAVE_FUNC_ATTRIBUTE_FORMAT)
30
#define QXP_ATTRIBUTE_PRINTF(fmt, arg) __attribute__((format(printf, fmt, arg)))
31
#else
32
#define QXP_ATTRIBUTE_PRINTF(fmt, arg)
33
#endif
34
35
#if defined(HAVE_CLANG_ATTRIBUTE_FALLTHROUGH)
36
#  define QXP_FALLTHROUGH [[clang::fallthrough]]
37
#elif defined(HAVE_GCC_ATTRIBUTE_FALLTHROUGH)
38
708k
#  define QXP_FALLTHROUGH __attribute__((fallthrough))
39
#else
40
#  define QXP_FALLTHROUGH ((void) 0)
41
#endif
42
43
// do nothing with debug messages in a release compile
44
#ifdef DEBUG
45
namespace libqxp
46
{
47
void debugPrint(const char *format, ...) QXP_ATTRIBUTE_PRINTF(1, 2);
48
}
49
50
#define QXP_DEBUG_MSG(M) libqxp::debugPrint M
51
#define QXP_DEBUG(M) M
52
#else
53
#define QXP_DEBUG_MSG(M)
54
#define QXP_DEBUG(M)
55
#endif
56
57
#define QXP_NUM_ELEMENTS(array) (sizeof(array) / sizeof(array[0]))
58
59
namespace libqxp
60
{
61
62
struct QXPDummyDeleter
63
{
64
20.1k
  void operator()(void *) {}
65
};
66
67
template<typename T, typename... Args>
68
std::unique_ptr<T> make_unique(Args &&... args)
69
{
70
  return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
71
}
72
73
uint8_t readU8(librevenge::RVNGInputStream *input, bool = false);
74
uint16_t readU16(librevenge::RVNGInputStream *input, bool bigEndian=false);
75
uint32_t readU32(librevenge::RVNGInputStream *input, bool bigEndian=false);
76
uint64_t readU64(librevenge::RVNGInputStream *input, bool bigEndian=false);
77
int16_t readS16(librevenge::RVNGInputStream *input, bool bigEndian=false);
78
int32_t readS32(librevenge::RVNGInputStream *input, bool bigEndian=false);
79
double readFloat16(librevenge::RVNGInputStream *input, bool bigEndian=false);
80
double readFraction(librevenge::RVNGInputStream *input, bool bigEndian=false);
81
82
const unsigned char *readNBytes(librevenge::RVNGInputStream *input, unsigned long numBytes);
83
84
std::string readCString(librevenge::RVNGInputStream *input);
85
std::string readPascalString(librevenge::RVNGInputStream *input);
86
std::string readString(librevenge::RVNGInputStream *input, const unsigned length);
87
std::string readPlatformString(librevenge::RVNGInputStream *input, bool bigEndian=false);
88
89
void skip(librevenge::RVNGInputStream *input, unsigned long numBytes);
90
91
void seek(librevenge::RVNGInputStream *input, unsigned long pos);
92
void seekRelative(librevenge::RVNGInputStream *input, long pos);
93
94
unsigned long getRemainingLength(librevenge::RVNGInputStream *input);
95
96
uint8_t readU8(std::shared_ptr<librevenge::RVNGInputStream> input, bool = false);
97
uint16_t readU16(std::shared_ptr<librevenge::RVNGInputStream> input, bool bigEndian=false);
98
uint32_t readU32(std::shared_ptr<librevenge::RVNGInputStream> input, bool bigEndian=false);
99
uint64_t readU64(std::shared_ptr<librevenge::RVNGInputStream> input, bool bigEndian=false);
100
int16_t readS16(std::shared_ptr<librevenge::RVNGInputStream> input, bool bigEndian=false);
101
int32_t readS32(std::shared_ptr<librevenge::RVNGInputStream> input, bool bigEndian=false);
102
double readFloat16(std::shared_ptr<librevenge::RVNGInputStream> input, bool bigEndian=false);
103
double readFraction(std::shared_ptr<librevenge::RVNGInputStream> input, bool bigEndian=false);
104
105
const unsigned char *readNBytes(std::shared_ptr<librevenge::RVNGInputStream> input, unsigned long numBytes);
106
107
std::string readCString(std::shared_ptr<librevenge::RVNGInputStream> input);
108
std::string readPascalString(std::shared_ptr<librevenge::RVNGInputStream> input);
109
std::string readString(std::shared_ptr<librevenge::RVNGInputStream> input, const unsigned length);
110
std::string readPlatformString(std::shared_ptr<librevenge::RVNGInputStream> input, bool bigEndian=false);
111
112
void skip(std::shared_ptr<librevenge::RVNGInputStream> input, unsigned long numBytes);
113
114
void seek(std::shared_ptr<librevenge::RVNGInputStream> input, unsigned long pos);
115
void seekRelative(std::shared_ptr<librevenge::RVNGInputStream> input, long pos);
116
117
unsigned long getRemainingLength(const std::shared_ptr<librevenge::RVNGInputStream> &input);
118
119
double deg2rad(double value);
120
double normalizeDegAngle(double degAngle);
121
double normalizeRadAngle(double radAngle);
122
123
void appendCharacters(librevenge::RVNGString &text, const char *characters, const size_t size,
124
                      const char *encoding);
125
126
class EndOfStreamException
127
{
128
public:
129
  EndOfStreamException();
130
};
131
132
class GenericException
133
{
134
};
135
136
// parser exceptions
137
138
class FileAccessError
139
{
140
};
141
142
class ParseError
143
{
144
};
145
146
class UnsupportedFormat
147
{
148
};
149
150
} // namespace libqxp
151
152
#endif // INCLUDED_LIBQXP_UTILS_H
153
154
/* vim:set shiftwidth=2 softtabstop=2 expandtab: */