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 
40 namespace libwps
41 {
43 namespace Debug
44 {
48 bool dumpFile(librevenge::RVNGBinaryData &data, char const *fileName);
49 
51 std::string flattenFileName(std::string const &name);
52 }
53 
55 typedef std::stringstream DebugStream;
56 
59 class DebugFile
60 {
61 public:
64  : m_file(), m_on(false), m_input(ip), m_actOffset(-1), m_notes(), m_skipZones() { }
65 
68  {
69  m_input = ip;
70  }
72  ~DebugFile()
73  {
74  reset();
75  }
77  bool open(std::string const &filename);
79  void reset()
80  {
81  write();
82  m_file.close();
83  m_on = false;
84  m_notes.resize(0);
85  m_skipZones.resize(0);
86  m_actOffset = -1;
87  }
89  void addPos(long pos);
91  void addNote(char const *note);
93  void addDelimiter(long pos, char c);
94 
96  void skipZone(long beginPos, long endPos)
97  {
98  if (m_on) m_skipZones.push_back(Vec2<long>(beginPos, endPos));
99  }
100 
101 protected:
103  void write();
104 
106  void sort();
107 
109  mutable std::ofstream m_file;
111  mutable bool m_on;
112 
114  RVNGInputStreamPtr m_input;
115 
117  struct NotePos
118  {
120  NotePos() : m_pos(-1), m_text(""), m_breaking(false) { }
121 
123  NotePos(long p, std::string const &n, bool br=true) : m_pos(p), m_text(n), m_breaking(br) {}
125  long m_pos;
127  std::string m_text;
129  bool m_breaking;
130 
132  bool operator<(NotePos const &p) const
133  {
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
143  {
145  bool operator()(NotePos const &s1, NotePos const &s2) const
146  {
147  return s1 < s2;
148  }
149  };
153  typedef std::map<NotePos, int,struct NotePosLt> Map;
154  };
155 
157  long m_actOffset;
159  std::vector<NotePos> m_notes;
161  std::vector<Vec2<long> > m_skipZones;
162 };
163 }
164 # else
165 namespace libwps
166 {
167 namespace Debug
168 {
169 inline bool dumpFile(librevenge::RVNGBinaryData &, char const *)
170 {
171  return true;
172 }
173 
174 inline std::string flattenFileName(std::string const &name)
175 {
176  return name;
177 }
178 }
179 
181 {
182 public:
183  template <class T>
185  {
186  return *this;
187  }
188 
189  static std::string str()
190  {
191  return std::string("");
192  }
193  static void str(std::string const &) { }
194 };
195 
197 {
198 public:
201  static void setStream(RVNGInputStreamPtr) { }
203 
204  static bool open(std::string const &)
205  {
206  return true;
207  }
208 
209  static void addPos(long) {}
210  static void addNote(char const *) {}
211  static void addDelimiter(long, char) {}
212 
213  static void reset() { }
214 
215  static void skipZone(long, long) {}
216 };
217 }
218 # endif
219 
220 #endif
221 
222 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
static std::string str()
Definition: WPSDebug.h:189
Definition: WPSDebug.h:196
static void reset()
Definition: WPSDebug.h:213
static bool open(std::string const &)
Definition: WPSDebug.h:204
static void addPos(long)
Definition: WPSDebug.h:209
static void addNote(char const *)
Definition: WPSDebug.h:210
static void setStream(RVNGInputStreamPtr)
Definition: WPSDebug.h:201
static void addDelimiter(long, char)
Definition: WPSDebug.h:211
Definition: WPSDebug.h:180
static void skipZone(long, long)
Definition: WPSDebug.h:215
std::string name(long id)
returns the name given Windows© id
Definition: libwps_tools_win.cpp:7297
static void str(std::string const &)
Definition: WPSDebug.h:193
shared_ptr< librevenge::RVNGInputStream > RVNGInputStreamPtr
shared pointer to librevenge::RVNGInputStream
Definition: libwps_internal.h:102
~DebugFile()
Definition: WPSDebug.h:202
bool dumpFile(librevenge::RVNGBinaryData &, char const *)
Definition: WPSDebug.h:169
DebugStream & operator<<(T const &)
Definition: WPSDebug.h:184
DebugFile()
Definition: WPSDebug.h:200
DebugFile(RVNGInputStreamPtr)
Definition: WPSDebug.h:199
std::string flattenFileName(std::string const &name)
Definition: WPSDebug.h:174
small class which defines a vector with 2 elements
Definition: libwps_internal.h:564

Generated on Wed Apr 11 2018 00:19:12 for libwps by doxygen 1.8.5