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 class WPXBinaryData;
42 
43 # if defined(DEBUG_WITH_FILES)
44 #include <fstream>
45 #include <sstream>
46 #include <vector>
48 namespace libmwaw
49 {
51 namespace Debug
52 {
56 bool dumpFile(WPXBinaryData &data, char const *fileName);
58 std::string flattenFileName(std::string const &name);
59 }
60 
62 typedef std::stringstream DebugStream;
63 
66 class DebugFile
67 {
68 public:
71  : m_file(), m_on(false), m_input(ip), m_actOffset(-1), m_notes(), m_skipZones() { }
72 
75  m_input = ip;
76  }
79  reset();
80  }
82  bool open(std::string const &filename);
84  void reset() {
85  write();
86  m_file.close();
87  m_on = false;
88  m_notes.resize(0);
89  m_skipZones.resize(0);
90  m_actOffset = -1;
91  }
93  void write();
95  void addPos(long pos);
97  void addNote(char const *note);
99  void addDelimiter(long pos, char c);
100 
102  void skipZone(long beginPos, long endPos) {
103  if (m_on) m_skipZones.push_back(Vec2<long>(beginPos, endPos));
104  }
105 
106 protected:
108  void sort();
109 
111  mutable std::ofstream m_file;
113  mutable bool m_on;
114 
117 
119  struct NotePos {
121  NotePos() : m_pos(-1), m_text(""), m_breaking(false) { }
122 
124  NotePos(long p, std::string const &n, bool br=true) : m_pos(p), m_text(n), m_breaking(br) {}
126  long m_pos;
128  std::string m_text;
131 
133  bool operator<(NotePos const &p) const {
134  long diff = m_pos-p.m_pos;
135  if (diff) return (diff < 0) ? true : false;
136  if (m_breaking != p.m_breaking) return m_breaking;
137  return m_text < p.m_text;
138  }
142  struct NotePosLt {
144  bool operator()(NotePos const &s1, NotePos const &s2) const {
145  return s1 < s2;
146  }
147  };
148  };
149 
153  std::vector<NotePos> m_notes;
155  std::vector<Vec2<long> > m_skipZones;
156 };
157 }
158 # else
159 namespace libmwaw
160 {
161 namespace Debug
162 {
163 inline bool dumpFile(WPXBinaryData &, char const *)
164 {
165  return true;
166 }
168 inline std::string flattenFileName(std::string const &name)
169 {
170  return name;
171 }
172 }
173 
174 class DebugStream
175 {
176 public:
177  template <class T>
178  DebugStream &operator<<(T const &) {
179  return *this;
180  }
181 
182  static std::string str() {
183  return std::string("");
184  }
185  static void str(std::string const &) { }
186 };
187 
188 class DebugFile
189 {
190 public:
191  DebugFile(MWAWInputStreamPtr) {}
192  DebugFile() {}
193  static void setStream(MWAWInputStreamPtr) { }
194  ~DebugFile() { }
195 
196  static bool open(std::string const &) {
197  return true;
198  }
199 
200  static void addPos(long ) {}
201  static void addNote(char const *) {}
202  static void addDelimiter(long, char) {}
203 
204  static void write() {}
205  static void reset() { }
206 
207  static void skipZone(long , long ) {}
208 };
209 }
210 # endif
211 
212 #endif
213 
214 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
void skipZone(long beginPos, long endPos)
skips the file zone defined by beginPos-endPos
Definition: MWAWDebug.hxx:102
void write()
flushes the file
Definition: MWAWDebug.cxx:113
NotePos(long p, std::string const &n, bool br=true)
constructor: given position and note
Definition: MWAWDebug.hxx:124
void setStream(MWAWInputStreamPtr ip)
resets the input
Definition: MWAWDebug.hxx:74
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 sort()
sorts the position/note date
Definition: MWAWDebug.cxx:82
std::ostream & operator<<(std::ostream &o, PrinterInfo const &r)
operator&lt;&lt; for a PrinterInfo
Definition: MWAWPrinter.cxx:203
a note and its position (used to sort all notes)
Definition: MWAWDebug.hxx:119
bool operator<(NotePos const &p) const
comparison operator based on the position
Definition: MWAWDebug.hxx:133
bool m_breaking
flag to indicate a non breaking note
Definition: MWAWDebug.hxx:130
long m_actOffset
the actual offset (used to store note)
Definition: MWAWDebug.hxx:151
std::string m_text
note text
Definition: MWAWDebug.hxx:128
bool open(std::string const &filename)
opens/creates a file to store a result
Definition: MWAWDebug.cxx:46
void addDelimiter(long pos, char c)
adds a not breaking delimiter in position pos
Definition: MWAWDebug.cxx:74
void addPos(long pos)
adds a new position in the file
Definition: MWAWDebug.cxx:54
std::vector< NotePos > m_notes
list of notes
Definition: MWAWDebug.hxx:153
internal struct used to sort the notes, sorted by position
Definition: MWAWDebug.hxx:142
NotePos()
empty constructor used by std::vector
Definition: MWAWDebug.hxx:121
~DebugFile()
destructor
Definition: MWAWDebug.hxx:78
shared_ptr< MWAWInputStream > MWAWInputStreamPtr
a smart pointer of MWAWInputStream
Definition: libmwaw_internal.hxx:348
MWAWInputStreamPtr m_input
the input
Definition: MWAWDebug.hxx:116
std::ofstream m_file
a stream which is open to write the file
Definition: MWAWDebug.hxx:111
std::string flattenFileName(std::string const &name)
returns a file name from an ole/... name
Definition: MWAWDebug.cxx:207
void reset()
writes the current file and reset to zero
Definition: MWAWDebug.hxx:84
std::vector< Vec2< long > > m_skipZones
list of skipZone
Definition: MWAWDebug.hxx:155
std::stringstream DebugStream
a basic stream (if debug_with_files is not defined, does nothing)
Definition: MWAWDebug.hxx:62
long m_pos
note offset
Definition: MWAWDebug.hxx:126
m_skipZones()
Definition: MWAWDebug.hxx:71
bool m_on
a flag to know if the result stream is open or note
Definition: MWAWDebug.hxx:113
bool dumpFile(WPXBinaryData &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:192
bool operator()(NotePos const &s1, NotePos const &s2) const
comparison operator
Definition: MWAWDebug.hxx:144
void addNote(char const *note)
adds a note in the file, in actual position
Definition: MWAWDebug.cxx:60

Generated on Tue Mar 10 2015 17:32:08 for libmwaw by doxygen 1.8.5