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 RagTime5Document;
51 
53 {
54 struct State;
55 }
56 
59 {
60 public:
61  struct Link;
62  struct NameLink;
63 
64  struct Cluster;
65  struct ClusterRoot;
66  struct ClusterParser;
67 
68  friend struct ClusterParser;
69 
74 
76  bool sendClusterMainList();
77 
79  bool readCluster(RagTime5Zone &zone, ClusterParser &parser, bool warnForUnparsed=true);
81  bool readCluster(RagTime5Zone &zone, std::shared_ptr<Cluster> &cluster, int type=-1);
83  std::shared_ptr<Cluster> readRootCluster(RagTime5Zone &zone);
85  bool readClusterMainList(ClusterRoot &root, std::vector<int> &list, std::vector<int> const &clusterIdList);
86 
90  bool readUnknownClusterC(Link const &link);
94  int getClusterType(RagTime5Zone &zone, int fileType);
96  bool getClusterBasicHeaderInfo(RagTime5Zone &zone, long &N, long &fSz, long &debHeaderPos);
97 
98  // low level
99 
101  bool readFieldHeader(RagTime5Zone &zone, long endPos, std::string const &headerName, long &endDataPos, long expectedLVal=-99999);
103  std::string getClusterDebugName(int id);
105  void setClusterName(int id, librevenge::RVNGString const &name);
107  static std::string printType(unsigned long fileType)
108  {
109  return RagTime5StructManager::printType(fileType);
110  }
111 
113  struct Link {
120  };
122  explicit Link(Type type=L_Unknown)
123  : m_type(type)
124  , m_name("")
125  , m_ids()
126  , m_N(0)
127  , m_fieldSize(0)
128  , m_longList()
129  {
130  for (auto &typ : m_fileType) typ=0;
131  }
133  bool empty() const
134  {
135  if (m_type==L_LongList && !m_longList.empty())
136  return false;
137  for (auto id : m_ids)
138  if (id>0) return false;
139  return true;
140  }
142  std::string getZoneName() const
143  {
144  switch (m_type) {
145  case L_ClusterLink:
146  return "clustLink";
147  case L_LongList:
148  if (!m_name.empty())
149  return m_name;
150  else {
151  std::stringstream s;
152  s << "longList" << m_fieldSize;
153  return s.str();
154  }
155  case L_UnicodeList:
156  return "unicodeListLink";
157  case L_UnknownClusterC:
158  return "unknownClusterC";
159  case L_FieldsList:
160  if (!m_name.empty())
161  return m_name;
162  return "fieldsList[unkn]";
163  case L_List:
164  if (!m_name.empty())
165  return m_name;
166  break;
167  case L_Unknown:
168 #if !defined(__clang__)
169  default:
170 #endif
171  break;
172  }
173  std::stringstream s;
174  if (m_type==L_List)
175  s << "ListZone";
176  else
177  s << "FixZone";
178  s << std::hex << m_fileType[0] << "_" << m_fileType[1] << std::dec;
179  if (m_fieldSize)
180  s << "_" << m_fieldSize;
181  s << "A";
182  return s.str();
183  }
185  friend std::ostream &operator<<(std::ostream &o, Link const &z)
186  {
187  if (z.empty()) return o;
188  o << z.getZoneName() << ":";
189  size_t numLinks=z.m_ids.size();
190  if (numLinks>1) o << "[";
191  for (size_t i=0; i<numLinks; ++i) {
192  if (z.m_ids[i]<=0)
193  o << "_";
194  else
195  o << "data" << z.m_ids[i] << "A";
196  if (i+1!=numLinks) o << ",";
197  }
198  if (numLinks>1) o << "]";
199  if (z.m_fieldSize&0x8000)
200  o << "[" << std::hex << z.m_fieldSize << std::dec << ":" << z.m_N << "]";
201  else
202  o << "[" << z.m_fieldSize << ":" << z.m_N << "]";
203  return o;
204  }
208  std::string m_name;
210  std::vector<int> m_ids;
212  int m_N;
216  unsigned long m_fileType[2];
218  std::vector<long> m_longList;
219  };
220 
222  struct NameLink {
225  : m_ids()
226  , m_N(0)
227  , m_decalList()
228  {
229  }
231  explicit NameLink(Link const &lnk)
232  : m_ids(lnk.m_ids)
233  , m_N(lnk.m_N)
234  , m_decalList(lnk.m_longList)
235  {
236  }
238  bool empty() const
239  {
240  for (auto id : m_ids)
241  if (id>0) return false;
242  return true;
243  }
245  std::vector<int> m_ids;
247  int m_N;
249  std::vector<long> m_decalList;
251  std::vector<long> m_posToNames[2];
254  };
255 
257  // cluster classes
259 
261  struct Cluster {
263  enum Type {
266 
267  // the main zones
269  // group zones: 6.6
271  // the styles
273  // unknown clusters
275 
277  };
279  explicit Cluster(Type type)
280  : m_type(type)
281  , m_zoneId(0)
282  , m_hiLoEndian(true)
283  , m_name("")
284  , m_childLink()
285  , m_parentLink()
286  , m_dataLink()
287  , m_nameLink()
288  , m_formulaLink()
289  , m_settingLinks()
290  , m_linksList()
291  , m_clusterIdsList()
292  , m_isSent(false)
293  {
294  }
296  virtual ~Cluster();
300  int m_zoneId;
304  librevenge::RVNGString m_name;
316  std::vector<Link> m_settingLinks;
318  std::vector<Link> m_linksList;
320  std::vector<int> m_clusterIdsList;
322  bool m_isSent;
323  };
324 
326  Cluster::Type getClusterType(int zId) const;
327 
329  struct ClusterRoot final : public Cluster {
332  : Cluster(C_Root)
333  , m_docInfoLink()
337  , m_listClusterId(0)
339  , m_linkUnknown()
340  , m_fileName("")
341  {
342  for (auto &id : m_styleClusterIds) id=0;
343  for (auto &id : m_clusterIds) id=0;
344  }
346  ~ClusterRoot() final;
349 
351  int m_clusterIds[1];
352 
359 
368 
371 
373  librevenge::RVNGString m_fileName;
374  };
375 
377  // parser class
379 
381  struct ClusterParser {
383  ClusterParser(RagTime5ClusterManager &parser, int type, std::string const &zoneName)
384  : m_parser(parser)
385  , m_type(type)
386  , m_hiLoEndian(true)
387  , m_name(zoneName)
388  , m_dataId(0)
389  , m_link()
390  {
391  }
393  virtual ~ClusterParser();
395  virtual std::shared_ptr<Cluster> getCluster()=0;
397  virtual std::string getZoneName() const
398  {
399  return m_name;
400  }
402  virtual std::string getZoneName(int n, int m=-1) const
403  {
404  std::stringstream s;
405  s << m_name << "-" << n;
406  if (m>=0)
407  s << "-B" << m;
408  return s.str();
409  }
411  virtual void startZone()
412  {
413  }
415  virtual bool parseZone(MWAWInputStreamPtr &/*input*/, long /*fSz*/, int /*N*/, int /*flag*/, libmwaw::DebugStream &/*f*/)
416  {
417  return false;
418  }
420  virtual void endZone()
421  {
422  }
424  virtual bool parseField(RagTime5StructManager::Field const &/*field*/, int /*m*/, libmwaw::DebugStream &/*f*/)
425  {
426  return false;
427  }
430  virtual int getNewZoneToParse()
431  {
432  return -1;
433  }
434  //
435  // some tools
436  //
437 
439  bool isANameHeader(long N) const
440  {
441  return (m_hiLoEndian && N==int(0x80000000)) || (!m_hiLoEndian && N==0x8000);
442  }
443 
445  bool readLinkHeader(MWAWInputStreamPtr &input, long fSz, Link &link, long(&values)[4], std::string &message);
447  std::string getClusterDebugName(int id);
451  int m_type;
455  std::string m_name;
457  int m_dataId;
460  private:
461  explicit ClusterParser(ClusterParser const &orig) = delete;
462  ClusterParser &operator=(ClusterParser const &orig) = delete;
463  };
464 protected:
466  std::shared_ptr<RagTime5ClusterManagerInternal::State> m_state;
470  std::shared_ptr<RagTime5StructManager> m_structManager;
471 private:
472  RagTime5ClusterManager(RagTime5ClusterManager const &orig) = delete;
474 };
475 
476 #endif
477 // 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:258
static std::string printType(unsigned long fileType)
debug: print a file type
Definition: RagTime5StructManager.cxx:94
Definition: RagTime5ClusterManager.hxx:265
virtual int getNewZoneToParse()
returns to new zone to parse.
Definition: RagTime5ClusterManager.hxx:430
int m_clusterIds[1]
other cluster id (unknown cluster b, )
Definition: RagTime5ClusterManager.hxx:351
Type m_type
the cluster type
Definition: RagTime5ClusterManager.hxx:298
Definition: RagTime5ClusterManager.hxx:268
Cluster(Type type)
constructor
Definition: RagTime5ClusterManager.hxx:279
bool readCluster(RagTime5Zone &zone, ClusterParser &parser, bool warnForUnparsed=true)
try to read a cluster zone
Definition: RagTime5ClusterManager.cxx:365
Definition: MWAWDocument.hxx:56
Definition: RagTime5ClusterManager.hxx:272
RagTime5ClusterManager & m_parser
the main parser
Definition: RagTime5ClusterManager.hxx:449
std::string getClusterDebugName(int id)
returns "data"+id+"A" ( followed by the cluster type and name if know)
Definition: RagTime5ClusterManager.cxx:230
Definition: RagTime5ClusterManager.hxx:272
void setClusterName(int id, librevenge::RVNGString const &name)
define a cluster name (used to associate graph name)
Definition: RagTime5ClusterManager.cxx:240
ClusterRoot()
constructor
Definition: RagTime5ClusterManager.hxx:331
Link m_linkUnknown
other link: scripts and field 6
Definition: RagTime5ClusterManager.hxx:370
Link m_listUnicodeLink
a link to a list of unknown index+unicode string
Definition: RagTime5ClusterManager.hxx:361
virtual void endZone()
end of a start zone call
Definition: RagTime5ClusterManager.hxx:420
bool m_hiLoEndian
zone endian
Definition: RagTime5ClusterManager.hxx:453
int m_styleClusterIds[8]
the list of style cluster ( graph, units, unitsbis, text, format, unknown, graphcolor, col/pattern id)
Definition: RagTime5ClusterManager.hxx:348
int m_type
the cluster type
Definition: RagTime5ClusterManager.hxx:451
Definition: RagTime5ClusterManager.hxx:264
RagTime5ClusterManager(RagTime5Document &doc)
constructor
Definition: RagTime5ClusterManager.cxx:165
Link m_graphicTypeLink
the graphic type id
Definition: RagTime5ClusterManager.hxx:358
bool m_isSent
true if the cluster was send
Definition: RagTime5ClusterManager.hxx:322
virtual class use to parse the cluster data
Definition: RagTime5ClusterManager.hxx:381
virtual ~Cluster()
destructor
Definition: RagTime5ClusterManager.cxx:176
main zone in a RagTime v5-v6 document
Definition: RagTime5StructManager.hxx:50
bool readClusterGObjProperties(RagTime5Zone &zone)
try to read a level 2 child of a cluster (picture resizing, ...)
Definition: RagTime5ClusterManager.cxx:2493
Definition: RagTime5ClusterManager.hxx:264
Link m_docInfoLink
the doc info link
Definition: RagTime5ClusterManager.hxx:354
Internal: the structures of a RagTime5ClusterManager.
Definition: RagTime5ClusterManager.cxx:49
Definition: RagTime5ClusterManager.hxx:264
librevenge::RVNGString m_fileName
the filename if known
Definition: RagTime5ClusterManager.hxx:373
the cluster for root
Definition: RagTime5ClusterManager.hxx:329
bool m_hiLoEndian
the cluster hiLo endian
Definition: RagTime5ClusterManager.hxx:302
std::shared_ptr< Cluster > readRootCluster(RagTime5Zone &zone)
try to read the root cluster zone
Definition: RagTime5ClusterManager.cxx:2531
ClusterParser(RagTime5ClusterManager &parser, int type, std::string const &zoneName)
constructor
Definition: RagTime5ClusterManager.hxx:383
NameLink m_nameLink
the name link
Definition: RagTime5ClusterManager.hxx:312
std::shared_ptr< RagTime5StructManager > m_structManager
the structure manager
Definition: RagTime5ClusterManager.hxx:470
virtual void startZone()
start a new zone
Definition: RagTime5ClusterManager.hxx:411
Link m_formulaLink
the formula cluster links (def and pos)
Definition: RagTime5ClusterManager.hxx:314
NameLink m_listClusterName
the cluster list id name zone link
Definition: RagTime5ClusterManager.hxx:365
Definition: RagTime5ClusterManager.hxx:264
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:397
Definition: RagTime5ClusterManager.hxx:268
Link m_childLink
the child link
Definition: RagTime5ClusterManager.hxx:306
Definition: RagTime5ClusterManager.hxx:272
std::vector< Link > m_linksList
the link list
Definition: RagTime5ClusterManager.hxx:318
bool isANameHeader(long N) const
return true if N correspond to a file/script name
Definition: RagTime5ClusterManager.hxx:439
Link m_link
the actual link
Definition: RagTime5ClusterManager.hxx:459
virtual bool parseZone(MWAWInputStreamPtr &, long, int, int, libmwaw::DebugStream &)
parse a zone
Definition: RagTime5ClusterManager.hxx:415
int getClusterType(RagTime5Zone &zone, int fileType)
returns the local zone type
Definition: RagTime5ClusterManager.cxx:2361
a field of RagTime 5/6 structures
Definition: RagTime5StructManager.hxx:242
friend struct ClusterParser
Definition: RagTime5ClusterManager.hxx:66
Definition: RagTime5ClusterManager.hxx:264
RagTime5Document & m_document
the main parser
Definition: RagTime5ClusterManager.hxx:468
Definition: RagTime5ClusterManager.hxx:268
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:2340
std::shared_ptr< MWAWInputStream > MWAWInputStreamPtr
a smart pointer of MWAWInputStream
Definition: libmwaw_internal.hxx:551
Link m_dataLink
the main data link
Definition: RagTime5ClusterManager.hxx:310
Definition: RagTime5ClusterManager.hxx:265
Type
the cluster type
Definition: RagTime5ClusterManager.hxx:263
std::vector< Link > m_settingLinks
the settings links
Definition: RagTime5ClusterManager.hxx:316
int m_listClusterId
the cluster list id
Definition: RagTime5ClusterManager.hxx:363
RagTime5ClusterManager operator=(RagTime5ClusterManager const &orig)=delete
Definition: RagTime5ClusterManager.hxx:268
~RagTime5ClusterManager()
destructor
Definition: RagTime5ClusterManager.cxx:172
bool sendClusterMainList()
try to send the root cluster zone
Definition: RagTime5ClusterManager.cxx:531
the main class to read a RagTime v5 file
Definition: RagTime5Document.hxx:76
Definition: RagTime5ClusterManager.hxx:276
std::vector< int > m_clusterIdsList
the cluster ids
Definition: RagTime5ClusterManager.hxx:320
Definition: RagTime5ClusterManager.hxx:276
librevenge::RVNGString m_name
the cluster name (if know)
Definition: RagTime5ClusterManager.hxx:304
Definition: RagTime5ClusterManager.hxx:272
virtual bool parseField(RagTime5StructManager::Field const &, int, libmwaw::DebugStream &)
parse a the data of a zone, n_dataId:m
Definition: RagTime5ClusterManager.hxx:424
std::string m_name
the cluster name
Definition: RagTime5ClusterManager.hxx:455
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:457
Definition: RagTime5ClusterManager.hxx:270
Link m_functionNameLink
the function name links
Definition: RagTime5ClusterManager.hxx:356
~ClusterRoot() final
destructor
Definition: RagTime5ClusterManager.cxx:184
Definition: RagTime5ClusterManager.hxx:272
basic class used to store RagTime 5/6 structures
Definition: RagTime5StructManager.hxx:174
static std::string printType(unsigned long fileType)
debug: print a file type
Definition: RagTime5ClusterManager.hxx:107
Link m_parentLink
the parent link
Definition: RagTime5ClusterManager.hxx:308
bool readUnknownClusterC(Link const &link)
try to read some unknown cluster
Definition: RagTime5ClusterManager.cxx:344
int getClusterFileType(RagTime5Zone &zone)
try to find a cluster zone type ( heuristic when the cluster type is unknown )
Definition: RagTime5ClusterManager.cxx:2443
Definition: RagTime5ClusterManager.hxx:265
std::shared_ptr< RagTime5ClusterManagerInternal::State > m_state
the state
Definition: RagTime5ClusterManager.hxx:466
Link m_listClusterLink[3]
first the main cluster link, second list of field definition link, third in header ...
Definition: RagTime5ClusterManager.hxx:367
Definition: RagTime5ClusterManager.hxx:268
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:201
int m_zoneId
the zone id
Definition: RagTime5ClusterManager.hxx:300
Definition: RagTime5ClusterManager.hxx:268
Definition: RagTime5ClusterManager.hxx:274
the cluster data
Definition: RagTime5ClusterManager.hxx:261
virtual std::string getZoneName(int n, int m=-1) const
return the debug name corresponding to a cluster
Definition: RagTime5ClusterManager.hxx:402

Generated for libmwaw by doxygen 1.8.14