MWAWParser.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 MWAW_PARSER_H
00035 #define MWAW_PARSER_H
00036 
00037 #include <ostream>
00038 #include <string>
00039 #include <vector>
00040 
00041 #include "MWAWDebug.hxx"
00042 #include "MWAWInputStream.hxx"
00043 
00044 #include "MWAWEntry.hxx"
00045 #include "MWAWHeader.hxx"
00046 #include "MWAWPageSpan.hxx"
00047 
00049 class MWAWParserState
00050 {
00051 public:
00053   enum Type { Graphic, Presentation, Spreadsheet, Text };
00055   MWAWParserState(Type type, MWAWInputStreamPtr input, MWAWRSRCParserPtr rsrcParser, MWAWHeader *header);
00057   ~MWAWParserState();
00059   MWAWListenerPtr getMainListener();
00061   Type m_type;
00063   MWAWDocument::Kind m_kind;
00065   int m_version;
00067   MWAWInputStreamPtr m_input;
00069   MWAWHeader *m_header;
00071   MWAWRSRCParserPtr m_rsrcParser;
00073   MWAWPageSpan m_pageSpan;
00074 
00076   MWAWFontConverterPtr m_fontConverter;
00078   MWAWGraphicListenerPtr m_graphicListener;
00080   MWAWListManagerPtr m_listManager;
00082   MWAWPresentationListenerPtr m_presentationListener;
00084   MWAWSpreadsheetListenerPtr m_spreadsheetListener;
00086   MWAWTextListenerPtr m_textListener;
00087 
00089   libmwaw::DebugFile m_asciiFile;
00090 
00091 private:
00092   MWAWParserState(MWAWParserState const &orig);
00093   MWAWParserState &operator=(MWAWParserState const &orig);
00094 };
00095 
00097 class MWAWParser
00098 {
00099 public:
00101   virtual ~MWAWParser();
00103   virtual bool checkHeader(MWAWHeader *header, bool strict=false) = 0;
00104 
00106   int version() const
00107   {
00108     return m_parserState->m_version;
00109   }
00111   MWAWParserStatePtr getParserState()
00112   {
00113     return m_parserState;
00114   }
00116   MWAWHeader *getHeader()
00117   {
00118     return m_parserState->m_header;
00119   }
00121   MWAWInputStreamPtr &getInput()
00122   {
00123     return m_parserState->m_input;
00124   }
00126   MWAWListenerPtr getMainListener();
00128   MWAWGraphicListenerPtr &getGraphicListener()
00129   {
00130     return m_parserState->m_graphicListener;
00131   }
00133   MWAWPresentationListenerPtr &getPresentationListener()
00134   {
00135     return m_parserState->m_presentationListener;
00136   }
00138   MWAWSpreadsheetListenerPtr &getSpreadsheetListener()
00139   {
00140     return m_parserState->m_spreadsheetListener;
00141   }
00143   MWAWTextListenerPtr &getTextListener()
00144   {
00145     return m_parserState->m_textListener;
00146   }
00148   MWAWFontConverterPtr &getFontConverter()
00149   {
00150     return m_parserState->m_fontConverter;
00151   }
00153   MWAWPageSpan const &getPageSpan() const
00154   {
00155     return m_parserState->m_pageSpan;
00156   }
00158   MWAWPageSpan &getPageSpan()
00159   {
00160     return m_parserState->m_pageSpan;
00161   }
00163   double getFormLength() const
00164   {
00165     return m_parserState->m_pageSpan.getFormLength();
00166   }
00168   double getFormWidth() const
00169   {
00170     return m_parserState->m_pageSpan.getFormWidth();
00171   }
00173   double getPageLength() const
00174   {
00175     return m_parserState->m_pageSpan.getPageLength();
00176   }
00178   double getPageWidth() const
00179   {
00180     return m_parserState->m_pageSpan.getPageWidth();
00181   }
00183   MWAWRSRCParserPtr &getRSRCParser()
00184   {
00185     return m_parserState->m_rsrcParser;
00186   }
00188   libmwaw::DebugFile &ascii()
00189   {
00190     return m_parserState->m_asciiFile;
00191   }
00192 protected:
00194   MWAWParser(MWAWParserState::Type type, MWAWInputStreamPtr input, MWAWRSRCParserPtr rsrcParser, MWAWHeader *header);
00196   MWAWParser(MWAWParserStatePtr state) : m_parserState(state), m_asciiName("") { }
00197 
00199   void setVersion(int vers)
00200   {
00201     m_parserState->m_version = vers;
00202   }
00204   void setGraphicListener(MWAWGraphicListenerPtr &listener);
00206   void resetGraphicListener();
00208   void setPresentationListener(MWAWPresentationListenerPtr &listener);
00210   void resetPresentationListener();
00212   void setSpreadsheetListener(MWAWSpreadsheetListenerPtr &listener);
00214   void resetSpreadsheetListener();
00216   void setTextListener(MWAWTextListenerPtr &listener);
00218   void resetTextListener();
00220   void setFontConverter(MWAWFontConverterPtr fontConverter);
00222   void setAsciiName(char const *name)
00223   {
00224     m_asciiName = name;
00225   }
00227   std::string const &asciiName() const
00228   {
00229     return m_asciiName;
00230   }
00231 
00232 private:
00234   MWAWParser(const MWAWParser &);
00236   MWAWParser &operator=(const MWAWParser &);
00237 
00239   MWAWParserStatePtr m_parserState;
00241   std::string m_asciiName;
00242 };
00243 
00245 class MWAWGraphicParser : public MWAWParser
00246 {
00247 public:
00249   virtual void parse(librevenge::RVNGDrawingInterface *documentInterface) = 0;
00250 protected:
00252   MWAWGraphicParser(MWAWInputStreamPtr input, MWAWRSRCParserPtr rsrcParser, MWAWHeader *header) : MWAWParser(MWAWParserState::Graphic, input, rsrcParser, header) {}
00254   MWAWGraphicParser(MWAWParserStatePtr state) : MWAWParser(state) {}
00255 };
00256 
00258 class MWAWPresentationParser : public MWAWParser
00259 {
00260 public:
00262   virtual void parse(librevenge::RVNGPresentationInterface *documentInterface) = 0;
00263 protected:
00265   MWAWPresentationParser(MWAWInputStreamPtr input, MWAWRSRCParserPtr rsrcParser, MWAWHeader *header) : MWAWParser(MWAWParserState::Presentation, input, rsrcParser, header) {}
00267   MWAWPresentationParser(MWAWParserStatePtr state) : MWAWParser(state) {}
00268 };
00269 
00271 class MWAWSpreadsheetParser : public MWAWParser
00272 {
00273 public:
00275   virtual void parse(librevenge::RVNGSpreadsheetInterface *documentInterface) = 0;
00276 protected:
00278   MWAWSpreadsheetParser(MWAWInputStreamPtr input, MWAWRSRCParserPtr rsrcParser, MWAWHeader *header) : MWAWParser(MWAWParserState::Spreadsheet, input, rsrcParser, header) {}
00280   MWAWSpreadsheetParser(MWAWParserStatePtr state) : MWAWParser(state) {}
00281 };
00282 
00284 class MWAWTextParser : public MWAWParser
00285 {
00286 public:
00288   virtual void parse(librevenge::RVNGTextInterface *documentInterface) = 0;
00289 protected:
00291   MWAWTextParser(MWAWInputStreamPtr input, MWAWRSRCParserPtr rsrcParser, MWAWHeader *header) : MWAWParser(MWAWParserState::Text, input, rsrcParser, header) {}
00293   MWAWTextParser(MWAWParserStatePtr state) : MWAWParser(state) {}
00294 };
00295 
00296 #endif /* MWAWPARSER_H */
00297 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: