Main Page
Namespaces
Classes
Files
File List
File Members
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
# if defined(DEBUG_WITH_FILES)
42
#include <fstream>
43
#include <sstream>
44
#include <string>
45
#include <vector>
47
namespace
libmwaw
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
:
69
explicit
DebugFile
(
MWAWInputStreamPtr
ip)
70
:
m_fileName
(
""
),
m_file
(),
m_on
(false),
m_input
(ip),
m_actOffset
(-1),
m_notes
(),
m_skipZones
() { }
71
73
void
setStream
(
MWAWInputStreamPtr
ip)
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_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(
MWAWVec2<long>
(beginPos, endPos));
108
}
109
110
protected
:
112
void
sort
();
113
115
mutable
std::string
m_fileName
;
117
mutable
std::ofstream
m_file
;
119
mutable
bool
m_on
;
120
122
MWAWInputStreamPtr
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<MWAWVec2<long> >
m_skipZones
;
164
};
165
}
166
# else
167
namespace
libmwaw
168
{
169
namespace
Debug
170
{
171
inline
bool
dumpFile
(librevenge::RVNGBinaryData &,
char
const
*)
172
{
173
return
true
;
174
}
176
inline
std::string
flattenFileName
(std::string
const
&name)
177
{
178
return
name;
179
}
180
}
181
182
class
DebugStream
183
{
184
public
:
185
template
<
class
T>
186
DebugStream
&
operator<<
(T
const
&)
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
198
class
DebugFile
199
{
200
public
:
201
explicit
DebugFile
(
MWAWInputStreamPtr
) {}
202
DebugFile
() {}
203
static
void
setStream
(
MWAWInputStreamPtr
) { }
204
~DebugFile
() { }
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:
Generated on Tue Mar 1 2016 23:42:50 for libmwaw by
doxygen
1.8.4