Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef MWAW_DEBUG
00035 # define MWAW_DEBUG
00036
00037 #include <string>
00038
00039 #include "MWAWInputStream.hxx"
00040
00041 class WPXBinaryData;
00042
00043 # if defined(DEBUG_WITH_FILES)
00044 #include <fstream>
00045 #include <sstream>
00046 #include <vector>
00048 namespace libmwaw
00049 {
00051 namespace Debug
00052 {
00056 bool dumpFile(WPXBinaryData &data, char const *fileName);
00058 std::string flattenFileName(std::string const &name);
00059 }
00060
00062 typedef std::stringstream DebugStream;
00063
00066 class DebugFile
00067 {
00068 public:
00070 DebugFile(MWAWInputStreamPtr ip=MWAWInputStreamPtr())
00071 : m_file(), m_on(false), m_input(ip), m_actOffset(-1), m_notes(), m_skipZones() { }
00072
00074 void setStream(MWAWInputStreamPtr ip) {
00075 m_input = ip;
00076 }
00078 ~DebugFile() {
00079 reset();
00080 }
00082 bool open(std::string const &filename);
00084 void reset() {
00085 write();
00086 m_file.close();
00087 m_on = false;
00088 m_notes.resize(0);
00089 m_skipZones.resize(0);
00090 m_actOffset = -1;
00091 }
00093 void write();
00095 void addPos(long pos);
00097 void addNote(char const *note);
00099 void addDelimiter(long pos, char c);
00100
00102 void skipZone(long beginPos, long endPos) {
00103 if (m_on) m_skipZones.push_back(Vec2<long>(beginPos, endPos));
00104 }
00105
00106 protected:
00108 void sort();
00109
00111 mutable std::ofstream m_file;
00113 mutable bool m_on;
00114
00116 MWAWInputStreamPtr m_input;
00117
00119 struct NotePos {
00121 NotePos() : m_pos(-1), m_text(""), m_breaking(false) { }
00122
00124 NotePos(long p, std::string const &n, bool br=true) : m_pos(p), m_text(n), m_breaking(br) {}
00126 long m_pos;
00128 std::string m_text;
00130 bool m_breaking;
00131
00133 bool operator<(NotePos const &p) const {
00134 long diff = m_pos-p.m_pos;
00135 if (diff) return (diff < 0) ? true : false;
00136 if (m_breaking != p.m_breaking) return m_breaking;
00137 return m_text < p.m_text;
00138 }
00142 struct NotePosLt {
00144 bool operator()(NotePos const &s1, NotePos const &s2) const {
00145 return s1 < s2;
00146 }
00147 };
00148 };
00149
00151 long m_actOffset;
00153 std::vector<NotePos> m_notes;
00155 std::vector<Vec2<long> > m_skipZones;
00156 };
00157 }
00158 # else
00159 namespace libmwaw
00160 {
00161 namespace Debug
00162 {
00163 inline bool dumpFile(WPXBinaryData &, char const *)
00164 {
00165 return true;
00166 }
00168 inline std::string flattenFileName(std::string const &name)
00169 {
00170 return name;
00171 }
00172 }
00173
00174 class DebugStream
00175 {
00176 public:
00177 template <class T>
00178 DebugStream &operator<<(T const &) {
00179 return *this;
00180 }
00181
00182 static std::string str() {
00183 return std::string("");
00184 }
00185 static void str(std::string const &) { }
00186 };
00187
00188 class DebugFile
00189 {
00190 public:
00191 DebugFile(MWAWInputStreamPtr) {}
00192 DebugFile() {}
00193 static void setStream(MWAWInputStreamPtr) { }
00194 ~DebugFile() { }
00195
00196 static bool open(std::string const &) {
00197 return true;
00198 }
00199
00200 static void addPos(long ) {}
00201 static void addNote(char const *) {}
00202 static void addDelimiter(long, char) {}
00203
00204 static void write() {}
00205 static void reset() { }
00206
00207 static void skipZone(long , long ) {}
00208 };
00209 }
00210 # endif
00211
00212 #endif
00213
00214