Blame src/lib/MWAWParser.hxx

rpm-build 6f7582
/* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
rpm-build 6f7582
rpm-build 6f7582
/* libmwaw
rpm-build 6f7582
* Version: MPL 2.0 / LGPLv2+
rpm-build 6f7582
*
rpm-build 6f7582
* The contents of this file are subject to the Mozilla Public License Version
rpm-build 6f7582
* 2.0 (the "License"); you may not use this file except in compliance with
rpm-build 6f7582
* the License or as specified alternatively below. You may obtain a copy of
rpm-build 6f7582
* the License at http://www.mozilla.org/MPL/
rpm-build 6f7582
*
rpm-build 6f7582
* Software distributed under the License is distributed on an "AS IS" basis,
rpm-build 6f7582
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
rpm-build 6f7582
* for the specific language governing rights and limitations under the
rpm-build 6f7582
* License.
rpm-build 6f7582
*
rpm-build 6f7582
* Major Contributor(s):
rpm-build 6f7582
* Copyright (C) 2002 William Lachance (wrlach@gmail.com)
rpm-build 6f7582
* Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
rpm-build 6f7582
* Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
rpm-build 6f7582
* Copyright (C) 2006, 2007 Andrew Ziem
rpm-build 6f7582
* Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
rpm-build 6f7582
*
rpm-build 6f7582
*
rpm-build 6f7582
* All Rights Reserved.
rpm-build 6f7582
*
rpm-build 6f7582
* For minor contributions see the git repository.
rpm-build 6f7582
*
rpm-build 6f7582
* Alternatively, the contents of this file may be used under the terms of
rpm-build 6f7582
* the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
rpm-build 6f7582
* in which case the provisions of the LGPLv2+ are applicable
rpm-build 6f7582
* instead of those above.
rpm-build 6f7582
*/
rpm-build 6f7582
rpm-build 6f7582
#ifndef MWAW_PARSER_H
rpm-build 6f7582
#define MWAW_PARSER_H
rpm-build 6f7582
rpm-build 6f7582
#include <ostream>
rpm-build 6f7582
#include <string>
rpm-build 6f7582
#include <vector>
rpm-build 6f7582
rpm-build 6f7582
#include "MWAWDebug.hxx"
rpm-build 6f7582
#include "MWAWInputStream.hxx"
rpm-build 6f7582
rpm-build 6f7582
#include "MWAWEntry.hxx"
rpm-build 6f7582
#include "MWAWHeader.hxx"
rpm-build 6f7582
#include "MWAWPageSpan.hxx"
rpm-build 6f7582
rpm-build 6f7582
/** a class to define the parser state */
rpm-build 6f7582
class MWAWParserState
rpm-build 6f7582
{
rpm-build 6f7582
public:
rpm-build 6f7582
  //! the parser state type
rpm-build 6f7582
  enum Type { Graphic, Presentation, Spreadsheet, Text };
rpm-build 6f7582
  //! Constructor
rpm-build 6f7582
  MWAWParserState(Type type, MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header);
rpm-build 6f7582
  //! destructor
rpm-build 6f7582
  ~MWAWParserState();
rpm-build 6f7582
  //! returns the main listener
rpm-build 6f7582
  MWAWListenerPtr getMainListener();
rpm-build 6f7582
  //! the state type
rpm-build 6f7582
  Type m_type;
rpm-build 6f7582
  //! the document kind
rpm-build 6f7582
  MWAWDocument::Kind m_kind;
rpm-build 6f7582
  //! the input
rpm-build 6f7582
  MWAWInputStreamPtr m_input;
rpm-build 6f7582
  //! the header
rpm-build 6f7582
  MWAWHeader *m_header;
rpm-build 6f7582
  //! the resource parser
rpm-build 6f7582
  MWAWRSRCParserPtr m_rsrcParser;
rpm-build 6f7582
  //! the actual document size
rpm-build 6f7582
  MWAWPageSpan m_pageSpan;
rpm-build 6f7582
rpm-build 6f7582
  //! the font converter
rpm-build 6f7582
  MWAWFontConverterPtr m_fontConverter;
rpm-build 6f7582
  //! the font manager
rpm-build 6f7582
  MWAWFontManagerPtr m_fontManager;
rpm-build 6f7582
  //! the graphic listener
rpm-build 6f7582
  MWAWGraphicListenerPtr m_graphicListener;
rpm-build 6f7582
  //! the list manager
rpm-build 6f7582
  MWAWListManagerPtr m_listManager;
rpm-build 6f7582
  //! the presentation listener
rpm-build 6f7582
  MWAWPresentationListenerPtr m_presentationListener;
rpm-build 6f7582
  //! the spreadsheet listener
rpm-build 6f7582
  MWAWSpreadsheetListenerPtr m_spreadsheetListener;
rpm-build 6f7582
  //! the text listener
rpm-build 6f7582
  MWAWTextListenerPtr m_textListener;
rpm-build 6f7582
  //! the actual version
rpm-build 6f7582
  int m_version;
rpm-build 6f7582
rpm-build 6f7582
  //! the debug file
rpm-build 6f7582
  libmwaw::DebugFile m_asciiFile;
rpm-build 6f7582
rpm-build 6f7582
private:
rpm-build 6f7582
  MWAWParserState(MWAWParserState const &orig) = delete;
rpm-build 6f7582
  MWAWParserState &operator=(MWAWParserState const &orig) = delete;
rpm-build 6f7582
};
rpm-build 6f7582
rpm-build 6f7582
/** virtual class which defines the ancestor of all main zone parser */
rpm-build 6f7582
class MWAWParser
rpm-build 6f7582
{
rpm-build 6f7582
public:
rpm-build 6f7582
  //! virtual destructor
rpm-build 6f7582
  virtual ~MWAWParser();
rpm-build 6f7582
  //! virtual function used to check if the document header is correct (or not)
rpm-build 6f7582
  virtual bool checkHeader(MWAWHeader *header, bool strict=false) = 0;
rpm-build 6f7582
rpm-build 6f7582
  //! returns the works version
rpm-build 6f7582
  int version() const
rpm-build 6f7582
  {
rpm-build 6f7582
    return m_parserState->m_version;
rpm-build 6f7582
  }
rpm-build 6f7582
  //! returns the parser state
rpm-build 6f7582
  MWAWParserStatePtr getParserState()
rpm-build 6f7582
  {
rpm-build 6f7582
    return m_parserState;
rpm-build 6f7582
  }
rpm-build 6f7582
  //! returns the header
rpm-build 6f7582
  MWAWHeader *getHeader()
rpm-build 6f7582
  {
rpm-build 6f7582
    return m_parserState->m_header;
rpm-build 6f7582
  }
rpm-build 6f7582
  //! returns the actual input
rpm-build 6f7582
  MWAWInputStreamPtr &getInput()
rpm-build 6f7582
  {
rpm-build 6f7582
    return m_parserState->m_input;
rpm-build 6f7582
  }
rpm-build 6f7582
  //! returns the main listener
rpm-build 6f7582
  MWAWListenerPtr getMainListener();
rpm-build 6f7582
  //! returns the graphic listener
rpm-build 6f7582
  MWAWGraphicListenerPtr &getGraphicListener()
rpm-build 6f7582
  {
rpm-build 6f7582
    return m_parserState->m_graphicListener;
rpm-build 6f7582
  }
rpm-build 6f7582
  //! returns the presentation listener
rpm-build 6f7582
  MWAWPresentationListenerPtr &getPresentationListener()
rpm-build 6f7582
  {
rpm-build 6f7582
    return m_parserState->m_presentationListener;
rpm-build 6f7582
  }
rpm-build 6f7582
  //! returns the spreadsheet listener
rpm-build 6f7582
  MWAWSpreadsheetListenerPtr &getSpreadsheetListener()
rpm-build 6f7582
  {
rpm-build 6f7582
    return m_parserState->m_spreadsheetListener;
rpm-build 6f7582
  }
rpm-build 6f7582
  //! returns the text listener
rpm-build 6f7582
  MWAWTextListenerPtr &getTextListener()
rpm-build 6f7582
  {
rpm-build 6f7582
    return m_parserState->m_textListener;
rpm-build 6f7582
  }
rpm-build 6f7582
  //! returns the font converter
rpm-build 6f7582
  MWAWFontConverterPtr &getFontConverter()
rpm-build 6f7582
  {
rpm-build 6f7582
    return m_parserState->m_fontConverter;
rpm-build 6f7582
  }
rpm-build 6f7582
  //! returns the font manager
rpm-build 6f7582
  MWAWFontManagerPtr &getFontManager()
rpm-build 6f7582
  {
rpm-build 6f7582
    return m_parserState->m_fontManager;
rpm-build 6f7582
  }
rpm-build 6f7582
  //! returns the actual page dimension
rpm-build 6f7582
  MWAWPageSpan const &getPageSpan() const
rpm-build 6f7582
  {
rpm-build 6f7582
    return m_parserState->m_pageSpan;
rpm-build 6f7582
  }
rpm-build 6f7582
  //! returns the actual page dimension
rpm-build 6f7582
  MWAWPageSpan &getPageSpan()
rpm-build 6f7582
  {
rpm-build 6f7582
    return m_parserState->m_pageSpan;
rpm-build 6f7582
  }
rpm-build 6f7582
  //! returns the form length
rpm-build 6f7582
  double getFormLength() const
rpm-build 6f7582
  {
rpm-build 6f7582
    return m_parserState->m_pageSpan.getFormLength();
rpm-build 6f7582
  }
rpm-build 6f7582
  //! returns the form width
rpm-build 6f7582
  double getFormWidth() const
rpm-build 6f7582
  {
rpm-build 6f7582
    return m_parserState->m_pageSpan.getFormWidth();
rpm-build 6f7582
  }
rpm-build 6f7582
  //! returns the page length (form length without margin )
rpm-build 6f7582
  double getPageLength() const
rpm-build 6f7582
  {
rpm-build 6f7582
    return m_parserState->m_pageSpan.getPageLength();
rpm-build 6f7582
  }
rpm-build 6f7582
  //! returns the page width (form width without margin )
rpm-build 6f7582
  double getPageWidth() const
rpm-build 6f7582
  {
rpm-build 6f7582
    return m_parserState->m_pageSpan.getPageWidth();
rpm-build 6f7582
  }
rpm-build 6f7582
  //! returns the rsrc parser
rpm-build 6f7582
  MWAWRSRCParserPtr &getRSRCParser()
rpm-build 6f7582
  {
rpm-build 6f7582
    return m_parserState->m_rsrcParser;
rpm-build 6f7582
  }
rpm-build 6f7582
  //! a DebugFile used to write what we recognize when we parse the document
rpm-build 6f7582
  libmwaw::DebugFile &ascii()
rpm-build 6f7582
  {
rpm-build 6f7582
    return m_parserState->m_asciiFile;
rpm-build 6f7582
  }
rpm-build 6f7582
protected:
rpm-build 6f7582
  //! constructor (protected)
rpm-build 6f7582
  MWAWParser(MWAWParserState::Type type, MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header);
rpm-build 6f7582
  //! constructor using a state
rpm-build 6f7582
  explicit MWAWParser(MWAWParserStatePtr const &state) : m_parserState(state), m_asciiName("") { }
rpm-build 6f7582
rpm-build 6f7582
  //! sets the document's version
rpm-build 6f7582
  void setVersion(int vers)
rpm-build 6f7582
  {
rpm-build 6f7582
    m_parserState->m_version = vers;
rpm-build 6f7582
  }
rpm-build 6f7582
  //! sets the graphic listener
rpm-build 6f7582
  void setGraphicListener(MWAWGraphicListenerPtr &listener);
rpm-build 6f7582
  //! resets the listener
rpm-build 6f7582
  void resetGraphicListener();
rpm-build 6f7582
  //! sets the presentation listener
rpm-build 6f7582
  void setPresentationListener(MWAWPresentationListenerPtr &listener);
rpm-build 6f7582
  //! resets the listener
rpm-build 6f7582
  void resetPresentationListener();
rpm-build 6f7582
  //! sets the spreadsheet listener
rpm-build 6f7582
  void setSpreadsheetListener(MWAWSpreadsheetListenerPtr &listener);
rpm-build 6f7582
  //! resets the listener
rpm-build 6f7582
  void resetSpreadsheetListener();
rpm-build 6f7582
  //! sets the text listener
rpm-build 6f7582
  void setTextListener(MWAWTextListenerPtr &listener);
rpm-build 6f7582
  //! resets the listener
rpm-build 6f7582
  void resetTextListener();
rpm-build 6f7582
  //! Debugging: change the default ascii file
rpm-build 6f7582
  void setAsciiName(char const *name)
rpm-build 6f7582
  {
rpm-build 6f7582
    m_asciiName = name;
rpm-build 6f7582
  }
rpm-build 6f7582
  //! return the ascii file name
rpm-build 6f7582
  std::string const &asciiName() const
rpm-build 6f7582
  {
rpm-build 6f7582
    return m_asciiName;
rpm-build 6f7582
  }
rpm-build 6f7582
rpm-build 6f7582
private:
rpm-build 6f7582
  //! private copy constructor: forbidden
rpm-build 6f7582
  MWAWParser(const MWAWParser &) = delete;
rpm-build 6f7582
  //! private operator=: forbidden
rpm-build 6f7582
  MWAWParser &operator=(const MWAWParser &) = delete;
rpm-build 6f7582
rpm-build 6f7582
  //! the parser state
rpm-build 6f7582
  MWAWParserStatePtr m_parserState;
rpm-build 6f7582
  //! the debug file name
rpm-build 6f7582
  std::string m_asciiName;
rpm-build 6f7582
};
rpm-build 6f7582
rpm-build 6f7582
/** virtual class which defines the ancestor of all graphic zone parser */
rpm-build 6f7582
class MWAWGraphicParser : public MWAWParser
rpm-build 6f7582
{
rpm-build 6f7582
public:
rpm-build 6f7582
  //! destructor
rpm-build 6f7582
  ~MWAWGraphicParser() override;
rpm-build 6f7582
  //! virtual function used to parse the input
rpm-build 6f7582
  virtual void parse(librevenge::RVNGDrawingInterface *documentInterface) = 0;
rpm-build 6f7582
protected:
rpm-build 6f7582
  //! constructor (protected)
rpm-build 6f7582
  MWAWGraphicParser(MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header) : MWAWParser(MWAWParserState::Graphic, input, rsrcParser, header) {}
rpm-build 6f7582
  //! constructor using a state
rpm-build 6f7582
  explicit MWAWGraphicParser(MWAWParserStatePtr const &state)
rpm-build 6f7582
    : MWAWParser(state) {}
rpm-build 6f7582
};
rpm-build 6f7582
rpm-build 6f7582
/** virtual class which defines the ancestor of all presentation zone parser */
rpm-build 6f7582
class MWAWPresentationParser : public MWAWParser
rpm-build 6f7582
{
rpm-build 6f7582
public:
rpm-build 6f7582
  //! destructor
rpm-build 6f7582
  ~MWAWPresentationParser() override;
rpm-build 6f7582
  //! virtual function used to parse the input
rpm-build 6f7582
  virtual void parse(librevenge::RVNGPresentationInterface *documentInterface) = 0;
rpm-build 6f7582
protected:
rpm-build 6f7582
  //! constructor (protected)
rpm-build 6f7582
  MWAWPresentationParser(MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header) : MWAWParser(MWAWParserState::Presentation, input, rsrcParser, header) {}
rpm-build 6f7582
  //! constructor using a state
rpm-build 6f7582
  explicit MWAWPresentationParser(MWAWParserStatePtr const &state)
rpm-build 6f7582
    : MWAWParser(state) {}
rpm-build 6f7582
};
rpm-build 6f7582
rpm-build 6f7582
/** virtual class which defines the ancestor of all spreadsheet zone parser */
rpm-build 6f7582
class MWAWSpreadsheetParser : public MWAWParser
rpm-build 6f7582
{
rpm-build 6f7582
public:
rpm-build 6f7582
  //! destructor
rpm-build 6f7582
  ~MWAWSpreadsheetParser() override;
rpm-build 6f7582
  //! virtual function used to parse the input
rpm-build 6f7582
  virtual void parse(librevenge::RVNGSpreadsheetInterface *documentInterface) = 0;
rpm-build 6f7582
protected:
rpm-build 6f7582
  //! constructor (protected)
rpm-build 6f7582
  MWAWSpreadsheetParser(MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header) : MWAWParser(MWAWParserState::Spreadsheet, input, rsrcParser, header) {}
rpm-build 6f7582
  //! constructor using a state
rpm-build 6f7582
  explicit MWAWSpreadsheetParser(MWAWParserStatePtr const &state)
rpm-build 6f7582
    : MWAWParser(state) {}
rpm-build 6f7582
};
rpm-build 6f7582
rpm-build 6f7582
/** virtual class which defines the ancestor of all text zone parser */
rpm-build 6f7582
class MWAWTextParser : public MWAWParser
rpm-build 6f7582
{
rpm-build 6f7582
public:
rpm-build 6f7582
  //! destructor
rpm-build 6f7582
  ~MWAWTextParser() override;
rpm-build 6f7582
  //! virtual function used to parse the input
rpm-build 6f7582
  virtual void parse(librevenge::RVNGTextInterface *documentInterface) = 0;
rpm-build 6f7582
protected:
rpm-build 6f7582
  //! constructor (protected)
rpm-build 6f7582
  MWAWTextParser(MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header) : MWAWParser(MWAWParserState::Text, input, rsrcParser, header) {}
rpm-build 6f7582
  //! constructor using a state
rpm-build 6f7582
  explicit MWAWTextParser(MWAWParserStatePtr const &state)
rpm-build 6f7582
    : MWAWParser(state) {}
rpm-build 6f7582
};
rpm-build 6f7582
rpm-build 6f7582
#endif /* MWAWPARSER_H */
rpm-build 6f7582
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: