STOFFParser.hxx Source File documentation

STOFFParser.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
2
3 /* libstaroffice
4 * Version: MPL 2.0 / LGPLv2+
5 *
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 2.0 (the "License"); you may not use this file except in compliance with
8 * the License or as specified alternatively below. You may obtain a copy of
9 * the License at http://www.mozilla.org/MPL/
10 *
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
15 *
16 * Major Contributor(s):
17 * Copyright (C) 2002 William Lachance (wrlach@gmail.com)
18 * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
19 * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
20 * Copyright (C) 2006, 2007 Andrew Ziem
21 * Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
22 *
23 *
24 * All Rights Reserved.
25 *
26 * For minor contributions see the git repository.
27 *
28 * Alternatively, the contents of this file may be used under the terms of
29 * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
30 * in which case the provisions of the LGPLv2+ are applicable
31 * instead of those above.
32 */
33
34 #ifndef STOFF_PARSER_H
35 #define STOFF_PARSER_H
36
37 #include <ostream>
38 #include <string>
39 #include <vector>
40
41 #include "STOFFDebug.hxx"
42 #include "STOFFInputStream.hxx"
43
44 #include "STOFFEntry.hxx"
45 #include "STOFFHeader.hxx"
46 #include "STOFFPageSpan.hxx"
47
49 class STOFFParserState
50 {
51 public:
53 enum Type { Graphic, Presentation, Spreadsheet, Text };
55 STOFFParserState(Type type, STOFFInputStreamPtr input, STOFFHeader *header);
57 ~STOFFParserState();
59 Type m_type;
61 STOFFDocument::Kind m_kind;
63 int m_version;
65 STOFFInputStreamPtr m_input;
67 STOFFHeader *m_header;
69 STOFFPageSpan m_pageSpan;
70
72 STOFFListManagerPtr m_listManager;
74 STOFFGraphicListenerPtr m_graphicListener;
76 STOFFSpreadsheetListenerPtr m_spreadsheetListener;
78 STOFFTextListenerPtr m_textListener;
79
81 libstoff::DebugFile m_asciiFile;
82
83 private:
84 STOFFParserState(STOFFParserState const &orig);
85 STOFFParserState &operator=(STOFFParserState const &orig);
86 };
87
89 class STOFFParser
90 {
91 public:
93 virtual ~STOFFParser();
95 virtual bool checkHeader(STOFFHeader *header, bool strict=false) = 0;
96
98 int version() const
99 {
100 return m_parserState->m_version;
101 }
103 STOFFParserStatePtr getParserState()
104 {
105 return m_parserState;
106 }
108 STOFFHeader *getHeader()
109 {
110 return m_parserState->m_header;
111 }
113 STOFFInputStreamPtr &getInput()
114 {
115 return m_parserState->m_input;
116 }
118 STOFFPageSpan const &getPageSpan() const
119 {
120 return m_parserState->m_pageSpan;
121 }
123 STOFFPageSpan &getPageSpan()
124 {
125 return m_parserState->m_pageSpan;
126 }
128 STOFFGraphicListenerPtr &getGraphicListener()
129 {
130 return m_parserState->m_graphicListener;
131 }
133 STOFFSpreadsheetListenerPtr &getSpreadsheetListener()
134 {
135 return m_parserState->m_spreadsheetListener;
136 }
138 STOFFTextListenerPtr &getTextListener()
139 {
140 return m_parserState->m_textListener;
141 }
143 libstoff::DebugFile &ascii()
144 {
145 return m_parserState->m_asciiFile;
146 }
147 protected:
149 STOFFParser(STOFFParserState::Type type, STOFFInputStreamPtr input, STOFFHeader *header);
151 explicit STOFFParser(STOFFParserStatePtr state) : m_parserState(state), m_asciiName("") { }
152
154 void setVersion(int vers)
155 {
156 m_parserState->m_version = vers;
157 }
159 void setGraphicListener(STOFFGraphicListenerPtr &listener);
161 void resetGraphicListener();
163 void setSpreadsheetListener(STOFFSpreadsheetListenerPtr &listener);
165 void resetSpreadsheetListener();
167 void setTextListener(STOFFTextListenerPtr &listener);
169 void resetTextListener();
171 void setAsciiName(char const *name)
172 {
173 m_asciiName = name;
174 }
176 std::string const &asciiName() const
177 {
178 return m_asciiName;
179 }
180
181 private:
183 STOFFParser(const STOFFParser &);
185 STOFFParser &operator=(const STOFFParser &);
186
188 STOFFParserStatePtr m_parserState;
190 std::string m_asciiName;
191 };
192
194 class STOFFTextParser : public STOFFParser
195 {
196 public:
198 virtual void parse(librevenge::RVNGTextInterface *documentInterface) = 0;
199 protected:
201 STOFFTextParser(STOFFInputStreamPtr input, STOFFHeader *header) : STOFFParser(STOFFParserState::Text, input, header) {}
203 explicit STOFFTextParser(STOFFParserStatePtr state) : STOFFParser(state) {}
205 ~STOFFTextParser() override;
206 };
207
209 class STOFFGraphicParser : public STOFFParser
210 {
211 public:
213 virtual void parse(librevenge::RVNGDrawingInterface *documentInterface);
215 virtual void parse(librevenge::RVNGPresentationInterface *documentInterface);
216 protected:
218 STOFFGraphicParser(STOFFInputStreamPtr input, STOFFHeader *header) : STOFFParser(STOFFParserState::Graphic, input, header) {}
220 explicit STOFFGraphicParser(STOFFParserStatePtr state) : STOFFParser(state) {}
222 ~STOFFGraphicParser() override;
223 };
224
226 class STOFFSpreadsheetParser : public STOFFParser
227 {
228 public:
230 virtual void parse(librevenge::RVNGSpreadsheetInterface *documentInterface) = 0;
231 protected:
233 STOFFSpreadsheetParser(STOFFInputStreamPtr input, STOFFHeader *header) : STOFFParser(STOFFParserState::Spreadsheet, input, header) {}
235 explicit STOFFSpreadsheetParser(STOFFParserStatePtr state) : STOFFParser(state) {}
237 ~STOFFSpreadsheetParser() override;
238 };
239
240 #endif /* STOFFPARSER_H */
241 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
STOFFParserState::Type
Type
the parser state type
Definition: STOFFParser.hxx:53
STOFFParser::getPageSpan
STOFFPageSpan & getPageSpan()
returns the actual page dimension
Definition: STOFFParser.hxx:123
STOFFHeader
a function used by STOFFDocument to store the version of document
Definition: STOFFHeader.hxx:56
STOFFParser::~STOFFParser
virtual ~STOFFParser()
virtual destructor
Definition: STOFFParser.cxx:74
STOFFParser::setTextListener
void setTextListener(STOFFTextListenerPtr &listener)
sets the text listener
Definition: STOFFParser.cxx:100
STOFFParserState::m_pageSpan
STOFFPageSpan m_pageSpan
the actual document size
Definition: STOFFParser.hxx:69
STOFFGraphicParser::STOFFGraphicParser
STOFFGraphicParser(STOFFInputStreamPtr input, STOFFHeader *header)
constructor (protected)
Definition: STOFFParser.hxx:218
STOFFTextListenerPtr
std::shared_ptr< STOFFTextListener > STOFFTextListenerPtr
a smart pointer of STOFFTextListener
Definition: libstaroffice_internal.hxx:496
libstoff::DebugFile
Definition: STOFFDebug.hxx:210
STOFFDebug.hxx
STOFFGraphicParser::STOFFGraphicParser
STOFFGraphicParser(STOFFParserStatePtr state)
constructor using a state
Definition: STOFFParser.hxx:220
STOFFTextParser::STOFFTextParser
STOFFTextParser(STOFFParserStatePtr state)
constructor using a state
Definition: STOFFParser.hxx:203
STOFFParserState::m_header
STOFFHeader * m_header
the header
Definition: STOFFParser.hxx:67
STOFFGraphicParser::parse
virtual void parse(librevenge::RVNGDrawingInterface *documentInterface)
virtual function used to parse the input
Definition: STOFFParser.cxx:115
STOFFParser::m_parserState
STOFFParserStatePtr m_parserState
the parser state
Definition: STOFFParser.hxx:188
STOFFParserState::Presentation
Definition: STOFFParser.hxx:53
STOFFInputStreamPtr
std::shared_ptr< STOFFInputStream > STOFFInputStreamPtr
a smart pointer of STOFFInputStream
Definition: libstaroffice_internal.hxx:484
STOFFGraphicParser
virtual class which defines the ancestor of all graphic/presentation zone parser
Definition: STOFFParser.hxx:209
STOFFParserState::m_graphicListener
STOFFGraphicListenerPtr m_graphicListener
the graphic listener
Definition: STOFFParser.hxx:74
STOFFParserState::m_spreadsheetListener
STOFFSpreadsheetListenerPtr m_spreadsheetListener
the spreadsheet listener
Definition: STOFFParser.hxx:76
STOFFParserState
a class to define the parser state
Definition: STOFFParser.hxx:49
STOFFParserState::operator=
STOFFParserState & operator=(STOFFParserState const &orig)
STOFFParser::m_asciiName
std::string m_asciiName
the debug file name
Definition: STOFFParser.hxx:190
STOFFParserStatePtr
std::shared_ptr< STOFFParserState > STOFFParserStatePtr
a smart pointer of STOFFParserState
Definition: libstaroffice_internal.hxx:490
STOFFParser::ascii
libstoff::DebugFile & ascii()
a DebugFile used to write what we recognize when we parse the document
Definition: STOFFParser.hxx:143
STOFFHeader.hxx
Defines STOFFHeader (document&#39;s type, version, kind)
STOFFTextParser::parse
virtual void parse(librevenge::RVNGTextInterface *documentInterface)=0
virtual function used to parse the input
STOFFParser::resetTextListener
void resetTextListener()
resets the text listener
Definition: STOFFParser.cxx:105
STOFFParser::resetGraphicListener
void resetGraphicListener()
resets the graphic listener
Definition: STOFFParser.cxx:83
STOFFParserState::Graphic
Definition: STOFFParser.hxx:53
STOFFParser::getPageSpan
STOFFPageSpan const & getPageSpan() const
returns the actual page dimension
Definition: STOFFParser.hxx:118
STOFFSpreadsheetListenerPtr
std::shared_ptr< STOFFSpreadsheetListener > STOFFSpreadsheetListenerPtr
a smart pointer of STOFFSpreadsheetListener
Definition: libstaroffice_internal.hxx:492
STOFFParser::setAsciiName
void setAsciiName(char const *name)
Debugging: change the default ascii file.
Definition: STOFFParser.hxx:171
STOFFParser::STOFFParser
STOFFParser(STOFFParserStatePtr state)
constructor using a state
Definition: STOFFParser.hxx:151
STOFFTextParser::STOFFTextParser
STOFFTextParser(STOFFInputStreamPtr input, STOFFHeader *header)
constructor (protected)
Definition: STOFFParser.hxx:201
STOFFEntry.hxx
STOFFParser::checkHeader
virtual bool checkHeader(STOFFHeader *header, bool strict=false)=0
virtual function used to check if the document header is correct (or not)
STOFFSpreadsheetParser::STOFFSpreadsheetParser
STOFFSpreadsheetParser(STOFFInputStreamPtr input, STOFFHeader *header)
constructor (protected)
Definition: STOFFParser.hxx:233
STOFFParserState::m_asciiFile
libstoff::DebugFile m_asciiFile
the debug file
Definition: STOFFParser.hxx:81
STOFFPageSpan.hxx
STOFFParser::operator=
STOFFParser & operator=(const STOFFParser &)
private operator=: forbidden
STOFFTextParser
virtual class which defines the ancestor of all text zone parser
Definition: STOFFParser.hxx:194
STOFFParser::getParserState
STOFFParserStatePtr getParserState()
returns the parser state
Definition: STOFFParser.hxx:103
STOFFParser::getHeader
STOFFHeader * getHeader()
returns the header
Definition: STOFFParser.hxx:108
STOFFTextParser::~STOFFTextParser
~STOFFTextParser() override
destructor
Definition: STOFFParser.cxx:129
STOFFParser::setGraphicListener
void setGraphicListener(STOFFGraphicListenerPtr &listener)
sets the graphic listener
Definition: STOFFParser.cxx:78
STOFFSpreadsheetParser::parse
virtual void parse(librevenge::RVNGSpreadsheetInterface *documentInterface)=0
virtual function used to parse the input
STOFFParserState::Text
Definition: STOFFParser.hxx:53
STOFFParser::resetSpreadsheetListener
void resetSpreadsheetListener()
resets the spreadsheet listener
Definition: STOFFParser.cxx:94
STOFFParser::setVersion
void setVersion(int vers)
sets the document&#39;s version
Definition: STOFFParser.hxx:154
STOFFInputStream.hxx
STOFFGraphicListenerPtr
std::shared_ptr< STOFFGraphicListener > STOFFGraphicListenerPtr
a smart pointer of STOFFGraphicListener
Definition: libstaroffice_internal.hxx:480
STOFFParserState::STOFFParserState
STOFFParserState(Type type, STOFFInputStreamPtr input, STOFFHeader *header)
Constructor.
Definition: STOFFParser.cxx:43
STOFFParser::version
int version() const
returns the works version
Definition: STOFFParser.hxx:98
STOFFParserState::m_listManager
STOFFListManagerPtr m_listManager
the list manager
Definition: STOFFParser.hxx:72
STOFFParserState::Spreadsheet
Definition: STOFFParser.hxx:53
STOFFParserState::m_textListener
STOFFTextListenerPtr m_textListener
the text listener
Definition: STOFFParser.hxx:78
STOFFGraphicParser::~STOFFGraphicParser
~STOFFGraphicParser() override
destructor
Definition: STOFFParser.cxx:111
STOFFParserState::m_type
Type m_type
the state type
Definition: STOFFParser.hxx:59
STOFFDocument::Kind
Kind
an enum to define the kind of document
Definition: STOFFDocument.hxx:66
STOFFParserState::m_version
int m_version
the actual version
Definition: STOFFParser.hxx:63
STOFFParser::getInput
STOFFInputStreamPtr & getInput()
returns the actual input
Definition: STOFFParser.hxx:113
STOFFParser::getSpreadsheetListener
STOFFSpreadsheetListenerPtr & getSpreadsheetListener()
returns the spreadsheet listener
Definition: STOFFParser.hxx:133
STOFFSpreadsheetParser::STOFFSpreadsheetParser
STOFFSpreadsheetParser(STOFFParserStatePtr state)
constructor using a state
Definition: STOFFParser.hxx:235
STOFFParser::getGraphicListener
STOFFGraphicListenerPtr & getGraphicListener()
returns the graphic listener
Definition: STOFFParser.hxx:128
STOFFPageSpan
A class which defines the page properties.
Definition: STOFFPageSpan.hxx:75
STOFFParserState::~STOFFParserState
~STOFFParserState()
destructor
Definition: STOFFParser.cxx:63
STOFFParser::setSpreadsheetListener
void setSpreadsheetListener(STOFFSpreadsheetListenerPtr &listener)
sets the spreadsheet listener
Definition: STOFFParser.cxx:89
STOFFSpreadsheetParser
virtual class which defines the ancestor of all spreadsheet zone parser
Definition: STOFFParser.hxx:226
STOFFListManagerPtr
std::shared_ptr< STOFFListManager > STOFFListManagerPtr
a smart pointer of STOFFListManager
Definition: libstaroffice_internal.hxx:488
STOFFParser::asciiName
std::string const & asciiName() const
return the ascii file name
Definition: STOFFParser.hxx:176
STOFFParser::getTextListener
STOFFTextListenerPtr & getTextListener()
returns the text listener
Definition: STOFFParser.hxx:138
STOFFParser
virtual class which defines the ancestor of all main zone parser
Definition: STOFFParser.hxx:89
STOFFParserState::m_input
STOFFInputStreamPtr m_input
the input
Definition: STOFFParser.hxx:65
STOFFSpreadsheetParser::~STOFFSpreadsheetParser
~STOFFSpreadsheetParser() override
destructor
Definition: STOFFParser.cxx:125
STOFFParser::STOFFParser
STOFFParser(STOFFParserState::Type type, STOFFInputStreamPtr input, STOFFHeader *header)
constructor (protected)
Definition: STOFFParser.cxx:67
STOFFParserState::m_kind
STOFFDocument::Kind m_kind
the document kind
Definition: STOFFParser.hxx:61