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 
52 namespace RagTime5ClusterManagerInternal
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 
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) : 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  default:
159  break;
160  }
161  std::stringstream s;
162  if (m_type==L_List)
163  s << "ListZone";
164  else
165  s << "FixZone";
166  s << std::hex << m_fileType[0] << "_" << m_fileType[1] << std::dec;
167  if (m_fieldSize)
168  s << "_" << m_fieldSize;
169  s << "A";
170  return s.str();
171  }
173  friend std::ostream &operator<<(std::ostream &o, Link const &z)
174  {
175  if (z.empty()) return o;
176  o << z.getZoneName() << ":";
177  size_t numLinks=z.m_ids.size();
178  if (numLinks>1) o << "[";
179  for (size_t i=0; i<numLinks; ++i) {
180  if (z.m_ids[i]<=0)
181  o << "_";
182  else
183  o << "data" << z.m_ids[i] << "A";
184  if (i+1!=numLinks) o << ",";
185  }
186  if (numLinks>1) o << "]";
187  if (z.m_fieldSize&0x8000)
188  o << "[" << std::hex << z.m_fieldSize << std::dec << ":" << z.m_N << "]";
189  else
190  o << "[" << z.m_fieldSize << ":" << z.m_N << "]";
191  return o;
192  }
196  std::string m_name;
198  std::vector<int> m_ids;
200  int m_N;
204  long m_fileType[2];
206  std::vector<long> m_longList;
207  };
208 
210  // cluster classes
212 
214  struct Cluster {
216  enum Type {
219 
220  // the main zones
222  // the styles
224  // unknown clusters
226 
228  };
230  explicit Cluster(Type type) : m_type(type), m_zoneId(0), m_hiLoEndian(true), m_name(""),
233  {
234  }
236  virtual ~Cluster() {}
240  int m_zoneId;
244  librevenge::RVNGString m_name;
252  std::vector<Link> m_conditionFormulaLinks;
254  std::vector<Link> m_settingLinks;
256  std::vector<Link> m_linksList;
258  std::vector<int> m_clusterIdsList;
260  bool m_isSent;
261  };
262 
264  Cluster::Type getClusterType(int zId) const;
265 
267  struct ClusterRoot : public Cluster {
271  {
272  for (int i=0; i<8; ++i) m_styleClusterIds[i]=0;
273  for (int i=0; i<1; ++i) m_clusterIds[i]=0;
274  }
276  virtual ~ClusterRoot() {}
279 
281  int m_clusterIds[1];
282 
285 
296 
299 
301  librevenge::RVNGString m_fileName;
302  };
303 
305  struct ClusterScript : public Cluster {
308  {
309  }
311  virtual ~ClusterScript() {}
315  librevenge::RVNGString m_scriptName;
316  };
317 
319  // parser class
321 
323  struct ClusterParser {
325  ClusterParser(RagTime5ClusterManager &parser, int type, std::string const &zoneName) :
326  m_parser(parser), m_type(type), m_hiLoEndian(true), m_name(zoneName), m_dataId(0), m_link()
327  {
328  }
330  virtual ~ClusterParser() {}
332  virtual shared_ptr<Cluster> getCluster()=0;
334  virtual std::string getZoneName() const
335  {
336  return m_name;
337  }
339  virtual std::string getZoneName(int n, int m=-1) const
340  {
341  std::stringstream s;
342  s << m_name << "-" << n;
343  if (m>=0)
344  s << "-B" << m;
345  return s.str();
346  }
348  virtual void startZone()
349  {
350  }
352  virtual bool parseZone(MWAWInputStreamPtr &/*input*/, long /*fSz*/, int /*N*/, int /*flag*/, libmwaw::DebugStream &/*f*/)
353  {
354  return false;
355  }
357  virtual void endZone()
358  {
359  }
361  virtual bool parseField(RagTime5StructManager::Field const &/*field*/, int /*m*/, libmwaw::DebugStream &/*f*/)
362  {
363  return false;
364  }
367  virtual int getNewZoneToParse()
368  {
369  return -1;
370  }
371  //
372  // some tools
373  //
374 
376  bool isANameHeader(long N) const
377  {
378  return (m_hiLoEndian && N==int(0x80000000)) || (!m_hiLoEndian && N==0x8000);
379  }
380 
382  bool readLinkHeader(MWAWInputStreamPtr &input, long fSz, Link &link, long(&values)[4], std::string &message);
384  std::string getClusterName(int id);
388  int m_type;
392  std::string m_name;
394  int m_dataId;
397  private:
398  explicit ClusterParser(ClusterParser const &orig);
399  ClusterParser &operator=(ClusterParser const &orig);
400  };
401 protected:
403  shared_ptr<RagTime5ClusterManagerInternal::State> m_state;
407  shared_ptr<RagTime5StructManager> m_structManager;
408 private:
411 };
412 
413 #endif
414 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:

Generated on Tue Mar 1 2016 23:42:52 for libmwaw by doxygen 1.8.4