RagTime5StructManager.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 RAG_TIME_5_STRUCT_MANAGER
35 # define RAG_TIME_5_STRUCT_MANAGER
36
37 #include <map>
38 #include <ostream>
39 #include <sstream>
40 #include <string>
41 #include <vector>
42
43 #include "libmwaw_internal.hxx"
44 #include "MWAWDebug.hxx"
45 #include "MWAWEntry.hxx"
46
48 class RagTime5Zone
49 {
50 public:
52 RagTime5Zone(MWAWInputStreamPtr input, libmwaw::DebugFile &asc):
53 m_level(-1), m_parentName(""), m_defPosition(0), m_entry(), m_name(""), m_hiLoEndian(true),
54 m_entriesList(), m_childIdToZoneMap(), m_isParsed(false), m_extra(""),
55 m_input(input), m_defaultInput(true), m_asciiName(""), m_asciiFile(&asc), m_mainAsciiFile(&asc), m_localAsciiFile()
56 {
57 for (int i=0; i<3; ++i) m_ids[i]=m_idsFlag[i]=0;
58 for (int i=0; i<2; ++i) m_kinds[i]="";
59 for (int i=0; i<2; ++i) m_variableD[i]=0;
60 }
62 virtual ~RagTime5Zone();
64 std::string getZoneName() const;
66 std::string getKindLastPart(bool main=true) const
67 {
68 std::string res(m_kinds[main ? 0 : 1]);
69 std::string::size_type pos = res.find_last_of(':');
70 if (pos == std::string::npos) return res;
71 return res.substr(pos+1);
72 }
73
75 friend std::ostream &operator<<(std::ostream &o, RagTime5Zone const &z);
77 MWAWInputStreamPtr getInput()
78 {
79 return m_input;
80 }
82 void setInput(MWAWInputStreamPtr input)
83 {
84 m_input = input;
85 m_defaultInput = false;
86 }
88 bool isMainInput() const
89 {
90 return m_defaultInput;
91 }
93 libmwaw::DebugFile &ascii()
94 {
95 if (!m_defaultInput && !m_localAsciiFile)
96 createAsciiFile();
97 return *m_asciiFile;
98 }
100 void setAsciiFileName(std::string const &name)
101 {
102 m_asciiName = name;
103 }
105 void createAsciiFile();
107 void addErrorInDebugFile(std::string const &zoneName);
108
110 int m_level;
112 std::string m_parentName;
114 long m_defPosition;
116 std::string m_kinds[2];
118 MWAWEntry m_entry;
120 std::string m_name;
122 bool m_hiLoEndian;
124 int m_ids[3];
126 int m_idsFlag[3];
128 std::vector<MWAWEntry> m_entriesList;
130 std::map<int,shared_ptr<RagTime5Zone> > m_childIdToZoneMap;
132 int m_variableD[2];
134 bool m_isParsed;
136 std::string m_extra;
137 protected:
139 MWAWInputStreamPtr m_input;
141 bool m_defaultInput;
143 std::string m_asciiName;
145 libmwaw::DebugFile *m_asciiFile;
147 libmwaw::DebugFile *m_mainAsciiFile;
149 shared_ptr<libmwaw::DebugFile> m_localAsciiFile;
150 private:
151 RagTime5Zone(RagTime5Zone const &orig);
152 RagTime5Zone &operator=(RagTime5Zone const &orig);
153 };
154
156 class RagTime5StructManager
157 {
158 public:
159 struct Field;
161 RagTime5StructManager();
163 ~RagTime5StructManager();
164
166 bool readTypeDefinitions(RagTime5Zone &zone);
168 bool readField(MWAWInputStreamPtr input, long endPos, libmwaw::DebugFile &ascFile,
169 Field &field, long fSz=0);
171 static bool readCompressedLong(MWAWInputStreamPtr &input, long endPos, long &val);
173 static bool readUnicodeString(MWAWInputStreamPtr input, long endPos, librevenge::RVNGString &string);
175 static bool readDataIdList(MWAWInputStreamPtr input, int n, std::vector<int> &listIds);
176
178 struct TabStop {
180 TabStop() : m_position(0), m_type(1), m_leaderChar(0)
181 {
182 }
184 friend std::ostream &operator<<(std::ostream &o, TabStop const &tab)
185 {
186 o << tab.m_position;
187 switch (tab.m_type) {
188 case 1:
189 break;
190 case 2:
191 o << "R";
192 break;
193 case 3:
194 o << "C";
195 break;
196 case 4:
197 o << "D";
198 break;
199 case 5: // Kintou Waritsuke: sort of center
200 o << "K";
201 break;
202 default:
203 o << ":#type=" << tab.m_type;
204 break;
205 }
206 if (tab.m_leaderChar>0)
207 o << ":leader=" << char(tab.m_leaderChar);
208 return o;
209 }
211 float m_position;
213 int m_type;
215 uint16_t m_leaderChar;
216 };
218 struct Field {
220 enum Type { T_Unknown, T_Bool, T_Double, T_Long, T_2Long, T_FieldList, T_LongList, T_DoubleList, T_TabList,
221 T_Code, T_Color, T_CondColor, T_PrintInfo, T_String, T_Unicode, T_ZoneId, T_LongDouble, T_Unstructured
222 };
223
225 Field() : m_type(T_Unknown), m_fileType(0), m_name(""), m_doubleValue(0), m_color(), m_string(""),
226 m_longList(), m_doubleList(), m_numLongByData(1), m_tabList(), m_fieldList(), m_entry(), m_extra("")
227 {
228 for (int i=0; i<2; ++i) m_longValue[i]=0;
229 }
231 ~Field()
232 {
233 }
235 friend std::ostream &operator<<(std::ostream &o, Field const &field);
237 Type m_type;
239 long m_fileType;
241 std::string m_name;
243 long m_longValue[2];
245 double m_doubleValue;
247 MWAWColor m_color;
249 librevenge::RVNGString m_string;
251 std::vector<long> m_longList;
253 std::vector<double> m_doubleList;
255 int m_numLongByData;
257 std::vector<TabStop> m_tabList;
259 std::vector<Field> m_fieldList;
261 MWAWEntry m_entry;
263 std::string m_extra;
264 };
266 struct ZoneLink {
268 ZoneLink() : m_dataId(0), m_valuesList(), m_extra("")
269 {
270 m_subZoneId[0]=m_subZoneId[1]=0;
271 }
273 int getSubZoneId(int i) const
274 {
275 if (i<0 || i>=2) {
276 MWAW_DEBUG_MSG(("RagTime5StructManager::ZoneLink::getSubZoneId: called with bad value=%d\n", i));
277 return 0;
278 }
279 return (m_subZoneId[0]&0x3fffffff);
280 }
282 friend std::ostream &operator<<(std::ostream &o, ZoneLink const &link)
283 {
284 if (link.m_dataId) o << "data" << link.m_dataId << "A,";
285 if (link.m_subZoneId[0]) {
286 if (link.m_subZoneId[0]> 0&& (static_cast<unsigned long>(link.m_subZoneId[0])&0xc0000000)==0)
287 o << "data[subId]=" << link.m_subZoneId[0] << ",";
288 else
289 o << "data[subId]=" << (link.m_subZoneId[0]&0x3fffffff) << "[" << (link.m_subZoneId[0]>>30) << "],";
290 }
291 if (link.m_subZoneId[1]) o << "orig[subId]=" << link.m_subZoneId[1] << ",";
292 for (size_t i=0; i<link.m_valuesList.size(); ++i) {
293 if (!link.m_valuesList[i]) continue;
294 o << "f" << i << "=" << link.m_valuesList[i] << ",";
295 }
296 return o;
297 }
299 int m_dataId;
301 long m_subZoneId[2];
303 std::vector<long> m_valuesList;
305 std::string m_extra;
306 };
308 struct FieldParser {
310 explicit FieldParser(std::string const &zoneName) : m_regroupFields(false), m_name(zoneName) {}
312 virtual ~FieldParser();
314 virtual std::string getZoneName() const
315 {
316 return m_name;
317 }
319 virtual std::string getZoneName(int n) const
320 {
321 std::stringstream s;
322 s << m_name << "-" << n;
323 return s.str();
324 }
326 virtual bool parseHeaderField(Field &field, RagTime5Zone &/*zone*/, int /*n*/, libmwaw::DebugStream &f)
327 {
328 f << field;
329 return true;
330 }
332 virtual bool parseField(Field &field, RagTime5Zone &/*zone*/, int /*n*/, libmwaw::DebugStream &f)
333 {
334 f << field;
335 return true;
336 }
338 bool m_regroupFields;
339 protected:
341 std::string m_name;
342 private:
343 FieldParser(FieldParser const &orig);
344 FieldParser &operator=(FieldParser const &orig);
345 };
347 struct DataParser {
349 explicit DataParser(std::string const &zoneName) : m_name(zoneName) {}
351 virtual ~DataParser();
353 virtual std::string getZoneName() const
354 {
355 return m_name;
356 }
358 virtual std::string getZoneName(int n) const
359 {
360 std::stringstream s;
361 s << m_name << "-" << n;
362 return s.str();
363 }
365 virtual bool parseData(MWAWInputStreamPtr &/*input*/, long /*endPos*/, RagTime5Zone &/*zone*/, int /*n*/, libmwaw::DebugStream &/*f*/)
366 {
367 return true;
368 }
369 protected:
371 std::string m_name;
372 private:
373 DataParser(DataParser const &orig);
374 DataParser &operator=(DataParser const &orig);
375 };
376
378 struct GObjPropFieldParser : public FieldParser {
380 explicit GObjPropFieldParser(std::string const &name) : FieldParser(name), m_clusterId(0)
381 {
382 }
384 virtual bool parseField(Field &field, RagTime5Zone &zone, int n, libmwaw::DebugStream &f);
385
387 int m_clusterId;
388 };
389
390 private:
391 RagTime5StructManager(RagTime5StructManager const &orig);
392 RagTime5StructManager operator=(RagTime5StructManager const &orig);
393 };
394
395 #endif
396 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
RagTime5StructManager::ZoneLink::operator<<
friend std::ostream & operator<<(std::ostream &o, ZoneLink const &link)
operator<<
Definition: RagTime5StructManager.hxx:282
RagTime5Zone::getZoneName
std::string getZoneName() const
returns the zone name
Definition: RagTime5StructManager.cxx:1660
RagTime5StructManager::TabStop
a tabulation in RagTime 5/6 structures
Definition: RagTime5StructManager.hxx:178
RagTime5Zone::m_asciiName
std::string m_asciiName
the ascii file name ( used if we need to create a ascii file)
Definition: RagTime5StructManager.hxx:143
RagTime5Zone::getKindLastPart
std::string getKindLastPart(bool main=true) const
returns the main type
Definition: RagTime5StructManager.hxx:66
RagTime5Zone::ascii
libmwaw::DebugFile & ascii()
returns the current ascii file
Definition: RagTime5StructManager.hxx:93
RagTime5StructManager::FieldParser::getZoneName
virtual std::string getZoneName() const
return the debug name corresponding to a zone
Definition: RagTime5StructManager.hxx:314
RagTime5StructManager::FieldParser::FieldParser
FieldParser(std::string const &zoneName)
constructor
Definition: RagTime5StructManager.hxx:310
RagTime5Zone::isMainInput
bool isMainInput() const
returns true if the input correspond to the basic file
Definition: RagTime5StructManager.hxx:88
RagTime5StructManager::Field::m_fileType
long m_fileType
the file type
Definition: RagTime5StructManager.hxx:239
RagTime5StructManager::DataParser::m_name
std::string m_name
the field name
Definition: RagTime5StructManager.hxx:371
RagTime5Zone::~RagTime5Zone
virtual ~RagTime5Zone()
destructor
Definition: RagTime5StructManager.cxx:1642
MWAWEntry.hxx
libmwaw_internal.hxx
RagTime5StructManager::TabStop::TabStop
TabStop()
constructor
Definition: RagTime5StructManager.hxx:180
libmwaw::DebugFile
an interface used to insert comment in a binary file, written in ascii form (if debug_with_files is n...
Definition: MWAWDebug.hxx:65
RagTime5StructManager::ZoneLink::getSubZoneId
int getSubZoneId(int i) const
returns the sub zone id
Definition: RagTime5StructManager.hxx:273
RagTime5StructManager::FieldParser::getZoneName
virtual std::string getZoneName(int n) const
return the debug name corresponding to a field
Definition: RagTime5StructManager.hxx:319
RagTime5Zone::m_idsFlag
int m_idsFlag[3]
the zone flag
Definition: RagTime5StructManager.hxx:126
RagTime5Zone::m_variableD
int m_variableD[2]
the content of the zone D if it exists
Definition: RagTime5StructManager.hxx:132
RagTime5StructManager::Field::m_doubleValue
double m_doubleValue
the double value
Definition: RagTime5StructManager.hxx:245
RagTime5Zone::m_asciiFile
libmwaw::DebugFile * m_asciiFile
the ascii file corresponding to an input
Definition: RagTime5StructManager.hxx:145
RagTime5Zone::addErrorInDebugFile
void addErrorInDebugFile(std::string const &zoneName)
mark a zone as bad
Definition: RagTime5StructManager.cxx:1680
RagTime5StructManager::Field::~Field
~Field()
destructor
Definition: RagTime5StructManager.hxx:231
RagTime5StructManager::TabStop::m_leaderChar
uint16_t m_leaderChar
the unicode leader char
Definition: RagTime5StructManager.hxx:215
RagTime5StructManager::FieldParser
virtual class use to parse the field data
Definition: RagTime5StructManager.hxx:308
RagTime5Zone::m_localAsciiFile
shared_ptr< libmwaw::DebugFile > m_localAsciiFile
the local ascii file ( if we need to create a new input)
Definition: RagTime5StructManager.hxx:149
RagTime5Zone
main zone in a RagTime v5-v6 document
Definition: RagTime5StructManager.hxx:48
MWAWColor
the class to store a color
Definition: libmwaw_internal.hxx:196
RagTime5StructManager::TabStop::m_type
int m_type
the type
Definition: RagTime5StructManager.hxx:213
RagTime5Zone::m_level
int m_level
the zone level
Definition: RagTime5StructManager.hxx:110
RagTime5StructManager::Field::m_doubleList
std::vector< double > m_doubleList
the list of double value
Definition: RagTime5StructManager.hxx:253
MWAW_DEBUG_MSG
#define MWAW_DEBUG_MSG(M)
Definition: libmwaw_internal.hxx:141
RagTime5StructManager::DataParser
virtual class use to parse the unstructured data
Definition: RagTime5StructManager.hxx:347
RagTime5StructManager::Field::m_type
Type m_type
the field type
Definition: RagTime5StructManager.hxx:237
RagTime5StructManager::ZoneLink::m_valuesList
std::vector< long > m_valuesList
list of potential values
Definition: RagTime5StructManager.hxx:303
RagTime5Zone::operator<<
friend std::ostream & operator<<(std::ostream &o, RagTime5Zone const &z)
operator<<
Definition: RagTime5StructManager.cxx:1697
RagTime5StructManager::ZoneLink
a zone link in RagTime 5/6 structures
Definition: RagTime5StructManager.hxx:266
RagTime5StructManager::ZoneLink::m_dataId
int m_dataId
the data id (or 0)
Definition: RagTime5StructManager.hxx:299
RagTime5Zone::m_isParsed
bool m_isParsed
a flag to know if the zone is parsed
Definition: RagTime5StructManager.hxx:134
RagTime5Zone::m_defPosition
long m_defPosition
the position of the definition in the main zones
Definition: RagTime5StructManager.hxx:114
RagTime5StructManager::DataParser::getZoneName
virtual std::string getZoneName() const
return the debug name corresponding to a zone
Definition: RagTime5StructManager.hxx:353
RagTime5Zone::setAsciiFileName
void setAsciiFileName(std::string const &name)
defines the ascii name
Definition: RagTime5StructManager.hxx:100
RagTime5StructManager::Field::T_ZoneId
Definition: RagTime5StructManager.hxx:221
RagTime5Zone::m_kinds
std::string m_kinds[2]
the zone types: normal and packing
Definition: RagTime5StructManager.hxx:116
RagTime5Zone::m_mainAsciiFile
libmwaw::DebugFile * m_mainAsciiFile
the main ascii file (used to print error)
Definition: RagTime5StructManager.hxx:147
RagTime5StructManager::Field::m_name
std::string m_name
the field type name
Definition: RagTime5StructManager.hxx:241
RagTime5Zone::RagTime5Zone
RagTime5Zone(MWAWInputStreamPtr input, libmwaw::DebugFile &asc)
constructor
Definition: RagTime5StructManager.hxx:52
RagTime5StructManager::Field
a field of RagTime 5/6 structures
Definition: RagTime5StructManager.hxx:218
RagTime5StructManager::Field::m_longList
std::vector< long > m_longList
the list of long value
Definition: RagTime5StructManager.hxx:251
RagTime5StructManager::FieldParser::m_regroupFields
bool m_regroupFields
a flag use to decide if we output one debug message by field or not
Definition: RagTime5StructManager.hxx:338
RagTime5Zone::createAsciiFile
void createAsciiFile()
creates the ascii file
Definition: RagTime5StructManager.cxx:1646
MWAWInputStreamPtr
shared_ptr< MWAWInputStream > MWAWInputStreamPtr
a smart pointer of MWAWInputStream
Definition: libmwaw_internal.hxx:517
RagTime5Zone::m_entriesList
std::vector< MWAWEntry > m_entriesList
the list of original entries
Definition: RagTime5StructManager.hxx:128
RagTime5StructManager::Field::Field
Field()
constructor
Definition: RagTime5StructManager.hxx:225
RagTime5Zone::m_entry
MWAWEntry m_entry
the zone entry
Definition: RagTime5StructManager.hxx:118
RagTime5StructManager::GObjPropFieldParser::m_clusterId
int m_clusterId
the id of the zone corresponding to this property (always a clust graph ?)
Definition: RagTime5StructManager.hxx:387
MWAWDebug.hxx
RagTime5StructManager::FieldParser::m_name
std::string m_name
the field name
Definition: RagTime5StructManager.hxx:341
RagTime5StructManager::Field::m_tabList
std::vector< TabStop > m_tabList
the list of tabStop
Definition: RagTime5StructManager.hxx:257
RagTime5Zone::m_name
std::string m_name
the zone name ( mainly used for debugging)
Definition: RagTime5StructManager.hxx:120
RagTime5Zone::m_childIdToZoneMap
std::map< int, shared_ptr< RagTime5Zone > > m_childIdToZoneMap
the child zones
Definition: RagTime5StructManager.hxx:130
RagTime5StructManager::Field::m_color
MWAWColor m_color
the color
Definition: RagTime5StructManager.hxx:247
RagTime5Zone::setInput
void setInput(MWAWInputStreamPtr input)
reset the current input
Definition: RagTime5StructManager.hxx:82
RagTime5StructManager::ZoneLink::m_subZoneId
long m_subZoneId[2]
the sub id zones
Definition: RagTime5StructManager.hxx:301
RagTime5StructManager::Field::m_extra
std::string m_extra
extra data
Definition: RagTime5StructManager.hxx:263
RagTime5StructManager::GObjPropFieldParser::GObjPropFieldParser
GObjPropFieldParser(std::string const &name)
constructor
Definition: RagTime5StructManager.hxx:380
RagTime5StructManager::TabStop::m_position
float m_position
the position
Definition: RagTime5StructManager.hxx:211
RagTime5StructManager::Field::m_numLongByData
int m_numLongByData
the number of long by data (in m_longList)
Definition: RagTime5StructManager.hxx:255
RagTime5StructManager::FieldParser::parseHeaderField
virtual bool parseHeaderField(Field &field, RagTime5Zone &, int, libmwaw::DebugStream &f)
parse a header field
Definition: RagTime5StructManager.hxx:326
libmwaw::DebugStream
std::stringstream DebugStream
a basic stream (if debug_with_files is not defined, does nothing)
Definition: MWAWDebug.hxx:61
RagTime5StructManager::Field::Type
Type
the different type
Definition: RagTime5StructManager.hxx:220
RagTime5StructManager::DataParser::DataParser
DataParser(std::string const &zoneName)
constructor
Definition: RagTime5StructManager.hxx:349
RagTime5Zone::m_parentName
std::string m_parentName
the parent name
Definition: RagTime5StructManager.hxx:112
RagTime5Zone::operator=
RagTime5Zone & operator=(RagTime5Zone const &orig)
MWAWEntry
basic class to store an entry in a file This contained :
Definition: MWAWEntry.hxx:46
RagTime5StructManager
basic class used to store RagTime 5/6 structures
Definition: RagTime5StructManager.hxx:156
RagTime5StructManager::TabStop::operator<<
friend std::ostream & operator<<(std::ostream &o, TabStop const &tab)
operator<<
Definition: RagTime5StructManager.hxx:184
RagTime5Zone::m_hiLoEndian
bool m_hiLoEndian
true if the endian is hilo
Definition: RagTime5StructManager.hxx:122
RagTime5Zone::m_defaultInput
bool m_defaultInput
a flag used to know if the input is or not the default input
Definition: RagTime5StructManager.hxx:141
RagTime5Zone::m_ids
int m_ids[3]
the zone id
Definition: RagTime5StructManager.hxx:124
RagTime5StructManager::ZoneLink::m_extra
std::string m_extra
extra data
Definition: RagTime5StructManager.hxx:305
RagTime5StructManager::ZoneLink::ZoneLink
ZoneLink()
constructor
Definition: RagTime5StructManager.hxx:268
RagTime5StructManager::Field::m_fieldList
std::vector< Field > m_fieldList
the list of field
Definition: RagTime5StructManager.hxx:259
RagTime5StructManager::FieldParser::parseField
virtual bool parseField(Field &field, RagTime5Zone &, int, libmwaw::DebugStream &f)
parse a field
Definition: RagTime5StructManager.hxx:332
RagTime5StructManager::DataParser::getZoneName
virtual std::string getZoneName(int n) const
return the debug name corresponding to a field
Definition: RagTime5StructManager.hxx:358
RagTime5Zone::m_input
MWAWInputStreamPtr m_input
the main input
Definition: RagTime5StructManager.hxx:139
RagTime5StructManager::Field::m_entry
MWAWEntry m_entry
entry to defined the position of a String or Unstructured data
Definition: RagTime5StructManager.hxx:261
RagTime5StructManager::GObjPropFieldParser
basic parser to read image/main graphic position properties
Definition: RagTime5StructManager.hxx:378
RagTime5Zone::getInput
MWAWInputStreamPtr getInput()
returns the current input
Definition: RagTime5StructManager.hxx:77
RagTime5Zone::m_extra
std::string m_extra
extra data
Definition: RagTime5StructManager.hxx:136
RagTime5StructManager::DataParser::parseData
virtual bool parseData(MWAWInputStreamPtr &, long, RagTime5Zone &, int, libmwaw::DebugStream &)
parse a data
Definition: RagTime5StructManager.hxx:365
RagTime5StructManager::Field::m_string
librevenge::RVNGString m_string
small string use to store a string or a 4 char code
Definition: RagTime5StructManager.hxx:249