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
40namespace libwps
41{
43namespace Debug
44{
48bool dumpFile(librevenge::RVNGBinaryData const &data, char const *fileName);
49
51std::string flattenFileName(std::string const &name);
52}
53
55typedef std::stringstream DebugStream;
56
59class DebugFile
60{
61public:
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 }
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
106protected:
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
176namespace libwps
177{
178namespace Debug
179{
180inline bool dumpFile(librevenge::RVNGBinaryData const &, char const *)
181{
182 return true;
183}
184
185inline std::string flattenFileName(std::string const &name)
186{
187 return name;
188}
189}
190
192{
193public:
194 template <class T>
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
208{
209public:
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: */
Definition WPSDebug.h:208
static void reset()
Definition WPSDebug.h:224
~DebugFile()
Definition WPSDebug.h:213
static void addDelimiter(long, char)
Definition WPSDebug.h:222
DebugFile()
Definition WPSDebug.h:211
static void addPos(long)
Definition WPSDebug.h:220
DebugFile(RVNGInputStreamPtr)
Definition WPSDebug.h:210
static bool open(std::string const &)
Definition WPSDebug.h:215
static void setStream(RVNGInputStreamPtr)
Definition WPSDebug.h:212
static void addNote(char const *)
Definition WPSDebug.h:221
static void skipZone(long, long)
Definition WPSDebug.h:226
Definition WPSDebug.h:192
DebugStream & operator<<(T const &)
Definition WPSDebug.h:195
static void str(std::string const &)
Definition WPSDebug.h:204
static std::string str()
Definition WPSDebug.h:200
std::shared_ptr< librevenge::RVNGInputStream > RVNGInputStreamPtr
shared pointer to librevenge::RVNGInputStream
Definition libwps_internal.h:87
Definition WPSDebug.h:179
std::string flattenFileName(std::string const &name)
Definition WPSDebug.h:185
bool dumpFile(librevenge::RVNGBinaryData const &, char const *)
Definition WPSDebug.h:180
Definition libwps_internal.cpp:39

Generated on Sat Jul 19 2025 05:24:40 for libwps by doxygen 1.14.0