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>
47namespace libmwaw
48{
50namespace Debug
51{
55bool dumpFile(librevenge::RVNGBinaryData &data, char const *fileName);
57std::string flattenFileName(std::string const &name);
58}
59
61typedef std::stringstream DebugStream;
62
66{
67public:
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
82 {
83 m_input = ip;
84 }
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
118protected:
120 void sort();
121
123 mutable std::string m_fileName;
125 mutable std::ofstream m_file;
127 mutable bool m_on;
128
131
133 struct 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;
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
179 std::vector<NotePos> m_notes;
181 std::vector<MWAWVec2<long> > m_skipZones;
182};
183}
184# else
185namespace libmwaw
186{
187namespace Debug
188{
189inline bool dumpFile(librevenge::RVNGBinaryData &, char const *)
190{
191 return true;
192}
194inline std::string flattenFileName(std::string const &name)
195{
196 return name;
197}
198}
199
200class DebugStream
201{
202public:
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
216class DebugFile
217{
218public:
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:
small class which defines a vector with 2 elements
Definition: libmwaw_internal.hxx:656
an interface used to insert comment in a binary file, written in ascii form (if debug_with_files is n...
Definition: MWAWDebug.hxx:66
void addPos(long pos)
adds a new position in the file
Definition: MWAWDebug.cxx:53
void skipZone(long beginPos, long endPos)
skips the file zone defined by beginPos-endPos
Definition: MWAWDebug.hxx:113
std::vector< MWAWVec2< long > > m_skipZones
list of skipZone
Definition: MWAWDebug.hxx:181
void setStream(MWAWInputStreamPtr const &ip)
resets the input
Definition: MWAWDebug.hxx:81
void reset()
writes the current file and reset to zero
Definition: MWAWDebug.hxx:93
void addNote(char const *note)
adds a note in the file, in actual position
Definition: MWAWDebug.cxx:59
void sort()
sorts the position/note date
Definition: MWAWDebug.cxx:81
void addDelimiter(long pos, char c)
adds a not breaking delimiter in position pos
Definition: MWAWDebug.cxx:73
void write()
flushes the file
Definition: MWAWDebug.cxx:110
~DebugFile()
destructor
Definition: MWAWDebug.hxx:86
bool open(std::string const &filename)
opens/creates a file to store a result
Definition: MWAWDebug.cxx:46
std::vector< NotePos > m_notes
list of notes
Definition: MWAWDebug.hxx:179
MWAWInputStreamPtr m_input
the input
Definition: MWAWDebug.hxx:130
long m_actOffset
the actual offset (used to store note)
Definition: MWAWDebug.hxx:177
DebugFile(MWAWInputStreamPtr const &ip)
constructor given the input file
Definition: MWAWDebug.hxx:69
bool m_on
a flag to know if the result stream is open or note
Definition: MWAWDebug.hxx:127
std::ofstream m_file
a stream which is open to write the file
Definition: MWAWDebug.hxx:125
std::string m_fileName
the file name
Definition: MWAWDebug.hxx:123
std::shared_ptr< MWAWInputStream > MWAWInputStreamPtr
a smart pointer of MWAWInputStream
Definition: libmwaw_internal.hxx:551
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
std::string flattenFileName(std::string const &name)
returns a file name from an ole/... name
Definition: MWAWDebug.cxx:208
namespace used to regroup all libwpd functions, enumerations which we have redefined for internal usa...
Definition: libmwaw_internal.cxx:51
std::ostream & operator<<(std::ostream &o, PrinterInfo const &r)
operator<< for a PrinterInfo
Definition: MWAWPrinter.cxx:228
std::stringstream DebugStream
a basic stream (if debug_with_files is not defined, does nothing)
Definition: MWAWDebug.hxx:61
internal struct used to sort the notes, sorted by position
Definition: MWAWDebug.hxx:167
bool operator()(NotePos const &s1, NotePos const &s2) const
comparison operator
Definition: MWAWDebug.hxx:169
a note and its position (used to sort all notes)
Definition: MWAWDebug.hxx:133
std::string m_text
note text
Definition: MWAWDebug.hxx:152
bool operator<(NotePos const &p) const
comparison operator based on the position
Definition: MWAWDebug.hxx:157
NotePos()
empty constructor used by std::vector
Definition: MWAWDebug.hxx:135
NotePos(long p, std::string const &n, bool br=true)
constructor: given position and note
Definition: MWAWDebug.hxx:143
bool m_breaking
flag to indicate a non breaking note
Definition: MWAWDebug.hxx:154
long m_pos
note offset
Definition: MWAWDebug.hxx:150

Generated on Wed May 3 2023 07:18:29 for libmwaw by doxygen 1.9.6