STOFFDebug.hxx Source File documentation

STOFFDebug.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
2
3 /* libstaroffice
4 * Version: MPL 2.0 / LGPLv2+
5 *
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 2.0 (the "License"); you may not use this file except in compliance with
8 * the License or as specified alternatively below. You may obtain a copy of
9 * the License at http://www.mozilla.org/MPL/
10 *
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
15 *
16 * Major Contributor(s):
17 * Copyright (C) 2002 William Lachance (wrlach@gmail.com)
18 * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
19 * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
20 * Copyright (C) 2006, 2007 Andrew Ziem
21 * Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
22 *
23 *
24 * All Rights Reserved.
25 *
26 * For minor contributions see the git repository.
27 *
28 * Alternatively, the contents of this file may be used under the terms of
29 * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
30 * in which case the provisions of the LGPLv2+ are applicable
31 * instead of those above.
32 */
33
34 #ifndef STOFF_DEBUG
35 # define STOFF_DEBUG
36
37 #include <string>
38
39 #include "STOFFInputStream.hxx"
40
41 # if defined(DEBUG_WITH_FILES)
42 #include <fstream>
43 #include <sstream>
44 #include <string>
45 #include <vector>
47 namespace libstoff
48 {
50 namespace Debug
51 {
55 bool dumpFile(librevenge::RVNGBinaryData &data, char const *fileName);
57 std::string flattenFileName(std::string const &name);
58 }
59
61 typedef std::stringstream DebugStream;
62
65 class DebugFile
66 {
67 public:
69 explicit DebugFile(STOFFInputStreamPtr ip=STOFFInputStreamPtr())
70 : m_fileName("")
71 , m_file()
72 , m_on(false)
73 , m_input(ip)
74 , m_actOffset(-1)
75 , m_notes()
76 , m_skipZones() { }
77
79 void setStream(STOFFInputStreamPtr ip)
80 {
81 m_input = ip;
82 }
84 ~DebugFile()
85 {
86 reset();
87 }
89 bool open(std::string const &filename);
91 void reset()
92 {
93 write();
94 m_fileName="";
95 m_file.close();
96 m_on = false;
97 m_notes.resize(0);
98 m_skipZones.resize(0);
99 m_actOffset = -1;
100 }
102 void write();
104 void addPos(long pos);
106 void addNote(char const *note);
108 void addDelimiter(long pos, char c);
109
111 void skipZone(long beginPos, long endPos)
112 {
113 if (m_on) m_skipZones.push_back(STOFFVec2<long>(beginPos, endPos));
114 }
115
116 protected:
118 void sort();
119
121 mutable std::string m_fileName;
123 mutable std::ofstream m_file;
125 mutable bool m_on;
126
128 STOFFInputStreamPtr m_input;
129
131 struct NotePos {
133 NotePos()
134 : m_pos(-1)
135 , m_text("")
136 , m_breaking(false) { }
137
139 NotePos(long p, std::string const &n, bool br=true)
140 : m_pos(p)
141 , m_text(n)
142 , m_breaking(br) {}
144 long m_pos;
146 std::string m_text;
148 bool m_breaking;
149
151 bool operator<(NotePos const &p) const
152 {
153 long diff = m_pos-p.m_pos;
154 if (diff) return (diff < 0) ? true : false;
155 if (m_breaking != p.m_breaking) return m_breaking;
156 return m_text < p.m_text;
157 }
161 struct NotePosLt {
163 bool operator()(NotePos const &s1, NotePos const &s2) const
164 {
165 return s1 < s2;
166 }
167 };
168 };
169
171 long m_actOffset;
173 std::vector<NotePos> m_notes;
175 std::vector<STOFFVec2<long> > m_skipZones;
176 };
177 }
178 # else
179 namespace libstoff
180 {
181 namespace Debug
182 {
183 inline bool dumpFile(librevenge::RVNGBinaryData &, char const *)
184 {
185 return true;
186 }
188 inline std::string flattenFileName(std::string const &name)
189 {
190 return name;
191 }
192 }
193
194 class DebugStream
195 {
196 public:
197 template <class T>
198 DebugStream &operator<<(T const &)
199 {
200 return *this;
201 }
202
203 static std::string str()
204 {
205 return std::string("");
206 }
207 static void str(std::string const &) { }
208 };
209
210 class DebugFile
211 {
212 public:
213 explicit DebugFile(STOFFInputStreamPtr) {}
214 DebugFile() {}
215 static void setStream(STOFFInputStreamPtr) { }
216 ~DebugFile() { }
217
218 static bool open(std::string const &)
219 {
220 return true;
221 }
222
223 static void addPos(long) {}
224 static void addNote(char const *) {}
225 static void addDelimiter(long, char) {}
226
227 static void write() {}
228 static void reset() { }
229
230 static void skipZone(long, long) {}
231 };
232 }
233 # endif
234
235 #endif
236
237 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
libstoff::DebugFile::addDelimiter
static void addDelimiter(long, char)
Definition: STOFFDebug.hxx:225
libstoff::DebugFile::write
static void write()
Definition: STOFFDebug.hxx:227
libstoff::DebugFile
Definition: STOFFDebug.hxx:210
STOFFVec2
small class which defines a vector with 2 elements
Definition: libstaroffice_internal.hxx:583
libstoff::DebugFile::addPos
static void addPos(long)
Definition: STOFFDebug.hxx:223
STOFFInputStreamPtr
std::shared_ptr< STOFFInputStream > STOFFInputStreamPtr
a smart pointer of STOFFInputStream
Definition: libstaroffice_internal.hxx:484
libstoff::DebugFile::DebugFile
DebugFile()
Definition: STOFFDebug.hxx:214
libstoff::Debug::dumpFile
bool dumpFile(librevenge::RVNGBinaryData &, char const *)
Definition: STOFFDebug.hxx:183
libstoff::DebugFile::reset
static void reset()
Definition: STOFFDebug.hxx:228
libstoff::DebugStream::operator<<
DebugStream & operator<<(T const &)
Definition: STOFFDebug.hxx:198
libstoff::DebugFile::~DebugFile
~DebugFile()
Definition: STOFFDebug.hxx:216
libstoff::Debug::flattenFileName
std::string flattenFileName(std::string const &name)
returns a file name from an ole/... name
Definition: STOFFDebug.hxx:188
libstoff
namespace used to regroup all libwpd functions, enumerations which we have redefined for internal usa...
Definition: libstaroffice_internal.cxx:50
libstoff::DebugFile::DebugFile
DebugFile(STOFFInputStreamPtr)
Definition: STOFFDebug.hxx:213
STOFFInputStream.hxx
libstoff::DebugStream::str
static void str(std::string const &)
Definition: STOFFDebug.hxx:207
libstoff::DebugStream::str
static std::string str()
Definition: STOFFDebug.hxx:203
libstoff::DebugFile::skipZone
static void skipZone(long, long)
Definition: STOFFDebug.hxx:230
libstoff::DebugFile::setStream
static void setStream(STOFFInputStreamPtr)
Definition: STOFFDebug.hxx:215
libstoff::DebugStream
Definition: STOFFDebug.hxx:194
libstoff::DebugFile::addNote
static void addNote(char const *)
Definition: STOFFDebug.hxx:224
libstoff::DebugFile::open
static bool open(std::string const &)
Definition: STOFFDebug.hxx:218