- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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;
77
79 libstoff::DebugFile m_asciiFile;
80
81 private:
82 STOFFParserState(STOFFParserState const &orig);
83 STOFFParserState &operator=(STOFFParserState const &orig);
84 };
85
87 class STOFFParser
88 {
89 public:
91 virtual ~STOFFParser();
93 virtual bool checkHeader(STOFFHeader *header, bool strict=false) = 0;
94
96 int version() const
97 {
98 return m_parserState->m_version;
99 }
101 STOFFParserStatePtr getParserState()
102 {
103 return m_parserState;
104 }
106 STOFFHeader *getHeader()
107 {
108 return m_parserState->m_header;
109 }
111 STOFFInputStreamPtr &getInput()
112 {
113 return m_parserState->m_input;
114 }
116 STOFFPageSpan const &getPageSpan() const
117 {
118 return m_parserState->m_pageSpan;
119 }
121 STOFFPageSpan &getPageSpan()
122 {
123 return m_parserState->m_pageSpan;
124 }
126 STOFFGraphicListenerPtr &getGraphicListener()
127 {
128 return m_parserState->m_graphicListener;
129 }
131 STOFFSpreadsheetListenerPtr &getSpreadsheetListener()
132 {
133 return m_parserState->m_spreadsheetListener;
134 }
136 libstoff::DebugFile &ascii()
137 {
138 return m_parserState->m_asciiFile;
139 }
140 protected:
142 STOFFParser(STOFFParserState::Type type, STOFFInputStreamPtr input, STOFFHeader *header);
144 explicit STOFFParser(STOFFParserStatePtr state) : m_parserState(state), m_asciiName("") { }
145
147 void setVersion(int vers)
148 {
149 m_parserState->m_version = vers;
150 }
152 void setGraphicListener(STOFFGraphicListenerPtr &listener);
154 void resetGraphicListener();
156 void setSpreadsheetListener(STOFFSpreadsheetListenerPtr &listener);
158 void resetSpreadsheetListener();
160 void setAsciiName(char const *name)
161 {
162 m_asciiName = name;
163 }
165 std::string const &asciiName() const
166 {
167 return m_asciiName;
168 }
169
170 private:
172 STOFFParser(const STOFFParser &);
174 STOFFParser &operator=(const STOFFParser &);
175
177 STOFFParserStatePtr m_parserState;
179 std::string m_asciiName;
180 };
181
183 class STOFFTextParser : public STOFFParser
184 {
185 public:
187 virtual void parse(librevenge::RVNGTextInterface *documentInterface) = 0;
188 protected:
190 STOFFTextParser(STOFFInputStreamPtr input, STOFFHeader *header) : STOFFParser(STOFFParserState::Text, input, header) {}
192 explicit STOFFTextParser(STOFFParserStatePtr state) : STOFFParser(state) {}
193 };
194
196 class STOFFGraphicParser : public STOFFParser
197 {
198 public:
200 virtual void parse(librevenge::RVNGDrawingInterface *documentInterface) = 0;
201 protected:
203 STOFFGraphicParser(STOFFInputStreamPtr input, STOFFHeader *header) : STOFFParser(STOFFParserState::Graphic, input, header) {}
205 explicit STOFFGraphicParser(STOFFParserStatePtr state) : STOFFParser(state) {}
206 };
207
209 class STOFFSpreadsheetParser : public STOFFParser
210 {
211 public:
213 virtual void parse(librevenge::RVNGSpreadsheetInterface *documentInterface) = 0;
214 protected:
216 STOFFSpreadsheetParser(STOFFInputStreamPtr input, STOFFHeader *header) : STOFFParser(STOFFParserState::Spreadsheet, input, header) {}
218 explicit STOFFSpreadsheetParser(STOFFParserStatePtr state) : STOFFParser(state) {}
219 };
220
221 #endif /* STOFFPARSER_H */
222 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
STOFFParserState::Type
Type
the parser state type
Definition: STOFFParser.hxx:53
STOFFDocumentInternal::checkHeader
bool checkHeader(STOFFInputStreamPtr &input, STOFFHeader &header, bool strict)
Wrapper to check a basic header of a mac file.
Definition: STOFFDocument.cxx:377
STOFFParser::getPageSpan
STOFFPageSpan & getPageSpan()
returns the actual page dimension
Definition: STOFFParser.hxx:121
STOFFPageSpan::m_pageSpan
int m_pageSpan
the number of page
Definition: STOFFPageSpan.hxx:103
STOFFInputStreamPtr
shared_ptr< STOFFInputStream > STOFFInputStreamPtr
a smart pointer of STOFFInputStream
Definition: libstaroffice_internal.hxx:482
STOFFHeader
a function used by STOFFDocument to store the version of document
Definition: STOFFHeader.hxx:56
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:203
libstoff::DebugFile
Definition: STOFFDebug.hxx:198
STOFFDebug.hxx
STOFFGraphicParser::STOFFGraphicParser
STOFFGraphicParser(STOFFParserStatePtr state)
constructor using a state
Definition: STOFFParser.hxx:205
STOFFTextParser::STOFFTextParser
STOFFTextParser(STOFFParserStatePtr state)
constructor using a state
Definition: STOFFParser.hxx:192
STOFFSpreadsheetListenerPtr
shared_ptr< STOFFSpreadsheetListener > STOFFSpreadsheetListenerPtr
a smart pointer of STOFFSpreadsheetListener
Definition: libstaroffice_internal.hxx:490
STOFFParserState::m_header
STOFFHeader * m_header
the header
Definition: STOFFParser.hxx:67
STOFFParser::m_parserState
STOFFParserStatePtr m_parserState
the parser state
Definition: STOFFParser.hxx:177
STOFFParserState::Presentation
Definition: STOFFParser.hxx:53
STOFFGraphicParser
virtual class which defines the ancestor of all graphic zone parser
Definition: STOFFParser.hxx:196
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:179
STOFFParser::ascii
libstoff::DebugFile & ascii()
a DebugFile used to write what we recognize when we parse the document
Definition: STOFFParser.hxx:136
STOFFHeader.hxx
Defines STOFFHeader (document&#39;s type, version, kind)
STOFFParserState::Graphic
Definition: STOFFParser.hxx:53
STOFFParser::setAsciiName
void setAsciiName(char const *name)
Debugging: change the default ascii file.
Definition: STOFFParser.hxx:160
STOFFListManagerPtr
shared_ptr< STOFFListManager > STOFFListManagerPtr
a smart pointer of STOFFListManager
Definition: libstaroffice_internal.hxx:486
STOFFParser::STOFFParser
STOFFParser(STOFFParserStatePtr state)
constructor using a state
Definition: STOFFParser.hxx:144
STOFFTextParser::STOFFTextParser
STOFFTextParser(STOFFInputStreamPtr input, STOFFHeader *header)
constructor (protected)
Definition: STOFFParser.hxx:190
STOFFEntry.hxx
STOFFSpreadsheetParser::STOFFSpreadsheetParser
STOFFSpreadsheetParser(STOFFInputStreamPtr input, STOFFHeader *header)
constructor (protected)
Definition: STOFFParser.hxx:216
STOFFParserState::m_asciiFile
libstoff::DebugFile m_asciiFile
the debug file
Definition: STOFFParser.hxx:79
STOFFPageSpan.hxx
STOFFTextParser
virtual class which defines the ancestor of all text zone parser
Definition: STOFFParser.hxx:183
STOFFParser::getParserState
STOFFParserStatePtr getParserState()
returns the parser state
Definition: STOFFParser.hxx:101
STOFFParser::getHeader
STOFFHeader * getHeader()
returns the header
Definition: STOFFParser.hxx:106
STOFFParser::version
int version() const
returns the works version
Definition: STOFFParser.hxx:96
STOFFParserState::Text
Definition: STOFFParser.hxx:53
STOFFParser::setVersion
void setVersion(int vers)
sets the document&#39;s version
Definition: STOFFParser.hxx:147
STOFFInputStream.hxx
STOFFParserState::STOFFParserState
STOFFParserState(Type type, STOFFInputStreamPtr input, STOFFHeader *header)
Constructor.
Definition: STOFFParser.cxx:42
STOFFParserState::m_listManager
STOFFListManagerPtr m_listManager
the list manager
Definition: STOFFParser.hxx:72
STOFFParserState::Spreadsheet
Definition: STOFFParser.hxx:53
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:111
STOFFParserStatePtr
shared_ptr< STOFFParserState > STOFFParserStatePtr
a smart pointer of STOFFParserState
Definition: libstaroffice_internal.hxx:488
STOFFParser::getSpreadsheetListener
STOFFSpreadsheetListenerPtr & getSpreadsheetListener()
returns the spreadsheet listener
Definition: STOFFParser.hxx:131
STOFFGraphicListenerPtr
shared_ptr< STOFFGraphicListener > STOFFGraphicListenerPtr
a smart pointer of STOFFGraphicListener
Definition: libstaroffice_internal.hxx:478
STOFFSpreadsheetParser::STOFFSpreadsheetParser
STOFFSpreadsheetParser(STOFFParserStatePtr state)
constructor using a state
Definition: STOFFParser.hxx:218
STOFFParser::getGraphicListener
STOFFGraphicListenerPtr & getGraphicListener()
returns the graphic listener
Definition: STOFFParser.hxx:126
STOFFPageSpan
A class which defines the page properties.
Definition: STOFFPageSpan.hxx:74
STOFFParserState::~STOFFParserState
~STOFFParserState()
destructor
Definition: STOFFParser.cxx:54
STOFFSpreadsheetParser
virtual class which defines the ancestor of all spreadsheet zone parser
Definition: STOFFParser.hxx:209
STOFFParser::getPageSpan
STOFFPageSpan const & getPageSpan() const
returns the actual page dimension
Definition: STOFFParser.hxx:116
STOFFParser
virtual class which defines the ancestor of all main zone parser
Definition: STOFFParser.hxx:87
STOFFParserState::m_input
STOFFInputStreamPtr m_input
the input
Definition: STOFFParser.hxx:65
STOFFParser::asciiName
std::string const & asciiName() const
return the ascii file name
Definition: STOFFParser.hxx:165
STOFFParserState::m_kind
STOFFDocument::Kind m_kind
the document kind
Definition: STOFFParser.hxx:61