RagTime5ClusterManager.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_CLUSTER_MANAGER
35 # define RAG_TIME_5_CLUSTER_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 
49 class RagTime5Parser;
51 
53 {
54 struct State;
55 }
56 
59 {
60 public:
61  struct Link;
62 
63  struct Cluster;
64  struct ClusterRoot;
65  struct ClusterParser;
66 
67  friend struct ClusterParser;
68 
70  explicit RagTime5ClusterManager(RagTime5Parser &parser);
73 
75  bool sendClusterMainList();
76 
78  bool readCluster(RagTime5Zone &zone, ClusterParser &parser, bool warnForUnparsed=true);
80  bool readCluster(RagTime5Zone &zone, std::shared_ptr<Cluster> &cluster, int type=-1);
82  bool readClusterMainList(ClusterRoot &root, std::vector<int> &list, std::vector<int> const &clusterIdList);
83 
87  bool readFieldClusters(Link const &link);
89  bool readUnknownClusterC(Link const &link);
93  int getClusterType(RagTime5Zone &zone, int fileType);
95  bool getClusterBasicHeaderInfo(RagTime5Zone &zone, long &N, long &fSz, long &debHeaderPos);
96 
97  // low level
98 
100  bool readFieldHeader(RagTime5Zone &zone, long endPos, std::string const &headerName, long &endDataPos, long expectedLVal=-99999);
102  std::string getClusterName(int id);
103 
105  struct Link {
113  };
115  explicit Link(Type type=L_Unknown)
116  : m_type(type)
117  , m_name("")
118  , m_ids()
119  , m_N(0)
120  , m_fieldSize(0)
121  , m_longList()
122  {
123  for (auto &typ : m_fileType) typ=0;
124  }
126  bool empty() const
127  {
128  if (m_type==L_LongList && !m_longList.empty())
129  return false;
130  for (auto id : m_ids)
131  if (id>0) return false;
132  return true;
133  }
135  std::string getZoneName() const
136  {
137  switch (m_type) {
138  case L_ClusterLink:
139  return "clustLink";
140  case L_LinkDef:
141  return "linkDef";
142  case L_LongList:
143  if (!m_name.empty())
144  return m_name;
145  else {
146  std::stringstream s;
147  s << "longList" << m_fieldSize;
148  return s.str();
149  }
150  case L_UnicodeList:
151  return "unicodeListLink";
152  case L_UnknownClusterC:
153  return "unknownClusterC";
154  case L_FieldsList:
155  if (!m_name.empty())
156  return m_name;
157  return "fieldsList[unkn]";
158  case L_List:
159  if (!m_name.empty())
160  return m_name;
161  break;
162  case L_Unknown:
163 #if !defined(__clang__)
164  default:
165 #endif
166  break;
167  }
168  std::stringstream s;
169  if (m_type==L_List)
170  s << "ListZone";
171  else
172  s << "FixZone";
173  s << std::hex << m_fileType[0] << "_" << m_fileType[1] << std::dec;
174  if (m_fieldSize)
175  s << "_" << m_fieldSize;
176  s << "A";
177  return s.str();
178  }
180  friend std::ostream &operator<<(std::ostream &o, Link const &z)
181  {
182  if (z.empty()) return o;
183  o << z.getZoneName() << ":";
184  size_t numLinks=z.m_ids.size();
185  if (numLinks>1) o << "[";
186  for (size_t i=0; i<numLinks; ++i) {
187  if (z.m_ids[i]<=0)
188  o << "_";
189  else
190  o << "data" << z.m_ids[i] << "A";
191  if (i+1!=numLinks) o << ",";
192  }
193  if (numLinks>1) o << "]";
194  if (z.m_fieldSize&0x8000)
195  o << "[" << std::hex << z.m_fieldSize << std::dec << ":" << z.m_N << "]";
196  else
197  o << "[" << z.m_fieldSize << ":" << z.m_N << "]";
198  return o;
199  }
203  std::string m_name;
205  std::vector<int> m_ids;
207  int m_N;
211  long m_fileType[2];
213  std::vector<long> m_longList;
214  };
215 
217  // cluster classes
219 
221  struct Cluster {
223  enum Type {
226 
227  // the main zones
229  // the styles
231  // unknown clusters
233 
235  };
237  explicit Cluster(Type type)
238  : m_type(type)
239  , m_zoneId(0)
240  , m_hiLoEndian(true)
241  , m_name("")
242  , m_dataLink()
243  , m_nameLink()
246  , m_settingLinks()
247  , m_linksList()
248  , m_clusterIdsList()
249  , m_isSent(false)
250  {
251  }
253  virtual ~Cluster();
257  int m_zoneId;
261  librevenge::RVNGString m_name;
269  std::vector<Link> m_conditionFormulaLinks;
271  std::vector<Link> m_settingLinks;
273  std::vector<Link> m_linksList;
275  std::vector<int> m_clusterIdsList;
277  bool m_isSent;
278  };
279 
281  Cluster::Type getClusterType(int zId) const;
282 
284  struct ClusterRoot final : public Cluster {
287  : Cluster(C_Root)
289  , m_docInfoLink()
291  , m_listClusterId(0)
293  , m_linkUnknown()
294  , m_fileName("")
295  {
296  for (auto &id : m_styleClusterIds) id=0;
297  for (auto &id : m_clusterIds) id=0;
298  }
300  ~ClusterRoot() final;
303 
305  int m_clusterIds[1];
306 
309 
320 
323 
325  librevenge::RVNGString m_fileName;
326  };
327 
329  struct ClusterScript final : public Cluster {
332  : Cluster(C_Script)
333  , m_scriptComment()
334  , m_scriptName("")
335  {
336  }
338  ~ClusterScript() final;
340  Link m_scriptComment;
342  librevenge::RVNGString m_scriptName;
343  };
344 
346  // parser class
348 
350  struct ClusterParser {
352  ClusterParser(RagTime5ClusterManager &parser, int type, std::string const &zoneName)
353  : m_parser(parser)
354  , m_type(type)
355  , m_hiLoEndian(true)
356  , m_name(zoneName)
357  , m_dataId(0)
358  , m_link()
359  {
360  }
362  virtual ~ClusterParser();
364  virtual std::shared_ptr<Cluster> getCluster()=0;
366  virtual std::string getZoneName() const
367  {
368  return m_name;
369  }
371  virtual std::string getZoneName(int n, int m=-1) const
372  {
373  std::stringstream s;
374  s << m_name << "-" << n;
375  if (m>=0)
376  s << "-B" << m;
377  return s.str();
378  }
380  virtual void startZone()
381  {
382  }
384  virtual bool parseZone(MWAWInputStreamPtr &/*input*/, long /*fSz*/, int /*N*/, int /*flag*/, libmwaw::DebugStream &/*f*/)
385  {
386  return false;
387  }
389  virtual void endZone()
390  {
391  }
393  virtual bool parseField(RagTime5StructManager::Field const &/*field*/, int /*m*/, libmwaw::DebugStream &/*f*/)
394  {
395  return false;
396  }
399  virtual int getNewZoneToParse()
400  {
401  return -1;
402  }
403  //
404  // some tools
405  //
406 
408  bool isANameHeader(long N) const
409  {
410  return (m_hiLoEndian && N==int(0x80000000)) || (!m_hiLoEndian && N==0x8000);
411  }
412 
414  bool readLinkHeader(MWAWInputStreamPtr &input, long fSz, Link &link, long(&values)[4], std::string &message);
416  std::string getClusterName(int id);
420  int m_type;
424  std::string m_name;
426  int m_dataId;
429  private:
430  explicit ClusterParser(ClusterParser const &orig) = delete;
431  ClusterParser &operator=(ClusterParser const &orig) = delete;
432  };
433 protected:
435  std::shared_ptr<RagTime5ClusterManagerInternal::State> m_state;
439  std::shared_ptr<RagTime5StructManager> m_structManager;
440 private:
441  RagTime5ClusterManager(RagTime5ClusterManager const &orig) = delete;
443 };
444 
445 #endif
446 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
bool readClusterMainList(ClusterRoot &root, std::vector< int > &list, std::vector< int > const &clusterIdList)
try to read the cluster root list (in general Data14)
Definition: RagTime5ClusterManager.cxx:236
Definition: RagTime5ClusterManager.hxx:225
virtual int getNewZoneToParse()
returns to new zone to parse.
Definition: RagTime5ClusterManager.hxx:399
int m_clusterIds[1]
other cluster id (unknown cluster b, )
Definition: RagTime5ClusterManager.hxx:305
RagTime5Parser & m_mainParser
the main parser
Definition: RagTime5ClusterManager.hxx:437
Type m_type
the cluster type
Definition: RagTime5ClusterManager.hxx:255
Definition: RagTime5ClusterManager.hxx:228
Cluster(Type type)
constructor
Definition: RagTime5ClusterManager.hxx:237
bool readCluster(RagTime5Zone &zone, ClusterParser &parser, bool warnForUnparsed=true)
try to read a cluster zone
Definition: RagTime5ClusterManager.cxx:360
Definition: MWAWDocument.hxx:56
Definition: RagTime5ClusterManager.hxx:230
RagTime5ClusterManager & m_parser
the main parser
Definition: RagTime5ClusterManager.hxx:418
Definition: RagTime5ClusterManager.hxx:230
ClusterRoot()
constructor
Definition: RagTime5ClusterManager.hxx:286
Link m_linkUnknown
other link: scripts and field 6
Definition: RagTime5ClusterManager.hxx:322
Link m_listUnicodeLink
a link to a list of unknown index+unicode string
Definition: RagTime5ClusterManager.hxx:313
virtual void endZone()
end of a start zone call
Definition: RagTime5ClusterManager.hxx:389
bool m_hiLoEndian
zone endian
Definition: RagTime5ClusterManager.hxx:422
int m_styleClusterIds[8]
the list of style cluster ( graph, units, unitsbis, text, format, unknown, graphcolor, col/pattern id)
Definition: RagTime5ClusterManager.hxx:302
int m_type
the cluster type
Definition: RagTime5ClusterManager.hxx:420
Definition: RagTime5ClusterManager.hxx:224
the cluster script ( 2/a/4002/400a zone)
Definition: RagTime5ClusterManager.hxx:329
Link m_graphicTypeLink
the graphic type id
Definition: RagTime5ClusterManager.hxx:308
bool m_isSent
true if the cluster was send
Definition: RagTime5ClusterManager.hxx:277
Link m_listClusterLink[2]
first the main cluster link, second list of field definition link
Definition: RagTime5ClusterManager.hxx:319
virtual class use to parse the cluster data
Definition: RagTime5ClusterManager.hxx:350
virtual ~Cluster()
destructor
Definition: RagTime5ClusterManager.cxx:165
std::vector< Link > m_conditionFormulaLinks
the conditions formula links
Definition: RagTime5ClusterManager.hxx:269
main zone in a RagTime v5-v6 document
Definition: RagTime5StructManager.hxx:48
bool readClusterGObjProperties(RagTime5Zone &zone)
try to read a level 2 child of a cluster (picture resizing, ...)
Definition: RagTime5ClusterManager.cxx:2278
Definition: RagTime5ClusterManager.hxx:224
Link m_docInfoLink
the doc info link
Definition: RagTime5ClusterManager.hxx:311
Internal: the structures of a RagTime5ClusterManager.
Definition: RagTime5ClusterManager.cxx:48
librevenge::RVNGString m_fileName
the filename if known
Definition: RagTime5ClusterManager.hxx:325
the cluster for root
Definition: RagTime5ClusterManager.hxx:284
ClusterScript()
constructor
Definition: RagTime5ClusterManager.hxx:331
bool m_hiLoEndian
the cluster hiLo endian
Definition: RagTime5ClusterManager.hxx:259
Definition: RagTime5ClusterManager.hxx:225
ClusterParser(RagTime5ClusterManager &parser, int type, std::string const &zoneName)
constructor
Definition: RagTime5ClusterManager.hxx:352
std::shared_ptr< RagTime5StructManager > m_structManager
the structure manager
Definition: RagTime5ClusterManager.hxx:439
virtual void startZone()
start a new zone
Definition: RagTime5ClusterManager.hxx:380
Definition: RagTime5ClusterManager.hxx:224
Link m_listClusterName
the cluster list id name zone link
Definition: RagTime5ClusterManager.hxx:317
basic class used to manage RagTime 5/6 zones
Definition: RagTime5ClusterManager.hxx:58
virtual std::string getZoneName() const
return the debug name corresponding to a zone
Definition: RagTime5ClusterManager.hxx:366
Definition: RagTime5ClusterManager.hxx:228
Definition: RagTime5ClusterManager.hxx:230
std::vector< Link > m_linksList
the link list
Definition: RagTime5ClusterManager.hxx:273
RagTime5ClusterManager(RagTime5Parser &parser)
constructor
Definition: RagTime5ClusterManager.cxx:154
bool isANameHeader(long N) const
return true if N correspond to a file/script name
Definition: RagTime5ClusterManager.hxx:408
Link m_link
the actual link
Definition: RagTime5ClusterManager.hxx:428
virtual bool parseZone(MWAWInputStreamPtr &, long, int, int, libmwaw::DebugStream &)
parse a zone
Definition: RagTime5ClusterManager.hxx:384
int getClusterType(RagTime5Zone &zone, int fileType)
returns the local zone type
Definition: RagTime5ClusterManager.cxx:2158
the main class to read a RagTime v5 file
Definition: RagTime5Parser.hxx:73
a field of RagTime 5/6 structures
Definition: RagTime5StructManager.hxx:235
friend struct ClusterParser
Definition: RagTime5ClusterManager.hxx:65
Definition: RagTime5ClusterManager.hxx:228
bool getClusterBasicHeaderInfo(RagTime5Zone &zone, long &N, long &fSz, long &debHeaderPos)
try to return basic information about the header cluster&#39;s zone
Definition: RagTime5ClusterManager.cxx:2137
std::shared_ptr< MWAWInputStream > MWAWInputStreamPtr
a smart pointer of MWAWInputStream
Definition: libmwaw_internal.hxx:547
Link m_dataLink
the main data link
Definition: RagTime5ClusterManager.hxx:263
Definition: RagTime5ClusterManager.hxx:225
Type
the cluster type
Definition: RagTime5ClusterManager.hxx:223
std::vector< Link > m_settingLinks
the settings links
Definition: RagTime5ClusterManager.hxx:271
int m_listClusterId
the cluster list id
Definition: RagTime5ClusterManager.hxx:315
RagTime5ClusterManager operator=(RagTime5ClusterManager const &orig)=delete
~RagTime5ClusterManager()
destructor
Definition: RagTime5ClusterManager.cxx:161
bool sendClusterMainList()
try to send the root cluster zone
Definition: RagTime5ClusterManager.cxx:523
Definition: RagTime5ClusterManager.hxx:234
std::vector< int > m_clusterIdsList
the cluster ids
Definition: RagTime5ClusterManager.hxx:275
Definition: RagTime5ClusterManager.hxx:234
Definition: RagTime5ClusterManager.hxx:224
librevenge::RVNGString m_name
the cluster name (if know)
Definition: RagTime5ClusterManager.hxx:261
Definition: RagTime5ClusterManager.hxx:230
virtual bool parseField(RagTime5StructManager::Field const &, int, libmwaw::DebugStream &)
parse a the data of a zone, n_dataId:m
Definition: RagTime5ClusterManager.hxx:393
std::string m_name
the cluster name
Definition: RagTime5ClusterManager.hxx:424
std::stringstream DebugStream
a basic stream (if debug_with_files is not defined, does nothing)
Definition: MWAWDebug.hxx:61
int m_dataId
the actual zone id
Definition: RagTime5ClusterManager.hxx:426
Link m_nameLink
the name link
Definition: RagTime5ClusterManager.hxx:265
~ClusterRoot() final
destructor
Definition: RagTime5ClusterManager.cxx:173
Definition: RagTime5ClusterManager.hxx:230
basic class used to store RagTime 5/6 structures
Definition: RagTime5StructManager.hxx:170
bool readFieldClusters(Link const &link)
try to read some field cluster
Definition: RagTime5ClusterManager.cxx:321
std::string getClusterName(int id)
returns "data"+id+"A" ( followed by the cluster type and name if know)
Definition: RagTime5ClusterManager.cxx:223
bool readUnknownClusterC(Link const &link)
try to read some unknown cluster
Definition: RagTime5ClusterManager.cxx:339
int getClusterFileType(RagTime5Zone &zone)
try to find a cluster zone type ( heuristic when the cluster type is unknown )
Definition: RagTime5ClusterManager.cxx:2228
std::shared_ptr< RagTime5ClusterManagerInternal::State > m_state
the state
Definition: RagTime5ClusterManager.hxx:435
Link m_fieldClusterLink
the field cluster links (def and pos)
Definition: RagTime5ClusterManager.hxx:267
Definition: RagTime5ClusterManager.hxx:228
bool readFieldHeader(RagTime5Zone &zone, long endPos, std::string const &headerName, long &endDataPos, long expectedLVal=-99999)
try to read a field header, if ok set the endDataPos positions
Definition: RagTime5ClusterManager.cxx:194
int m_zoneId
the zone id
Definition: RagTime5ClusterManager.hxx:257
Definition: RagTime5ClusterManager.hxx:228
Definition: RagTime5ClusterManager.hxx:232
the cluster data
Definition: RagTime5ClusterManager.hxx:221
virtual std::string getZoneName(int n, int m=-1) const
return the debug name corresponding to a cluster
Definition: RagTime5ClusterManager.hxx:371

Generated on Sat Apr 28 2018 09:11:33 for libmwaw by doxygen 1.8.14