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, shared_ptr<Cluster> &cluster, int type=-1);
82  bool readClusterMainList(ClusterRoot &root, std::vector<int> &list, std::vector<int> const &clusterIdList);
83 
85  bool readClusterGObjProperties(RagTime5Zone &zone);
87  bool readFieldClusters(Link const &link);
89  bool readUnknownClusterC(Link const &link);
91  int getClusterFileType(RagTime5Zone &zone);
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 {
107  enum Type { L_ClusterLink,
109  L_LongList, L_UnicodeList,
110  L_FieldsList, L_List,
112  L_Unknown
113  };
115  explicit Link(Type type=L_Unknown) : m_type(type), m_name(""), m_ids(), m_N(0), m_fieldSize(0), m_longList()
116  {
117  for (int i=0; i<2; ++i)
118  m_fileType[i]=0;
119  }
121  bool empty() const
122  {
123  if (m_type==L_LongList && !m_longList.empty())
124  return false;
125  for (size_t i=0; i<m_ids.size(); ++i)
126  if (m_ids[i]>0) return false;
127  return true;
128  }
130  std::string getZoneName() const
131  {
132  switch (m_type) {
133  case L_ClusterLink:
134  return "clustLink";
135  case L_LinkDef:
136  return "linkDef";
137  case L_LongList:
138  if (!m_name.empty())
139  return m_name;
140  else {
141  std::stringstream s;
142  s << "longList" << m_fieldSize;
143  return s.str();
144  }
145  case L_UnicodeList:
146  return "unicodeListLink";
147  case L_UnknownClusterC:
148  return "unknownClusterC";
149  case L_FieldsList:
150  if (!m_name.empty())
151  return m_name;
152  return "fieldsList[unkn]";
153  case L_List:
154  if (!m_name.empty())
155  return m_name;
156  break;
157  case L_Unknown:
158 #if !defined(__clang__)
159  default:
160 #endif
161  break;
162  }
163  std::stringstream s;
164  if (m_type==L_List)
165  s << "ListZone";
166  else
167  s << "FixZone";
168  s << std::hex << m_fileType[0] << "_" << m_fileType[1] << std::dec;
169  if (m_fieldSize)
170  s << "_" << m_fieldSize;
171  s << "A";
172  return s.str();
173  }
175  friend std::ostream &operator<<(std::ostream &o, Link const &z)
176  {
177  if (z.empty()) return o;
178  o << z.getZoneName() << ":";
179  size_t numLinks=z.m_ids.size();
180  if (numLinks>1) o << "[";
181  for (size_t i=0; i<numLinks; ++i) {
182  if (z.m_ids[i]<=0)
183  o << "_";
184  else
185  o << "data" << z.m_ids[i] << "A";
186  if (i+1!=numLinks) o << ",";
187  }
188  if (numLinks>1) o << "]";
189  if (z.m_fieldSize&0x8000)
190  o << "[" << std::hex << z.m_fieldSize << std::dec << ":" << z.m_N << "]";
191  else
192  o << "[" << z.m_fieldSize << ":" << z.m_N << "]";
193  return o;
194  }
198  std::string m_name;
200  std::vector<int> m_ids;
202  int m_N;
206  long m_fileType[2];
208  std::vector<long> m_longList;
209  };
210 
212  // cluster classes
214 
216  struct Cluster {
218  enum Type {
219  C_ColorPattern, C_Fields, C_Layout, C_Pipeline,
220  C_Root, C_ClusterGProp, C_Script,
221 
222  // the main zones
223  C_ChartZone, C_GraphicZone, C_PictureZone, C_SpreadsheetZone, C_TextZone,
224  // the styles
225  C_ColorStyles, C_FormatStyles, C_GraphicStyles, C_TextStyles, C_UnitStyles,
226  // unknown clusters
228 
229  C_Empty, C_Unknown
230  };
232  explicit Cluster(Type type) : m_type(type), m_zoneId(0), m_hiLoEndian(true), m_name(""),
233  m_dataLink(), m_nameLink(), m_fieldClusterLink(),
234  m_conditionFormulaLinks(), m_settingLinks(), m_linksList(), m_clusterIdsList(), m_isSent(false)
235  {
236  }
238  virtual ~Cluster();
242  int m_zoneId;
246  librevenge::RVNGString m_name;
254  std::vector<Link> m_conditionFormulaLinks;
256  std::vector<Link> m_settingLinks;
258  std::vector<Link> m_linksList;
260  std::vector<int> m_clusterIdsList;
262  bool m_isSent;
263  };
264 
266  Cluster::Type getClusterType(int zId) const;
267 
269  struct ClusterRoot : public Cluster {
271  ClusterRoot() : Cluster(C_Root), m_graphicTypeLink(), m_docInfoLink(), m_listUnicodeLink(),
272  m_listClusterId(0), m_listClusterName(), m_linkUnknown(), m_fileName("")
273  {
274  for (int i=0; i<8; ++i) m_styleClusterIds[i]=0;
275  for (int i=0; i<1; ++i) m_clusterIds[i]=0;
276  }
278  virtual ~ClusterRoot();
280  int m_styleClusterIds[8];
281 
283  int m_clusterIds[1];
284 
287 
297  Link m_listClusterLink[2];
298 
301 
303  librevenge::RVNGString m_fileName;
304  };
305 
307  struct ClusterScript : public Cluster {
309  ClusterScript() : Cluster(C_Script), m_scriptComment(), m_scriptName("")
310  {
311  }
313  virtual ~ClusterScript();
317  librevenge::RVNGString m_scriptName;
318  };
319 
321  // parser class
323 
325  struct ClusterParser {
327  ClusterParser(RagTime5ClusterManager &parser, int type, std::string const &zoneName) :
328  m_parser(parser), m_type(type), m_hiLoEndian(true), m_name(zoneName), m_dataId(0), m_link()
329  {
330  }
332  virtual ~ClusterParser();
334  virtual shared_ptr<Cluster> getCluster()=0;
336  virtual std::string getZoneName() const
337  {
338  return m_name;
339  }
341  virtual std::string getZoneName(int n, int m=-1) const
342  {
343  std::stringstream s;
344  s << m_name << "-" << n;
345  if (m>=0)
346  s << "-B" << m;
347  return s.str();
348  }
350  virtual void startZone()
351  {
352  }
354  virtual bool parseZone(MWAWInputStreamPtr &/*input*/, long /*fSz*/, int /*N*/, int /*flag*/, libmwaw::DebugStream &/*f*/)
355  {
356  return false;
357  }
359  virtual void endZone()
360  {
361  }
363  virtual bool parseField(RagTime5StructManager::Field const &/*field*/, int /*m*/, libmwaw::DebugStream &/*f*/)
364  {
365  return false;
366  }
369  virtual int getNewZoneToParse()
370  {
371  return -1;
372  }
373  //
374  // some tools
375  //
376 
378  bool isANameHeader(long N) const
379  {
380  return (m_hiLoEndian && N==int(0x80000000)) || (!m_hiLoEndian && N==0x8000);
381  }
382 
384  bool readLinkHeader(MWAWInputStreamPtr &input, long fSz, Link &link, long(&values)[4], std::string &message);
386  std::string getClusterName(int id);
390  int m_type;
394  std::string m_name;
396  int m_dataId;
399  private:
400  explicit ClusterParser(ClusterParser const &orig);
401  ClusterParser &operator=(ClusterParser const &orig);
402  };
403 protected:
405  shared_ptr<RagTime5ClusterManagerInternal::State> m_state;
409  shared_ptr<RagTime5StructManager> m_structManager;
410 private:
412  RagTime5ClusterManager operator=(RagTime5ClusterManager const &orig);
413 };
414 
415 #endif
416 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
librevenge::RVNGString m_scriptName
the scriptname if known
Definition: RagTime5ClusterManager.hxx:317
virtual int getNewZoneToParse()
returns to new zone to parse.
Definition: RagTime5ClusterManager.hxx:369
RagTime5Parser & m_mainParser
the main parser
Definition: RagTime5ClusterManager.hxx:407
Type m_type
the cluster type
Definition: RagTime5ClusterManager.hxx:240
Definition: RagTime5ClusterManager.hxx:223
Cluster(Type type)
constructor
Definition: RagTime5ClusterManager.hxx:232
RagTime5ClusterManager & m_parser
the main parser
Definition: RagTime5ClusterManager.hxx:388
Definition: RagTime5ClusterManager.hxx:225
ClusterRoot()
constructor
Definition: RagTime5ClusterManager.hxx:271
Link m_linkUnknown
other link: scripts and field 6
Definition: RagTime5ClusterManager.hxx:300
Link m_listUnicodeLink
a link to a list of unknown index+unicode string
Definition: RagTime5ClusterManager.hxx:291
virtual void endZone()
end of a start zone call
Definition: RagTime5ClusterManager.hxx:359
bool m_hiLoEndian
zone endian
Definition: RagTime5ClusterManager.hxx:392
int m_type
the cluster type
Definition: RagTime5ClusterManager.hxx:390
the cluster script ( 2/a/4002/400a zone)
Definition: RagTime5ClusterManager.hxx:307
Link m_graphicTypeLink
the graphic type id
Definition: RagTime5ClusterManager.hxx:286
bool isANameHeader(long N) const
return true if N correspond to a file/script name
Definition: RagTime5ClusterManager.hxx:378
bool m_isSent
true if the cluster was send
Definition: RagTime5ClusterManager.hxx:262
virtual class use to parse the cluster data
Definition: RagTime5ClusterManager.hxx:325
std::vector< Link > m_conditionFormulaLinks
the conditions formula links
Definition: RagTime5ClusterManager.hxx:254
main zone in a RagTime v5-v6 document
Definition: RagTime5StructManager.hxx:48
Link m_docInfoLink
the doc info link
Definition: RagTime5ClusterManager.hxx:289
Internal: the structures of a RagTime5ClusterManager.
Definition: RagTime5ClusterManager.cxx:48
librevenge::RVNGString m_fileName
the filename if known
Definition: RagTime5ClusterManager.hxx:303
the cluster for root
Definition: RagTime5ClusterManager.hxx:269
ClusterScript()
constructor
Definition: RagTime5ClusterManager.hxx:309
bool m_hiLoEndian
the cluster hiLo endian
Definition: RagTime5ClusterManager.hxx:244
Definition: RagTime5ClusterManager.hxx:220
ClusterParser(RagTime5ClusterManager &parser, int type, std::string const &zoneName)
constructor
Definition: RagTime5ClusterManager.hxx:327
virtual void startZone()
start a new zone
Definition: RagTime5ClusterManager.hxx:350
Definition: RagTime5ClusterManager.hxx:219
Link m_listClusterName
the cluster list id name zone link
Definition: RagTime5ClusterManager.hxx:295
basic class used to manage RagTime 5/6 zones
Definition: RagTime5ClusterManager.hxx:58
std::vector< Link > m_linksList
the link list
Definition: RagTime5ClusterManager.hxx:258
Link m_link
the actual link
Definition: RagTime5ClusterManager.hxx:398
virtual bool parseZone(MWAWInputStreamPtr &, long, int, int, libmwaw::DebugStream &)
parse a zone
Definition: RagTime5ClusterManager.hxx:354
the main class to read a RagTime v5 file
Definition: RagTime5Parser.hxx:73
a field of RagTime 5/6 structures
Definition: RagTime5StructManager.hxx:218
virtual std::string getZoneName() const
return the debug name corresponding to a zone
Definition: RagTime5ClusterManager.hxx:336
shared_ptr< MWAWInputStream > MWAWInputStreamPtr
a smart pointer of MWAWInputStream
Definition: libmwaw_internal.hxx:503
Link m_dataLink
the main data link
Definition: RagTime5ClusterManager.hxx:248
Type
the cluster type
Definition: RagTime5ClusterManager.hxx:218
std::vector< Link > m_settingLinks
the settings links
Definition: RagTime5ClusterManager.hxx:256
int m_listClusterId
the cluster list id
Definition: RagTime5ClusterManager.hxx:293
std::vector< int > m_clusterIdsList
the cluster ids
Definition: RagTime5ClusterManager.hxx:260
librevenge::RVNGString m_name
the cluster name (if know)
Definition: RagTime5ClusterManager.hxx:246
shared_ptr< RagTime5ClusterManagerInternal::State > m_state
the state
Definition: RagTime5ClusterManager.hxx:405
virtual bool parseField(RagTime5StructManager::Field const &, int, libmwaw::DebugStream &)
parse a the data of a zone, n_dataId:m
Definition: RagTime5ClusterManager.hxx:363
std::string m_name
the cluster name
Definition: RagTime5ClusterManager.hxx:394
std::stringstream DebugStream
a basic stream (if debug_with_files is not defined, does nothing)
Definition: MWAWDebug.hxx:61
Link m_scriptComment
the script comment zone
Definition: RagTime5ClusterManager.hxx:315
int m_dataId
the actual zone id
Definition: RagTime5ClusterManager.hxx:396
shared_ptr< RagTime5StructManager > m_structManager
the structure manager
Definition: RagTime5ClusterManager.hxx:409
Link m_nameLink
the name link
Definition: RagTime5ClusterManager.hxx:250
basic class used to store RagTime 5/6 structures
Definition: RagTime5StructManager.hxx:156
Link m_fieldClusterLink
the field cluster links (def and pos)
Definition: RagTime5ClusterManager.hxx:252
virtual std::string getZoneName(int n, int m=-1) const
return the debug name corresponding to a cluster
Definition: RagTime5ClusterManager.hxx:341
int m_zoneId
the zone id
Definition: RagTime5ClusterManager.hxx:242
Definition: RagTime5ClusterManager.hxx:227
the cluster data
Definition: RagTime5ClusterManager.hxx:216

Generated on Sat Jun 17 2017 01:18:11 for libmwaw by doxygen 1.8.11