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 <map>
46 #include <sstream>
47 #include <vector>
49 namespace libmwaw
50 {
52 namespace Debug
53 {
57 bool dumpFile(WPXBinaryData &data, char const *fileName);
59 std::string flattenFileName(std::string const &name);
60 }
61 
63 typedef std::stringstream DebugStream;
64 
67 class DebugFile
68 {
69 public:
72  : m_file(), m_on(false), m_input(ip), m_actOffset(-1), m_notes(), m_skipZones() { }
73 
76  m_input = ip;
77  }
80  reset();
81  }
83  bool open(std::string const &filename);
85  void reset() {
86  write();
87  m_file.close();
88  m_on = false;
89  m_notes.resize(0);
90  m_skipZones.resize(0);
91  m_actOffset = -1;
92  }
94  void write();
96  void addPos(long pos);
98  void addNote(char const *note);
100  void addDelimiter(long pos, char c);
101 
103  void skipZone(long beginPos, long endPos) {
104  if (m_on) m_skipZones.push_back(Vec2<long>(beginPos, endPos));
105  }
106 
107 protected:
109  void sort();
110 
112  mutable std::ofstream m_file;
114  mutable bool m_on;
115 
118 
120  struct NotePos {
122  NotePos() : m_pos(-1), m_text(""), m_breaking(false) { }
123 
125  NotePos(long p, std::string const &n, bool br=true) : m_pos(p), m_text(n), m_breaking(br) {}
127  long m_pos;
129  std::string m_text;
132 
134  bool operator<(NotePos const &p) const {
135  long diff = m_pos-p.m_pos;
136  if (diff) return (diff < 0) ? true : false;
137  if (m_breaking != p.m_breaking) return m_breaking;
138  return m_text < p.m_text;
139  }
143  struct NotePosLt {
145  bool operator()(NotePos const &s1, NotePos const &s2) const {
146  return s1 < s2;
147  }
148  };
152  typedef std::map<NotePos, int,struct NotePosLt> Map;
153  };
154 
158  std::vector<NotePos> m_notes;
160  std::vector<Vec2<long> > m_skipZones;
161 };
162 }
163 # else
164 namespace libmwaw
165 {
166 namespace Debug
167 {
168 inline bool dumpFile(WPXBinaryData &, char const *)
169 {
170  return true;
171 }
173 inline std::string flattenFileName(std::string const &name)
174 {
175  return name;
176 }
177 }
178 
179 class DebugStream
180 {
181 public:
182  template <class T>
183  DebugStream &operator<<(T const &) {
184  return *this;
185  }
186 
187  static std::string str() {
188  return std::string("");
189  }
190  static void str(std::string const &) { }
191 };
192 
193 class DebugFile
194 {
195 public:
197  DebugFile() {}
198  static void setStream(MWAWInputStreamPtr) { }
199  ~DebugFile() { }
200 
201  static bool open(std::string const &) {
202  return true;
203  }
204 
205  static void addPos(long ) {}
206  static void addNote(char const *) {}
207  static void addDelimiter(long, char) {}
208 
209  static void write() {}
210  static void reset() { }
211 
212  static void skipZone(long , long ) {}
213 };
214 }
215 # endif
216 
217 #endif
218 
219 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:

Generated on Tue Jul 2 2013 05:26:51 for libmwaw by doxygen 1.8.4