WPSDebug.h Source File documentation

WPSDebug.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /* libwps
3 * Version: MPL 2.0 / LGPLv2.1+
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 * Major Contributor(s):
10 * Copyright (C) 2009, 2011 Alonso Laurent (alonso@loria.fr)
11 * Copyright (C) 2006, 2007 Andrew Ziem
12 * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
13 * Copyright (C) 2004 Marc Maurer (uwog@uwog.net)
14 * Copyright (C) 2003-2005 William Lachance (william.lachance@sympatico.ca)
15 *
16 * For minor contributions see the git repository.
17 *
18 * Alternatively, the contents of this file may be used under the terms
19 * of the GNU Lesser General Public License Version 2.1 or later
20 * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
21 * applicable instead of those above.
22 *
23 * For further information visit http://libwps.sourceforge.net
24 */
25
26 #ifndef WPS_DEBUG
27 # define WPS_DEBUG
28
29 #include <string>
30
31 #include "libwps_internal.h"
32
33 # if defined(DEBUG_WITH_FILES)
34 #include <fstream>
35 #include <map>
36 #include <sstream>
37 #include <vector>
38
40 namespace libwps
41 {
43 namespace Debug
44 {
48 bool dumpFile(librevenge::RVNGBinaryData &data, char const *fileName);
49
51 std::string flattenFileName(std::string const &name);
52 }
53
55 typedef std::stringstream DebugStream;
56
59 class DebugFile
60 {
61 public:
63 explicit DebugFile(RVNGInputStreamPtr const &ip=RVNGInputStreamPtr())
64 : m_file()
65 , m_on(false)
66 , m_input(ip)
67 , m_actOffset(-1)
68 , m_notes()
69 , m_skipZones() { }
70
72 void setStream(RVNGInputStreamPtr const &ip)
73 {
74 m_input = ip;
75 }
77 ~DebugFile()
78 {
79 reset();
80 }
82 bool open(std::string const &filename);
84 void reset()
85 {
86 write();
87 m_file.close();
88 m_on = false;
89 m_notes.resize(0);
90 m_skipZones.resize(0);
91 m_actOffset = -1;
92 }
94 void addPos(long pos);
96 void addNote(char const *note);
98 void addDelimiter(long pos, char c);
99
101 void skipZone(long beginPos, long endPos)
102 {
103 if (m_on) m_skipZones.push_back(Vec2<long>(beginPos, endPos));
104 }
105
106 protected:
108 void write();
109
111 void sort();
112
114 mutable std::ofstream m_file;
116 mutable bool m_on;
117
119 RVNGInputStreamPtr m_input;
120
122 struct NotePos
123 {
125 NotePos()
126 : m_pos(-1)
127 , m_text("")
128 , m_breaking(false) { }
129
131 NotePos(long p, std::string const &n, bool br=true)
132 : m_pos(p)
133 , m_text(n)
134 , m_breaking(br) {}
136 long m_pos;
138 std::string m_text;
140 bool m_breaking;
141
143 bool operator<(NotePos const &p) const
144 {
145 long diff = m_pos-p.m_pos;
146 if (diff) return (diff < 0) ? true : false;
147 if (m_breaking != p.m_breaking) return m_breaking;
148 return m_text < p.m_text;
149 }
153 struct NotePosLt
154 {
156 bool operator()(NotePos const &s1, NotePos const &s2) const
157 {
158 return s1 < s2;
159 }
160 };
164 typedef std::map<NotePos, int,struct NotePosLt> Map;
165 };
166
168 long m_actOffset;
170 std::vector<NotePos> m_notes;
172 std::vector<Vec2<long> > m_skipZones;
173 };
174 }
175 # else
176 namespace libwps
177 {
178 namespace Debug
179 {
180 inline bool dumpFile(librevenge::RVNGBinaryData &, char const *)
181 {
182 return true;
183 }
184
185 inline std::string flattenFileName(std::string const &name)
186 {
187 return name;
188 }
189 }
190
191 class DebugStream
192 {
193 public:
194 template <class T>
195 DebugStream &operator<<(T const &)
196 {
197 return *this;
198 }
199
200 static std::string str()
201 {
202 return std::string("");
203 }
204 static void str(std::string const &) { }
205 };
206
207 class DebugFile
208 {
209 public:
210 explicit DebugFile(RVNGInputStreamPtr) {}
211 DebugFile() {}
212 static void setStream(RVNGInputStreamPtr) { }
213 ~DebugFile() { }
214
215 static bool open(std::string const &)
216 {
217 return true;
218 }
219
220 static void addPos(long) {}
221 static void addNote(char const *) {}
222 static void addDelimiter(long, char) {}
223
224 static void reset() { }
225
226 static void skipZone(long, long) {}
227 };
228 }
229 # endif
230
231 #endif
232
233 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
libwps::DebugStream::str
static std::string str()
Definition: WPSDebug.h:200
libwps::DebugFile::open
static bool open(std::string const &)
Definition: WPSDebug.h:215
Vec2::PosSizeLtX
internal struct used to create sorted map, sorted by X
Definition: libwps_internal.h:675
libwps::DebugFile::addPos
static void addPos(long)
Definition: WPSDebug.h:220
libwps::Debug::dumpFile
bool dumpFile(librevenge::RVNGBinaryData &, char const *)
Definition: WPSDebug.h:180
libwps
Definition: libwps_internal.cpp:38
libwps::DebugFile::reset
static void reset()
Definition: WPSDebug.h:224
libwps::DebugFile::skipZone
static void skipZone(long, long)
Definition: WPSDebug.h:226
libwps::DebugStream::operator<<
DebugStream & operator<<(T const &)
Definition: WPSDebug.h:195
libwps::Debug::flattenFileName
std::string flattenFileName(std::string const &name)
Definition: WPSDebug.h:185
Vec2
small class which defines a vector with 2 elements
Definition: libwps_internal.h:534
WPS_DEBUG_MSG
#define WPS_DEBUG_MSG(M)
Definition: libwps_internal.h:134
libwps::DebugStream::str
static void str(std::string const &)
Definition: WPSDebug.h:204
libwps::DebugFile::DebugFile
DebugFile(RVNGInputStreamPtr)
Definition: WPSDebug.h:210
libwps::DebugFile::addNote
static void addNote(char const *)
Definition: WPSDebug.h:221
libwps::DebugStream
Definition: WPSDebug.h:191
libwps::readU8
uint8_t readU8(librevenge::RVNGInputStream *input)
Definition: libwps_internal.cpp:40
libwps_tools_win::Language::name
std::string name(long id)
returns the name given Windows© id
Definition: libwps_tools_win.cpp:7332
libwps::DebugFile::~DebugFile
~DebugFile()
Definition: WPSDebug.h:213
RVNGInputStreamPtr
std::shared_ptr< librevenge::RVNGInputStream > RVNGInputStreamPtr
shared pointer to librevenge::RVNGInputStream
Definition: libwps_internal.h:87
WPSDebug.h
libwps::DebugFile::addDelimiter
static void addDelimiter(long, char)
Definition: WPSDebug.h:222
libwps_internal.h
libwps::DebugFile
Definition: WPSDebug.h:207
libwps::DebugFile::DebugFile
DebugFile()
Definition: WPSDebug.h:211
libwps::DebugFile::setStream
static void setStream(RVNGInputStreamPtr)
Definition: WPSDebug.h:212