| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
#ifndef WPS_DEBUG |
| 27 |
# define WPS_DEBUG |
| 28 |
|
| 29 |
#include <string> |
| 30 |
|
| 31 |
#include "libwps_internal.h" |
| 32 |
|
| 33 |
# if defined(DEBUG_WITH_FILES) |
| 34 |
#include <fstream> |
| 35 |
#include <map> |
| 36 |
#include <sstream> |
| 37 |
#include <vector> |
| 38 |
|
| 39 |
|
| 40 |
namespace libwps |
| 41 |
{ |
| 42 |
|
| 43 |
namespace Debug |
| 44 |
{ |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
bool dumpFile(librevenge::RVNGBinaryData const &data, char const *fileName); |
| 49 |
|
| 50 |
|
| 51 |
std::string flattenFileName(std::string const &name); |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
typedef std::stringstream DebugStream; |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
class DebugFile |
| 60 |
{ |
| 61 |
public: |
| 62 |
|
| 63 |
explicit DebugFile(RVNGInputStreamPtr const &ip=RVNGInputStreamPtr()) |
| 64 |
: m_file() |
| 65 |
, m_on(false) |
| 66 |
, m_input(ip) |
| 67 |
, m_actOffset(-1) |
| 68 |
, m_notes() |
| 69 |
, m_skipZones() { } |
| 70 |
|
| 71 |
|
| 72 |
void setStream(RVNGInputStreamPtr const &ip) |
| 73 |
{ |
| 74 |
m_input = ip; |
| 75 |
} |
| 76 |
|
| 77 |
~DebugFile() |
| 78 |
{ |
| 79 |
reset(); |
| 80 |
} |
| 81 |
|
| 82 |
bool open(std::string const &filename); |
| 83 |
|
| 84 |
void reset() |
| 85 |
{ |
| 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 |
} |
| 93 |
|
| 94 |
void addPos(long pos); |
| 95 |
|
| 96 |
void addNote(char const *note); |
| 97 |
|
| 98 |
void addDelimiter(long pos, char c); |
| 99 |
|
| 100 |
|
| 101 |
void skipZone(long beginPos, long endPos) |
| 102 |
{ |
| 103 |
if (m_on) m_skipZones.push_back(Vec2<long>(beginPos, endPos)); |
| 104 |
} |
| 105 |
|
| 106 |
protected: |
| 107 |
|
| 108 |
void write(); |
| 109 |
|
| 110 |
|
| 111 |
void sort(); |
| 112 |
|
| 113 |
|
| 114 |
mutable std::ofstream m_file; |
| 115 |
|
| 116 |
mutable bool m_on; |
| 117 |
|
| 118 |
|
| 119 |
RVNGInputStreamPtr m_input; |
| 120 |
|
| 121 |
|
| 122 |
struct NotePos |
| 123 |
{ |
| 124 |
|
| 125 |
NotePos() |
| 126 |
: m_pos(-1) |
| 127 |
, m_text("") |
| 128 |
, m_breaking(false) { } |
| 129 |
|
| 130 |
|
| 131 |
NotePos(long p, std::string const &n, bool br=true) |
| 132 |
: m_pos(p) |
| 133 |
, m_text(n) |
| 134 |
, m_breaking(br) {} |
| 135 |
|
| 136 |
long m_pos; |
| 137 |
|
| 138 |
std::string m_text; |
| 139 |
|
| 140 |
bool m_breaking; |
| 141 |
|
| 142 |
|
| 143 |
bool operator<(NotePos const &p) const |
| 144 |
{ |
| 145 |
long diff = m_pos-p.m_pos; |
| 146 |
if (diff) return (diff < 0) ? true : false; |
| 147 |
if (m_breaking != p.m_breaking) return m_breaking; |
| 148 |
return m_text < p.m_text; |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
struct NotePosLt |
| 154 |
{ |
| 155 |
|
| 156 |
bool operator()(NotePos const &s1, NotePos const &s2) const |
| 157 |
{ |
| 158 |
return s1 < s2; |
| 159 |
} |
| 160 |
}; |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
typedef std::map<NotePos, int,struct NotePosLt> Map; |
| 165 |
}; |
| 166 |
|
| 167 |
|
| 168 |
long m_actOffset; |
| 169 |
|
| 170 |
std::vector<NotePos> m_notes; |
| 171 |
|
| 172 |
std::vector<Vec2<long> > m_skipZones; |
| 173 |
}; |
| 174 |
} |
| 175 |
# else |
| 176 |
namespace libwps |
| 177 |
{ |
| 178 |
namespace Debug |
| 179 |
{ |
| 180 |
inline bool dumpFile(librevenge::RVNGBinaryData const &, char const *) |
| 181 |
{ |
| 182 |
return true; |
| 183 |
} |
| 184 |
|
| 185 |
inline std::string flattenFileName(std::string const &name) |
| 186 |
{ |
| 187 |
return name; |
| 188 |
} |
| 189 |
} |
| 190 |
|
| 191 |
class DebugStream |
| 192 |
{ |
| 193 |
public: |
| 194 |
template <class T> |
| 195 |
DebugStream &operator<<(T const &) |
| 196 |
{ |
| 197 |
return *this; |
| 198 |
} |
| 199 |
|
| 200 |
static std::string str() |
| 201 |
{ |
| 202 |
return std::string(""); |
| 203 |
} |
| 204 |
static void str(std::string const &) { } |
| 205 |
}; |
| 206 |
|
| 207 |
class DebugFile |
| 208 |
{ |
| 209 |
public: |
| 210 |
explicit DebugFile(RVNGInputStreamPtr) {} |
| 211 |
DebugFile() {} |
| 212 |
static void setStream(RVNGInputStreamPtr) { } |
| 213 |
~DebugFile() { } |
| 214 |
|
| 215 |
static bool open(std::string const &) |
| 216 |
{ |
| 217 |
return true; |
| 218 |
} |
| 219 |
|
| 220 |
static void addPos(long) {} |
| 221 |
static void addNote(char const *) {} |
| 222 |
static void addDelimiter(long, char) {} |
| 223 |
|
| 224 |
static void reset() { } |
| 225 |
|
| 226 |
static void skipZone(long, long) {} |
| 227 |
}; |
| 228 |
} |
| 229 |
# endif |
| 230 |
|
| 231 |
#endif |
| 232 |
|
| 233 |
|