STOFFParser.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 /* libstaroffice
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 STOFF_PARSER_H
00035 #define STOFF_PARSER_H
00036 
00037 #include <ostream>
00038 #include <string>
00039 #include <vector>
00040 
00041 #include "STOFFDebug.hxx"
00042 #include "STOFFInputStream.hxx"
00043 
00044 #include "STOFFEntry.hxx"
00045 #include "STOFFHeader.hxx"
00046 #include "STOFFPageSpan.hxx"
00047 
00049 class STOFFParserState
00050 {
00051 public:
00053   enum Type { Graphic, Presentation, Spreadsheet, Text };
00055   STOFFParserState(Type type, STOFFInputStreamPtr input, STOFFHeader *header);
00057   ~STOFFParserState();
00059   Type m_type;
00061   STOFFDocument::Kind m_kind;
00063   int m_version;
00065   STOFFInputStreamPtr m_input;
00067   STOFFHeader *m_header;
00069   STOFFPageSpan m_pageSpan;
00070 
00072   STOFFListManagerPtr m_listManager;
00074   STOFFGraphicListenerPtr m_graphicListener;
00076   STOFFSpreadsheetListenerPtr m_spreadsheetListener;
00078   STOFFTextListenerPtr m_textListener;
00079 
00081   libstoff::DebugFile m_asciiFile;
00082 
00083 private:
00084   STOFFParserState(STOFFParserState const &orig);
00085   STOFFParserState &operator=(STOFFParserState const &orig);
00086 };
00087 
00089 class STOFFParser
00090 {
00091 public:
00093   virtual ~STOFFParser();
00095   virtual bool checkHeader(STOFFHeader *header, bool strict=false) = 0;
00096 
00098   int version() const
00099   {
00100     return m_parserState->m_version;
00101   }
00103   STOFFParserStatePtr getParserState()
00104   {
00105     return m_parserState;
00106   }
00108   STOFFHeader *getHeader()
00109   {
00110     return m_parserState->m_header;
00111   }
00113   STOFFInputStreamPtr &getInput()
00114   {
00115     return m_parserState->m_input;
00116   }
00118   STOFFPageSpan const &getPageSpan() const
00119   {
00120     return m_parserState->m_pageSpan;
00121   }
00123   STOFFPageSpan &getPageSpan()
00124   {
00125     return m_parserState->m_pageSpan;
00126   }
00128   STOFFGraphicListenerPtr &getGraphicListener()
00129   {
00130     return m_parserState->m_graphicListener;
00131   }
00133   STOFFSpreadsheetListenerPtr &getSpreadsheetListener()
00134   {
00135     return m_parserState->m_spreadsheetListener;
00136   }
00138   STOFFTextListenerPtr &getTextListener()
00139   {
00140     return m_parserState->m_textListener;
00141   }
00143   libstoff::DebugFile &ascii()
00144   {
00145     return m_parserState->m_asciiFile;
00146   }
00147 protected:
00149   STOFFParser(STOFFParserState::Type type, STOFFInputStreamPtr input, STOFFHeader *header);
00151   explicit STOFFParser(STOFFParserStatePtr state) : m_parserState(state), m_asciiName("") { }
00152 
00154   void setVersion(int vers)
00155   {
00156     m_parserState->m_version = vers;
00157   }
00159   void setGraphicListener(STOFFGraphicListenerPtr &listener);
00161   void resetGraphicListener();
00163   void setSpreadsheetListener(STOFFSpreadsheetListenerPtr &listener);
00165   void resetSpreadsheetListener();
00167   void setTextListener(STOFFTextListenerPtr &listener);
00169   void resetTextListener();
00171   void setAsciiName(char const *name)
00172   {
00173     m_asciiName = name;
00174   }
00176   std::string const &asciiName() const
00177   {
00178     return m_asciiName;
00179   }
00180 
00181 private:
00183   STOFFParser(const STOFFParser &);
00185   STOFFParser &operator=(const STOFFParser &);
00186 
00188   STOFFParserStatePtr m_parserState;
00190   std::string m_asciiName;
00191 };
00192 
00194 class STOFFTextParser : public STOFFParser
00195 {
00196 public:
00198   virtual void parse(librevenge::RVNGTextInterface *documentInterface) = 0;
00199 protected:
00201   STOFFTextParser(STOFFInputStreamPtr input, STOFFHeader *header) : STOFFParser(STOFFParserState::Text, input, header) {}
00203   explicit STOFFTextParser(STOFFParserStatePtr state) : STOFFParser(state) {}
00205   virtual ~STOFFTextParser();
00206 };
00207 
00209 class STOFFGraphicParser : public STOFFParser
00210 {
00211 public:
00213   virtual void parse(librevenge::RVNGDrawingInterface *documentInterface) = 0;
00214 protected:
00216   STOFFGraphicParser(STOFFInputStreamPtr input, STOFFHeader *header) : STOFFParser(STOFFParserState::Graphic, input, header) {}
00218   explicit STOFFGraphicParser(STOFFParserStatePtr state) : STOFFParser(state) {}
00220   virtual ~STOFFGraphicParser();
00221 };
00222 
00224 class STOFFSpreadsheetParser : public STOFFParser
00225 {
00226 public:
00228   virtual void parse(librevenge::RVNGSpreadsheetInterface *documentInterface) = 0;
00229 protected:
00231   STOFFSpreadsheetParser(STOFFInputStreamPtr input, STOFFHeader *header) : STOFFParser(STOFFParserState::Spreadsheet, input, header) {}
00233   explicit STOFFSpreadsheetParser(STOFFParserStatePtr state) : STOFFParser(state) {}
00235   virtual ~STOFFSpreadsheetParser();
00236 };
00237 
00238 #endif /* STOFFPARSER_H */
00239 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: