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  * Copyright (C) 2009, 2011 Alonso Laurent (alonso@loria.fr)
4  * Copyright (C) 2006, 2007 Andrew Ziem
5  * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
6  * Copyright (C) 2004 Marc Maurer (uwog@uwog.net)
7  * Copyright (C) 2003-2005 William Lachance (william.lachance@sympatico.ca)
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Library General Public
11  * License as published by the Free Software Foundation; either
12  * version 2 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Library General Public License for more details.
18  *
19  * You should have received a copy of the GNU Library General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  *
23  * For further information visit http://libwps.sourceforge.net
24  */
25 
26 /* "This product is not manufactured, approved, or supported by
27  * Corel Corporation or Corel Corporation Limited."
28  */
29 
30 #ifndef WPS_DEBUG
31 # define WPS_DEBUG
32 
33 #include <string>
34 
35 #include "libwps_internal.h"
36 
37 class WPXBinaryData;
38 
39 # if defined(DEBUG_WITH_FILES)
40 #include <fstream>
41 #include <map>
42 #include <sstream>
43 #include <vector>
44 
46 namespace libwps
47 {
49 namespace Debug
50 {
54 bool dumpFile(WPXBinaryData &data, char const *fileName);
55 
57 std::string flattenFileName(std::string const &name);
58 }
59 
61 typedef std::stringstream DebugStream;
62 
65 class DebugFile
66 {
67 public:
70  : m_file(), m_on(false), m_input(ip), m_actOffset(-1), m_notes(), m_skipZones() { }
71 
74  {
75  m_input = ip;
76  }
78  ~DebugFile()
79  {
80  reset();
81  }
83  bool open(std::string const &filename);
85  void reset()
86  {
87  write();
88  m_file.close();
89  m_on = false;
90  m_notes.resize(0);
91  m_skipZones.resize(0);
92  m_actOffset = -1;
93  }
95  void addPos(long pos);
97  void addNote(char const *note);
99  void addDelimiter(long pos, char c);
100 
102  void skipZone(int beginPos, int endPos)
103  {
104  if (m_on) m_skipZones.push_back(Vec2i(beginPos, endPos));
105  }
106 
107 protected:
109  void write();
110 
112  void sort();
113 
115  mutable std::ofstream m_file;
117  mutable bool m_on;
118 
120  WPXInputStreamPtr m_input;
121 
123  struct NotePos
124  {
126  NotePos() : m_pos(-1), m_text(""), m_breaking(false) { }
127 
129  NotePos(long p, std::string const &n, bool br=true) : m_pos(p), m_text(n), m_breaking(br) {}
131  long m_pos;
133  std::string m_text;
135  bool m_breaking;
136 
138  bool operator<(NotePos const &p) const
139  {
140  long diff = m_pos-p.m_pos;
141  if (diff) return (diff < 0) ? true : false;
142  if (m_breaking != p.m_breaking) return m_breaking;
143  return m_text < p.m_text;
144  }
148  struct NotePosLt
149  {
151  bool operator()(NotePos const &s1, NotePos const &s2) const
152  {
153  return s1 < s2;
154  }
155  };
159  typedef std::map<NotePos, int,struct NotePosLt> Map;
160  };
161 
163  int m_actOffset;
165  std::vector<NotePos> m_notes;
167  std::vector<Vec2i> m_skipZones;
168 };
169 }
170 # else
171 namespace libwps
172 {
173 namespace Debug
174 {
175 inline bool dumpFile(WPXBinaryData &, char const *)
176 {
177  return true;
178 }
179 
180 inline std::string flattenFileName(std::string const &name)
181 {
182  return name;
183 }
184 }
185 
187 {
188 public:
189  template <class T>
191  {
192  return *this;
193  }
194 
195  std::string str() const
196  {
197  return std::string("");
198  }
199  void str(std::string const &) { }
200 };
201 
203 {
204 public:
209 
210  bool open(std::string const &)
211  {
212  return true;
213  }
214 
215  void addPos(long ) {}
216  void addNote(char const *) {}
217  void addDelimiter(long, char) {}
218 
219  void reset() { }
220 
221  void skipZone(int , int ) {}
222 };
223 }
224 # endif
225 
226 #endif
227 
228 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */

Generated on Wed Aug 8 2012 16:07:57 for libwps by doxygen 1.8.1.2