MWAWDebug.hxx Source File documentation

MWAWDebug.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 /* libmwaw
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 MWAW_DEBUG
35 # define MWAW_DEBUG
36
37 #include <string>
38
39 #include "MWAWInputStream.hxx"
40
41 # if defined(DEBUG_WITH_FILES)
42 #include <fstream>
43 #include <sstream>
44 #include <string>
45 #include <vector>
47 namespace libmwaw
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(MWAWInputStreamPtr const &ip)
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 {
78 }
79
81 void setStream(MWAWInputStreamPtr const &ip)
82 {
83 m_input = ip;
84 }
86 ~DebugFile()
87 {
88 reset();
89 }
91 bool open(std::string const &filename);
93 void reset()
94 {
95 write();
96 m_fileName="";
97 m_file.close();
98 m_on = false;
99 m_notes.resize(0);
100 m_skipZones.resize(0);
101 m_actOffset = -1;
102 }
104 void write();
106 void addPos(long pos);
108 void addNote(char const *note);
110 void addDelimiter(long pos, char c);
111
113 void skipZone(long beginPos, long endPos)
114 {
115 if (m_on) m_skipZones.push_back(MWAWVec2<long>(beginPos, endPos));
116 }
117
118 protected:
120 void sort();
121
123 mutable std::string m_fileName;
125 mutable std::ofstream m_file;
127 mutable bool m_on;
128
130 MWAWInputStreamPtr m_input;
131
133 struct NotePos {
135 NotePos()
136 : m_pos(-1)
137 , m_text("")
138 , m_breaking(false)
139 {
140 }
141
143 NotePos(long p, std::string const &n, bool br=true)
144 : m_pos(p)
145 , m_text(n)
146 , m_breaking(br)
147 {
148 }
150 long m_pos;
152 std::string m_text;
154 bool m_breaking;
155
157 bool operator<(NotePos const &p) const
158 {
159 long diff = m_pos-p.m_pos;
160 if (diff) return (diff < 0) ? true : false;
161 if (m_breaking != p.m_breaking) return m_breaking;
162 return m_text < p.m_text;
163 }
167 struct NotePosLt {
169 bool operator()(NotePos const &s1, NotePos const &s2) const
170 {
171 return s1 < s2;
172 }
173 };
174 };
175
177 long m_actOffset;
179 std::vector<NotePos> m_notes;
181 std::vector<MWAWVec2<long> > m_skipZones;
182 };
183 }
184 # else
185 namespace libmwaw
186 {
187 namespace Debug
188 {
189 inline bool dumpFile(librevenge::RVNGBinaryData &, char const *)
190 {
191 return true;
192 }
194 inline std::string flattenFileName(std::string const &name)
195 {
196 return name;
197 }
198 }
199
200 class DebugStream
201 {
202 public:
203 template <class T>
204 DebugStream &operator<<(T const &)
205 {
206 return *this;
207 }
208
209 static std::string str()
210 {
211 return std::string("");
212 }
213 static void str(std::string const &) { }
214 };
215
216 class DebugFile
217 {
218 public:
219 explicit DebugFile(MWAWInputStreamPtr const &) {}
220 DebugFile() {}
221 static void setStream(MWAWInputStreamPtr const &) { }
222 ~DebugFile() { }
223
224 static bool open(std::string const &)
225 {
226 return true;
227 }
228
229 static void addPos(long) {}
230 static void addNote(char const *) {}
231 static void addDelimiter(long, char) {}
232
233 static void write() {}
234 static void reset() { }
235
236 static void skipZone(long, long) {}
237 };
238 }
239 # endif
240
241 #endif
242
243 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
MWAWInputStream.hxx
MWAWVec2< long >
libmwaw::DebugFile
an interface used to insert comment in a binary file, written in ascii form (if debug_with_files is n...
Definition: MWAWDebug.hxx:66
libmwaw::DebugFile::addPos
void addPos(long pos)
adds a new position in the file
Definition: MWAWDebug.cxx:53
libmwaw::DebugFile::skipZone
void skipZone(long beginPos, long endPos)
skips the file zone defined by beginPos-endPos
Definition: MWAWDebug.hxx:113
libmwaw::DebugFile::m_skipZones
std::vector< MWAWVec2< long > > m_skipZones
list of skipZone
Definition: MWAWDebug.hxx:181
libmwaw::DebugFile::setStream
void setStream(MWAWInputStreamPtr const &ip)
resets the input
Definition: MWAWDebug.hxx:81
libmwaw::DebugFile::reset
void reset()
writes the current file and reset to zero
Definition: MWAWDebug.hxx:93
libmwaw::DebugFile::addNote
void addNote(char const *note)
adds a note in the file, in actual position
Definition: MWAWDebug.cxx:59
libmwaw::DebugFile::sort
void sort()
sorts the position/note date
Definition: MWAWDebug.cxx:81
libmwaw::DebugFile::addDelimiter
void addDelimiter(long pos, char c)
adds a not breaking delimiter in position pos
Definition: MWAWDebug.cxx:73
libmwaw::DebugFile::write
void write()
flushes the file
Definition: MWAWDebug.cxx:110
libmwaw::DebugFile::~DebugFile
~DebugFile()
destructor
Definition: MWAWDebug.hxx:86
libmwaw::DebugFile::open
bool open(std::string const &filename)
opens/creates a file to store a result
Definition: MWAWDebug.cxx:46
libmwaw::DebugFile::m_notes
std::vector< NotePos > m_notes
list of notes
Definition: MWAWDebug.hxx:179
libmwaw::DebugFile::m_input
MWAWInputStreamPtr m_input
the input
Definition: MWAWDebug.hxx:130
libmwaw::DebugFile::m_actOffset
long m_actOffset
the actual offset (used to store note)
Definition: MWAWDebug.hxx:177
libmwaw::DebugFile::DebugFile
DebugFile(MWAWInputStreamPtr const &ip)
constructor given the input file
Definition: MWAWDebug.hxx:69
libmwaw::DebugFile::m_on
bool m_on
a flag to know if the result stream is open or note
Definition: MWAWDebug.hxx:127
libmwaw::DebugFile::m_file
std::ofstream m_file
a stream which is open to write the file
Definition: MWAWDebug.hxx:125
libmwaw::DebugFile::m_fileName
std::string m_fileName
the file name
Definition: MWAWDebug.hxx:123
MWAWInputStreamPtr
std::shared_ptr< MWAWInputStream > MWAWInputStreamPtr
a smart pointer of MWAWInputStream
Definition: libmwaw_internal.hxx:551
libmwaw::Debug::dumpFile
bool dumpFile(librevenge::RVNGBinaryData &data, char const *fileName)
a debug function to store in a datafile in the current directory WARNING: this function erase the fil...
Definition: MWAWDebug.cxx:193
libmwaw::Debug::flattenFileName
std::string flattenFileName(std::string const &name)
returns a file name from an ole/... name
Definition: MWAWDebug.cxx:208
libmwaw
namespace used to regroup all libwpd functions, enumerations which we have redefined for internal usa...
Definition: libmwaw_internal.cxx:51
libmwaw::operator<<
std::ostream & operator<<(std::ostream &o, PrinterInfo const &r)
operator<< for a PrinterInfo
Definition: MWAWPrinter.cxx:228
libmwaw::DebugStream
std::stringstream DebugStream
a basic stream (if debug_with_files is not defined, does nothing)
Definition: MWAWDebug.hxx:61
libmwaw::DebugFile::NotePos::NotePosLt
internal struct used to sort the notes, sorted by position
Definition: MWAWDebug.hxx:167
libmwaw::DebugFile::NotePos::NotePosLt::operator()
bool operator()(NotePos const &s1, NotePos const &s2) const
comparison operator
Definition: MWAWDebug.hxx:169
libmwaw::DebugFile::NotePos
a note and its position (used to sort all notes)
Definition: MWAWDebug.hxx:133
libmwaw::DebugFile::NotePos::m_text
std::string m_text
note text
Definition: MWAWDebug.hxx:152
libmwaw::DebugFile::NotePos::operator<
bool operator<(NotePos const &p) const
comparison operator based on the position
Definition: MWAWDebug.hxx:157
libmwaw::DebugFile::NotePos::NotePos
NotePos()
empty constructor used by std::vector
Definition: MWAWDebug.hxx:135
libmwaw::DebugFile::NotePos::NotePos
NotePos(long p, std::string const &n, bool br=true)
constructor: given position and note
Definition: MWAWDebug.hxx:143
libmwaw::DebugFile::NotePos::m_breaking
bool m_breaking
flag to indicate a non breaking note
Definition: MWAWDebug.hxx:154
libmwaw::DebugFile::NotePos::m_pos
long m_pos
note offset
Definition: MWAWDebug.hxx:150