RagTime5Parser.hxx
Go to the documentation of this file.
00001 /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
00002 
00003 /* libmwaw
00004 * Version: MPL 2.0 / LGPLv2+
00005 *
00006 * The contents of this file are subject to the Mozilla Public License Version
00007 * 2.0 (the "License"); you may not use this file except in compliance with
00008 * the License or as specified alternatively below. You may obtain a copy of
00009 * the License at http://www.mozilla.org/MPL/
00010 *
00011 * Software distributed under the License is distributed on an "AS IS" basis,
00012 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013 * for the specific language governing rights and limitations under the
00014 * License.
00015 *
00016 * Major Contributor(s):
00017 * Copyright (C) 2002 William Lachance (wrlach@gmail.com)
00018 * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
00019 * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
00020 * Copyright (C) 2006, 2007 Andrew Ziem
00021 * Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
00022 *
00023 *
00024 * All Rights Reserved.
00025 *
00026 * For minor contributions see the git repository.
00027 *
00028 * Alternatively, the contents of this file may be used under the terms of
00029 * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
00030 * in which case the provisions of the LGPLv2+ are applicable
00031 * instead of those above.
00032 */
00033 
00034 #ifndef RAG_TIME_5_PARSER
00035 #  define RAG_TIME_5_PARSER
00036 
00037 #include <map>
00038 #include <string>
00039 #include <set>
00040 #include <vector>
00041 
00042 #include "MWAWDebug.hxx"
00043 #include "MWAWInputStream.hxx"
00044 
00045 #include "MWAWParser.hxx"
00046 
00047 #include "RagTime5StructManager.hxx"
00048 #include "RagTime5ClusterManager.hxx"
00049 
00050 namespace RagTime5ParserInternal
00051 {
00052 struct DocInfoFieldParser;
00053 struct State;
00054 class SubDocument;
00055 }
00056 
00057 class RagTime5Graph;
00058 class RagTime5Spreadsheet;
00059 class RagTime5StructManager;
00060 class RagTime5Text;
00061 class RagTime5Zone;
00062 class RagTime5ClusterManager;
00063 
00069 class RagTime5Parser : public MWAWTextParser
00070 {
00071   friend class RagTime5Graph;
00072   friend class RagTime5Spreadsheet;
00073   friend class RagTime5Text;
00074   friend class RagTime5ClusterManager;
00075   friend struct RagTime5ParserInternal::DocInfoFieldParser;
00076   friend class RagTime5ParserInternal::SubDocument;
00077 
00078 public:
00080   RagTime5Parser(MWAWInputStreamPtr input, MWAWRSRCParserPtr rsrcParser, MWAWHeader *header);
00082   virtual ~RagTime5Parser();
00083 
00085   bool checkHeader(MWAWHeader *header, bool strict=false);
00086 
00087   // the main parse function
00088   void parse(librevenge::RVNGTextInterface *documentInterface);
00089 
00090 protected:
00092   void init();
00093 
00094   //
00095   // interface
00096   //
00097 
00099   shared_ptr<RagTime5ClusterManager> getClusterManager();
00101   shared_ptr<RagTime5StructManager> getStructManager();
00102 
00104   bool readChartCluster(RagTime5Zone &zone, int zoneType);
00106   bool readGraphicCluster(RagTime5Zone &zone, int zoneType);
00108   bool readPictureCluster(RagTime5Zone &zone, int zoneType);
00110   bool readSpreadsheetCluster(RagTime5Zone &zone, int zoneType);
00112   bool readTextCluster(RagTime5Zone &zone, int zoneType);
00113 
00115   void createDocument(librevenge::RVNGTextInterface *documentInterface);
00117   bool sendZones();
00118 
00120   void newPage(int number);
00121 
00123   bool createZones();
00125   bool findDataZones(MWAWEntry const &entry);
00127   shared_ptr<RagTime5Zone> getDataZone(int dataId) const;
00129   bool update(RagTime5Zone &zone);
00131   bool readZoneData(RagTime5Zone &zone);
00133   bool unpackZone(RagTime5Zone &zone, MWAWEntry const &entry, std::vector<unsigned char> &data);
00135   bool unpackZone(RagTime5Zone &zone);
00136 
00138   bool readClusterZones();
00140   bool readClusterZone(RagTime5Zone &zone, int type=-1);
00142   bool readClusterLinkList(RagTime5Zone &zone,
00143                            RagTime5ClusterManager::Link const &link);
00145   bool readClusterLinkList(RagTime5ClusterManager::Link const &link,
00146                            RagTime5ClusterManager::Link const &nameLink,
00147                            std::vector<int> &list, std::string const &name="");
00148 
00150   bool readString(RagTime5Zone &zone, std::string &string);
00152   bool readUnicodeString(RagTime5Zone &zone);
00154   bool readLongListWithSize(int dataId, int fSz, std::vector<long> &list, std::string const &zoneName="");
00156   bool readPositions(int posId, std::vector<long> &listPosition);
00158   bool readLongList(RagTime5ClusterManager::Link const &link, std::vector<long> &list);
00160   bool readUnicodeStringList(RagTime5ClusterManager::Link const &link, std::map<int, librevenge::RVNGString> &idToStringMap);
00161 
00163   bool readDocumentVersion(RagTime5Zone &zone);
00165   bool readClusterRootData(RagTime5ClusterManager::ClusterRoot &cluster);
00167   bool readFormats(RagTime5ClusterManager::Cluster &cluster);
00169   bool readClusterFieldsData(RagTime5ClusterManager::Cluster &cluster);
00171   bool readClusterLayoutData(RagTime5ClusterManager::ClusterLayout &cluster);
00173   bool readClusterPipelineData(RagTime5ClusterManager::Cluster &cluster);
00175   bool readDocInfoClusterData(RagTime5Zone &zone, MWAWEntry const &entry);
00177   bool readClusterScriptData(RagTime5ClusterManager::ClusterScript &cluster);
00179   bool readUnknownClusterBData(RagTime5ClusterManager::Cluster &cluster);
00181   bool readUnknownClusterCData(RagTime5ClusterManager::Cluster &cluster);
00182 
00184   bool readStructZone(RagTime5ClusterManager::Cluster &cluster, RagTime5StructManager::FieldParser &parser, int headerSz);
00186   bool readStructData(RagTime5Zone &zone, long endPos, int n, int headerSz,
00187                       RagTime5StructManager::FieldParser &parser, librevenge::RVNGString const &dataName);
00189   bool readStructMainZone(RagTime5Zone &zone);
00190 
00192   bool readListZone(RagTime5ClusterManager::Link const &link);
00194   bool readListZone(RagTime5ClusterManager::Link const &link, RagTime5StructManager::DataParser &parser);
00196   bool readFixedSizeZone(RagTime5ClusterManager::Link const &link, std::string const &name);
00198   bool readFixedSizeZone(RagTime5ClusterManager::Link const &link, RagTime5StructManager::DataParser &parser);
00199 
00201   bool checkClusterList(std::vector<int> const &list);
00203   void flushExtra();
00204 
00205 protected:
00206 
00207   //
00208   // data
00209   //
00211   shared_ptr<RagTime5ParserInternal::State> m_state;
00213   shared_ptr<RagTime5Graph> m_graphParser;
00215   shared_ptr<RagTime5Spreadsheet> m_spreadsheetParser;
00217   shared_ptr<RagTime5Text> m_textParser;
00219   shared_ptr<RagTime5StructManager> m_structManager;
00221   shared_ptr<RagTime5ClusterManager> m_clusterManager;
00222 };
00223 #endif
00224 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: