STOFFParser.hxx
Go to the documentation of this file.
/* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
/* libstaroffice
* Version: MPL 2.0 / LGPLv2+
*
* The contents of this file are subject to the Mozilla Public License Version
* 2.0 (the "License"); you may not use this file except in compliance with
* the License or as specified alternatively below. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* Major Contributor(s):
* Copyright (C) 2002 William Lachance (wrlach@gmail.com)
* Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
* Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
* Copyright (C) 2006, 2007 Andrew Ziem
* Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
*
*
* All Rights Reserved.
*
* For minor contributions see the git repository.
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
* in which case the provisions of the LGPLv2+ are applicable
* instead of those above.
*/
#ifndef STOFF_PARSER_H
#define STOFF_PARSER_H
#include <ostream>
#include <string>
#include <vector>
#include "STOFFDebug.hxx"
#include "STOFFInputStream.hxx"
#include "STOFFEntry.hxx"
#include "STOFFHeader.hxx"
#include "STOFFPageSpan.hxx"
class STOFFParserState
{
public:
enum Type { Graphic, Presentation, Spreadsheet, Text };
STOFFParserState(Type type, STOFFInputStreamPtr &input, STOFFHeader *header);
~STOFFParserState();
Type m_type;
STOFFDocument::Kind m_kind;
int m_version;
STOFFInputStreamPtr m_input;
STOFFHeader *m_header;
STOFFPageSpan m_pageSpan;
STOFFListManagerPtr m_listManager;
STOFFGraphicListenerPtr m_graphicListener;
STOFFSpreadsheetListenerPtr m_spreadsheetListener;
STOFFTextListenerPtr m_textListener;
libstoff::DebugFile m_asciiFile;
private:
STOFFParserState(STOFFParserState const &orig);
STOFFParserState &operator=(STOFFParserState const &orig);
};
class STOFFParser
{
public:
virtual ~STOFFParser();
virtual bool checkHeader(STOFFHeader *header, bool strict=false) = 0;
int version() const
{
return m_parserState->m_version;
}
STOFFParserStatePtr getParserState()
{
return m_parserState;
}
STOFFHeader *getHeader()
{
return m_parserState->m_header;
}
STOFFInputStreamPtr &getInput()
{
return m_parserState->m_input;
}
STOFFPageSpan const &getPageSpan() const
{
return m_parserState->m_pageSpan;
}
STOFFPageSpan &getPageSpan()
{
return m_parserState->m_pageSpan;
}
STOFFGraphicListenerPtr &getGraphicListener()
{
return m_parserState->m_graphicListener;
}
STOFFSpreadsheetListenerPtr &getSpreadsheetListener()
{
return m_parserState->m_spreadsheetListener;
}
STOFFTextListenerPtr &getTextListener()
{
return m_parserState->m_textListener;
}
libstoff::DebugFile &ascii()
{
return m_parserState->m_asciiFile;
}
protected:
STOFFParser(STOFFParserState::Type type, STOFFInputStreamPtr input, STOFFHeader *header);
explicit STOFFParser(STOFFParserStatePtr &state) : m_parserState(state), m_asciiName("") { }
void setVersion(int vers)
{
m_parserState->m_version = vers;
}
void setGraphicListener(STOFFGraphicListenerPtr &listener);
void resetGraphicListener();
void setSpreadsheetListener(STOFFSpreadsheetListenerPtr &listener);
void resetSpreadsheetListener();
void setTextListener(STOFFTextListenerPtr &listener);
void resetTextListener();
void setAsciiName(char const *name)
{
m_asciiName = name;
}
std::string const &asciiName() const
{
return m_asciiName;
}
private:
STOFFParser(const STOFFParser &);
STOFFParser &operator=(const STOFFParser &);
STOFFParserStatePtr m_parserState;
std::string m_asciiName;
};
class STOFFTextParser : public STOFFParser
{
public:
virtual void parse(librevenge::RVNGTextInterface *documentInterface) = 0;
protected:
STOFFTextParser(STOFFInputStreamPtr &input, STOFFHeader *header) : STOFFParser(STOFFParserState::Text, input, header) {}
explicit STOFFTextParser(STOFFParserStatePtr &state) : STOFFParser(state) {}
~STOFFTextParser() override;
};
class STOFFGraphicParser : public STOFFParser
{
public:
virtual void parse(librevenge::RVNGDrawingInterface *documentInterface);
virtual void parse(librevenge::RVNGPresentationInterface *documentInterface);
protected:
STOFFGraphicParser(STOFFInputStreamPtr &input, STOFFHeader *header) : STOFFParser(STOFFParserState::Graphic, input, header) {}
explicit STOFFGraphicParser(STOFFParserStatePtr &state) : STOFFParser(state) {}
~STOFFGraphicParser() override;
};
class STOFFSpreadsheetParser : public STOFFParser
{
public:
virtual void parse(librevenge::RVNGSpreadsheetInterface *documentInterface) = 0;
protected:
STOFFSpreadsheetParser(STOFFInputStreamPtr &input, STOFFHeader *header) : STOFFParser(STOFFParserState::Spreadsheet, input, header) {}
explicit STOFFSpreadsheetParser(STOFFParserStatePtr &state) : STOFFParser(state) {}
~STOFFSpreadsheetParser() override;
};
#endif /* STOFFPARSER_H */
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
STOFFDebug.hxx
STOFFEntry.hxx
STOFFHeader.hxx
Defines STOFFHeader (document's type, version, kind).
STOFFInputStream.hxx
STOFFPageSpan.hxx
STOFFDocument::Kind
Kind
an enum to define the kind of document
Definition STOFFDocument.hxx:66
STOFFGraphicParser::STOFFGraphicParser
STOFFGraphicParser(STOFFParserStatePtr &state)
constructor using a state
Definition STOFFParser.hxx:220
STOFFGraphicParser::~STOFFGraphicParser
~STOFFGraphicParser() override
destructor
Definition STOFFParser.cxx:111
STOFFGraphicParser::parse
virtual void parse(librevenge::RVNGDrawingInterface *documentInterface)
virtual function used to parse the input
Definition STOFFParser.cxx:115
STOFFGraphicParser::STOFFGraphicParser
STOFFGraphicParser(STOFFInputStreamPtr &input, STOFFHeader *header)
constructor (protected)
Definition STOFFParser.hxx:218
STOFFHeader
a function used by STOFFDocument to store the version of document
Definition STOFFHeader.hxx:57
STOFFPageSpan
A class which defines the page properties.
Definition STOFFPageSpan.hxx:76
STOFFParserState
a class to define the parser state
Definition STOFFParser.hxx:50
STOFFParserState::~STOFFParserState
~STOFFParserState()
destructor
Definition STOFFParser.cxx:63
STOFFParserState::m_spreadsheetListener
STOFFSpreadsheetListenerPtr m_spreadsheetListener
the spreadsheet listener
Definition STOFFParser.hxx:76
STOFFParserState::m_textListener
STOFFTextListenerPtr m_textListener
the text listener
Definition STOFFParser.hxx:78
STOFFParserState::m_graphicListener
STOFFGraphicListenerPtr m_graphicListener
the graphic listener
Definition STOFFParser.hxx:74
STOFFParserState::Type
Type
the parser state type
Definition STOFFParser.hxx:53
STOFFParserState::Graphic
@ Graphic
Definition STOFFParser.hxx:53
STOFFParserState::Presentation
@ Presentation
Definition STOFFParser.hxx:53
STOFFParserState::Spreadsheet
@ Spreadsheet
Definition STOFFParser.hxx:53
STOFFParserState::Text
@ Text
Definition STOFFParser.hxx:53
STOFFParserState::m_type
Type m_type
the state type
Definition STOFFParser.hxx:59
STOFFParserState::m_asciiFile
libstoff::DebugFile m_asciiFile
the debug file
Definition STOFFParser.hxx:81
STOFFParserState::m_kind
STOFFDocument::Kind m_kind
the document kind
Definition STOFFParser.hxx:61
STOFFParserState::operator=
STOFFParserState & operator=(STOFFParserState const &orig)
STOFFParserState::m_listManager
STOFFListManagerPtr m_listManager
the list manager
Definition STOFFParser.hxx:72
STOFFParserState::m_version
int m_version
the actual version
Definition STOFFParser.hxx:63
STOFFParserState::STOFFParserState
STOFFParserState(STOFFParserState const &orig)
STOFFParserState::m_input
STOFFInputStreamPtr m_input
the input
Definition STOFFParser.hxx:65
STOFFParserState::m_pageSpan
STOFFPageSpan m_pageSpan
the actual document size
Definition STOFFParser.hxx:69
STOFFParserState::STOFFParserState
STOFFParserState(Type type, STOFFInputStreamPtr &input, STOFFHeader *header)
Constructor.
Definition STOFFParser.cxx:43
STOFFParserState::m_header
STOFFHeader * m_header
the header
Definition STOFFParser.hxx:67
STOFFParser::version
int version() const
returns the works version
Definition STOFFParser.hxx:98
STOFFParser::getInput
STOFFInputStreamPtr & getInput()
returns the actual input
Definition STOFFParser.hxx:113
STOFFParser::asciiName
std::string const & asciiName() const
return the ascii file name
Definition STOFFParser.hxx:176
STOFFParser::getSpreadsheetListener
STOFFSpreadsheetListenerPtr & getSpreadsheetListener()
returns the spreadsheet listener
Definition STOFFParser.hxx:133
STOFFParser::STOFFParser
STOFFParser(STOFFParserStatePtr &state)
constructor using a state
Definition STOFFParser.hxx:151
STOFFParser::getParserState
STOFFParserStatePtr getParserState()
returns the parser state
Definition STOFFParser.hxx:103
STOFFParser::ascii
libstoff::DebugFile & ascii()
a DebugFile used to write what we recognize when we parse the document
Definition STOFFParser.hxx:143
STOFFParser::setGraphicListener
void setGraphicListener(STOFFGraphicListenerPtr &listener)
sets the graphic listener
Definition STOFFParser.cxx:78
STOFFParser::getPageSpan
STOFFPageSpan const & getPageSpan() const
returns the actual page dimension
Definition STOFFParser.hxx:118
STOFFParser::setTextListener
void setTextListener(STOFFTextListenerPtr &listener)
sets the text listener
Definition STOFFParser.cxx:100
STOFFParser::setAsciiName
void setAsciiName(char const *name)
Debugging: change the default ascii file.
Definition STOFFParser.hxx:171
STOFFParser::setVersion
void setVersion(int vers)
sets the document's version
Definition STOFFParser.hxx:154
STOFFParser::STOFFParser
STOFFParser(const STOFFParser &)
private copy constructor: forbidden
STOFFParser::setSpreadsheetListener
void setSpreadsheetListener(STOFFSpreadsheetListenerPtr &listener)
sets the spreadsheet listener
Definition STOFFParser.cxx:89
STOFFParser::getPageSpan
STOFFPageSpan & getPageSpan()
returns the actual page dimension
Definition STOFFParser.hxx:123
STOFFParser::~STOFFParser
virtual ~STOFFParser()
virtual destructor
Definition STOFFParser.cxx:74
STOFFParser::resetGraphicListener
void resetGraphicListener()
resets the graphic listener
Definition STOFFParser.cxx:83
STOFFParser::getGraphicListener
STOFFGraphicListenerPtr & getGraphicListener()
returns the graphic listener
Definition STOFFParser.hxx:128
STOFFParser::resetSpreadsheetListener
void resetSpreadsheetListener()
resets the spreadsheet listener
Definition STOFFParser.cxx:94
STOFFParser::checkHeader
virtual bool checkHeader(STOFFHeader *header, bool strict=false)=0
virtual function used to check if the document header is correct (or not)
STOFFParser::resetTextListener
void resetTextListener()
resets the text listener
Definition STOFFParser.cxx:105
STOFFParser::STOFFParser
STOFFParser(STOFFParserState::Type type, STOFFInputStreamPtr input, STOFFHeader *header)
constructor (protected)
Definition STOFFParser.cxx:67
STOFFParser::operator=
STOFFParser & operator=(const STOFFParser &)
private operator=: forbidden
STOFFParser::getHeader
STOFFHeader * getHeader()
returns the header
Definition STOFFParser.hxx:108
STOFFParser::m_parserState
STOFFParserStatePtr m_parserState
the parser state
Definition STOFFParser.hxx:188
STOFFParser::m_asciiName
std::string m_asciiName
the debug file name
Definition STOFFParser.hxx:190
STOFFParser::getTextListener
STOFFTextListenerPtr & getTextListener()
returns the text listener
Definition STOFFParser.hxx:138
STOFFSpreadsheetParser::STOFFSpreadsheetParser
STOFFSpreadsheetParser(STOFFInputStreamPtr &input, STOFFHeader *header)
constructor (protected)
Definition STOFFParser.hxx:233
STOFFSpreadsheetParser::STOFFSpreadsheetParser
STOFFSpreadsheetParser(STOFFParserStatePtr &state)
constructor using a state
Definition STOFFParser.hxx:235
STOFFSpreadsheetParser::parse
virtual void parse(librevenge::RVNGSpreadsheetInterface *documentInterface)=0
virtual function used to parse the input
STOFFSpreadsheetParser::~STOFFSpreadsheetParser
~STOFFSpreadsheetParser() override
destructor
Definition STOFFParser.cxx:125
STOFFTextParser::STOFFTextParser
STOFFTextParser(STOFFInputStreamPtr &input, STOFFHeader *header)
constructor (protected)
Definition STOFFParser.hxx:201
STOFFTextParser::~STOFFTextParser
~STOFFTextParser() override
destructor
Definition STOFFParser.cxx:129
STOFFTextParser::parse
virtual void parse(librevenge::RVNGTextInterface *documentInterface)=0
virtual function used to parse the input
STOFFTextParser::STOFFTextParser
STOFFTextParser(STOFFParserStatePtr &state)
constructor using a state
Definition STOFFParser.hxx:203
libstoff::DebugFile
Definition STOFFDebug.hxx:211
STOFFGraphicListenerPtr
std::shared_ptr< STOFFGraphicListener > STOFFGraphicListenerPtr
a smart pointer of STOFFGraphicListener
Definition libstaroffice_internal.hxx:487
STOFFSpreadsheetListenerPtr
std::shared_ptr< STOFFSpreadsheetListener > STOFFSpreadsheetListenerPtr
a smart pointer of STOFFSpreadsheetListener
Definition libstaroffice_internal.hxx:497
STOFFParserStatePtr
std::shared_ptr< STOFFParserState > STOFFParserStatePtr
a smart pointer of STOFFParserState
Definition libstaroffice_internal.hxx:495
STOFFListManagerPtr
std::shared_ptr< STOFFListManager > STOFFListManagerPtr
a smart pointer of STOFFListManager
Definition libstaroffice_internal.hxx:493
STOFFInputStreamPtr
std::shared_ptr< STOFFInputStream > STOFFInputStreamPtr
a smart pointer of STOFFInputStream
Definition libstaroffice_internal.hxx:489
STOFFTextListenerPtr
std::shared_ptr< STOFFTextListener > STOFFTextListenerPtr
a smart pointer of STOFFTextListener
Definition libstaroffice_internal.hxx:501