STOFFDebug.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 /* libstaroffice
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 STOFF_DEBUG
35 # define STOFF_DEBUG
36 
37 #include <string>
38 
39 #include "STOFFInputStream.hxx"
40 
41 # if defined(DEBUG_WITH_FILES)
42 #include <fstream>
43 #include <sstream>
44 #include <string>
45 #include <vector>
47 namespace libstoff
48 {
50 namespace Debug
51 {
55 bool dumpFile(librevenge::RVNGBinaryData &data, char const *fileName);
57 std::string flattenFileName(std::string const &name);
58 }
59 
61 typedef std::stringstream DebugStream;
62 
65 class DebugFile
66 {
67 public:
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 
80  {
81  m_input = ip;
82  }
84  ~DebugFile()
85  {
86  reset();
87  }
89  bool open(std::string const &filename);
91  void reset()
92  {
93  write();
94  m_fileName="";
95  m_file.close();
96  m_on = false;
97  m_notes.resize(0);
98  m_skipZones.resize(0);
99  m_actOffset = -1;
100  }
102  void write();
104  void addPos(long pos);
106  void addNote(char const *note);
108  void addDelimiter(long pos, char c);
109 
111  void skipZone(long beginPos, long endPos)
112  {
113  if (m_on) m_skipZones.push_back(STOFFVec2<long>(beginPos, endPos));
114  }
115 
116 protected:
118  void sort();
119 
121  mutable std::string m_fileName;
123  mutable std::ofstream m_file;
125  mutable bool m_on;
126 
128  STOFFInputStreamPtr m_input;
129 
131  struct NotePos {
133  NotePos()
134  : m_pos(-1)
135  , m_text("")
136  , m_breaking(false) { }
137 
139  NotePos(long p, std::string const &n, bool br=true)
140  : m_pos(p)
141  , m_text(n)
142  , m_breaking(br) {}
144  long m_pos;
146  std::string m_text;
148  bool m_breaking;
149 
151  bool operator<(NotePos const &p) const
152  {
153  long diff = m_pos-p.m_pos;
154  if (diff) return (diff < 0) ? true : false;
155  if (m_breaking != p.m_breaking) return m_breaking;
156  return m_text < p.m_text;
157  }
161  struct NotePosLt {
163  bool operator()(NotePos const &s1, NotePos const &s2) const
164  {
165  return s1 < s2;
166  }
167  };
168  };
169 
171  long m_actOffset;
173  std::vector<NotePos> m_notes;
175  std::vector<STOFFVec2<long> > m_skipZones;
176 };
177 }
178 # else
179 namespace libstoff
180 {
181 namespace Debug
182 {
183 inline bool dumpFile(librevenge::RVNGBinaryData &, char const *)
184 {
185  return true;
186 }
188 inline std::string flattenFileName(std::string const &name)
189 {
190  return name;
191 }
192 }
193 
195 {
196 public:
197  template <class T>
199  {
200  return *this;
201  }
202 
203  static std::string str()
204  {
205  return std::string("");
206  }
207  static void str(std::string const &) { }
208 };
209 
211 {
212 public:
217 
218  static bool open(std::string const &)
219  {
220  return true;
221  }
222 
223  static void addPos(long) {}
224  static void addNote(char const *) {}
225  static void addDelimiter(long, char) {}
226 
227  static void write() {}
228  static void reset() { }
229 
230  static void skipZone(long, long) {}
231 };
232 }
233 # endif
234 
235 #endif
236 
237 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
small class which defines a vector with 2 elements
Definition: libstaroffice_internal.hxx:589
Definition: STOFFDebug.hxx:211
static void addPos(long)
Definition: STOFFDebug.hxx:223
DebugFile()
Definition: STOFFDebug.hxx:214
static void setStream(STOFFInputStreamPtr)
Definition: STOFFDebug.hxx:215
DebugFile(STOFFInputStreamPtr)
Definition: STOFFDebug.hxx:213
static void write()
Definition: STOFFDebug.hxx:227
static bool open(std::string const &)
Definition: STOFFDebug.hxx:218
~DebugFile()
Definition: STOFFDebug.hxx:216
static void addNote(char const *)
Definition: STOFFDebug.hxx:224
static void reset()
Definition: STOFFDebug.hxx:228
static void skipZone(long, long)
Definition: STOFFDebug.hxx:230
static void addDelimiter(long, char)
Definition: STOFFDebug.hxx:225
Definition: STOFFDebug.hxx:195
static std::string str()
Definition: STOFFDebug.hxx:203
static void str(std::string const &)
Definition: STOFFDebug.hxx:207
DebugStream & operator<<(T const &)
Definition: STOFFDebug.hxx:198
std::shared_ptr< STOFFInputStream > STOFFInputStreamPtr
a smart pointer of STOFFInputStream
Definition: libstaroffice_internal.hxx:489
bool dumpFile(librevenge::RVNGBinaryData &, char const *)
Definition: STOFFDebug.hxx:183
std::string flattenFileName(std::string const &name)
returns a file name from an ole/... name
Definition: STOFFDebug.hxx:188
namespace used to regroup all libwpd functions, enumerations which we have redefined for internal usa...
Definition: libstaroffice_internal.cxx:51

Generated on Wed Mar 15 2023 00:00:00 for libstaroffice by doxygen 1.9.1