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>
47namespace libstoff
48{
50namespace Debug
51{
55bool dumpFile(librevenge::RVNGBinaryData &data, char const *fileName);
57std::string flattenFileName(std::string const &name);
58}
59
61typedef std::stringstream DebugStream;
62
65class DebugFile
66{
67public:
70 : m_fileName(""), m_file(), m_on(false), m_input(ip), m_actOffset(-1), m_notes(), m_skipZones() { }
71
74 {
75 m_input = ip;
76 }
79 {
80 reset();
81 }
83 bool open(std::string const &filename);
85 void reset()
86 {
87 write();
88 m_fileName="";
89 m_file.close();
90 m_on = false;
91 m_notes.resize(0);
92 m_skipZones.resize(0);
93 m_actOffset = -1;
94 }
96 void write();
98 void addPos(long pos);
100 void addNote(char const *note);
102 void addDelimiter(long pos, char c);
103
105 void skipZone(long beginPos, long endPos)
106 {
107 if (m_on) m_skipZones.push_back(STOFFVec2<long>(beginPos, endPos));
108 }
109
110protected:
112 void sort();
113
115 mutable std::string m_fileName;
117 mutable std::ofstream m_file;
119 mutable bool m_on;
120
122 STOFFInputStreamPtr m_input;
123
125 struct NotePos {
127 NotePos() : m_pos(-1), m_text(""), m_breaking(false) { }
128
130 NotePos(long p, std::string const &n, bool br=true) : m_pos(p), m_text(n), m_breaking(br) {}
132 long m_pos;
134 std::string m_text;
136 bool m_breaking;
137
139 bool operator<(NotePos const &p) const
140 {
141 long diff = m_pos-p.m_pos;
142 if (diff) return (diff < 0) ? true : false;
143 if (m_breaking != p.m_breaking) return m_breaking;
144 return m_text < p.m_text;
145 }
149 struct NotePosLt {
151 bool operator()(NotePos const &s1, NotePos const &s2) const
152 {
153 return s1 < s2;
154 }
155 };
156 };
157
159 long m_actOffset;
161 std::vector<NotePos> m_notes;
163 std::vector<STOFFVec2<long> > m_skipZones;
164};
165}
166# else
167namespace libstoff
168{
169namespace Debug
170{
171inline bool dumpFile(librevenge::RVNGBinaryData &, char const *)
172{
173 return true;
174}
176inline std::string flattenFileName(std::string const &name)
177{
178 return name;
179}
180}
181
183{
184public:
185 template <class T>
187 {
188 return *this;
189 }
190
191 static std::string str()
192 {
193 return std::string("");
194 }
195 static void str(std::string const &) { }
196};
197
199{
200public:
205
206 static bool open(std::string const &)
207 {
208 return true;
209 }
210
211 static void addPos(long) {}
212 static void addNote(char const *) {}
213 static void addDelimiter(long, char) {}
214
215 static void write() {}
216 static void reset() { }
217
218 static void skipZone(long , long) {}
219};
220}
221# endif
222
223#endif
224
225// 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:574
Definition STOFFDebug.hxx:199
static void addPos(long)
Definition STOFFDebug.hxx:211
DebugFile()
Definition STOFFDebug.hxx:202
static void setStream(STOFFInputStreamPtr)
Definition STOFFDebug.hxx:203
DebugFile(STOFFInputStreamPtr)
Definition STOFFDebug.hxx:201
static void write()
Definition STOFFDebug.hxx:215
static bool open(std::string const &)
Definition STOFFDebug.hxx:206
~DebugFile()
Definition STOFFDebug.hxx:204
static void addNote(char const *)
Definition STOFFDebug.hxx:212
static void reset()
Definition STOFFDebug.hxx:216
static void skipZone(long, long)
Definition STOFFDebug.hxx:218
static void addDelimiter(long, char)
Definition STOFFDebug.hxx:213
Definition STOFFDebug.hxx:183
static std::string str()
Definition STOFFDebug.hxx:191
DebugStream & operator<<(T const &)
Definition STOFFDebug.hxx:186
static void str(std::string const &)
Definition STOFFDebug.hxx:195
shared_ptr< STOFFInputStream > STOFFInputStreamPtr
a smart pointer of STOFFInputStream
Definition libstaroffice_internal.hxx:474
bool dumpFile(librevenge::RVNGBinaryData &, char const *)
Definition STOFFDebug.hxx:171
std::string flattenFileName(std::string const &name)
returns a file name from an ole/... name
Definition STOFFDebug.hxx:176
namespace used to regroup all libwpd functions, enumerations which we have redefined for internal usa...
Definition libstaroffice_internal.cxx:51

Generated on Wed Nov 29 2023 18:59:40 for libstaroffice by doxygen 1.9.8