Coverage Report

Created: 2026-03-12 06:42

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libstaroffice/src/lib/STOFFParser.hxx
Line
Count
Source
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
48
/** a class to define the parser state */
49
class STOFFParserState
50
{
51
public:
52
  //! the parser state type
53
  enum Type { Graphic, Presentation, Spreadsheet, Text };
54
  //! Constructor
55
  STOFFParserState(Type type, STOFFInputStreamPtr &input, STOFFHeader *header);
56
  //! destructor
57
  ~STOFFParserState();
58
  //! the state type
59
  Type m_type;
60
  //! the document kind
61
  STOFFDocument::Kind m_kind;
62
  //! the actual version
63
  int m_version;
64
  //! the input
65
  STOFFInputStreamPtr m_input;
66
  //! the header
67
  STOFFHeader *m_header;
68
  //! the actual document size
69
  STOFFPageSpan m_pageSpan;
70
71
  //! the list manager
72
  STOFFListManagerPtr m_listManager;
73
  //! the graphic listener
74
  STOFFGraphicListenerPtr m_graphicListener;
75
  //! the spreadsheet listener
76
  STOFFSpreadsheetListenerPtr m_spreadsheetListener;
77
  //! the text listener
78
  STOFFTextListenerPtr m_textListener;
79
80
  //! the debug file
81
  libstoff::DebugFile m_asciiFile;
82
83
private:
84
  STOFFParserState(STOFFParserState const &orig);
85
  STOFFParserState &operator=(STOFFParserState const &orig);
86
};
87
88
/** virtual class which defines the ancestor of all main zone parser */
89
class STOFFParser
90
{
91
public:
92
  //! virtual destructor
93
  virtual ~STOFFParser();
94
  //! virtual function used to check if the document header is correct (or not)
95
  virtual bool checkHeader(STOFFHeader *header, bool strict=false) = 0;
96
97
  //! returns the works version
98
  int version() const
99
0
  {
100
0
    return m_parserState->m_version;
101
0
  }
102
  //! returns the parser state
103
  STOFFParserStatePtr getParserState()
104
44.2k
  {
105
44.2k
    return m_parserState;
106
44.2k
  }
107
  //! returns the header
108
  STOFFHeader *getHeader()
109
0
  {
110
0
    return m_parserState->m_header;
111
0
  }
112
  //! returns the actual input
113
  STOFFInputStreamPtr &getInput()
114
235k
  {
115
235k
    return m_parserState->m_input;
116
235k
  }
117
  //! returns the actual page dimension
118
  STOFFPageSpan const &getPageSpan() const
119
0
  {
120
0
    return m_parserState->m_pageSpan;
121
0
  }
122
  //! returns the actual page dimension
123
  STOFFPageSpan &getPageSpan()
124
19.0k
  {
125
19.0k
    return m_parserState->m_pageSpan;
126
19.0k
  }
127
  //! returns the graphic listener
128
  STOFFGraphicListenerPtr &getGraphicListener()
129
57.2k
  {
130
57.2k
    return m_parserState->m_graphicListener;
131
57.2k
  }
132
  //! returns the spreadsheet listener
133
  STOFFSpreadsheetListenerPtr &getSpreadsheetListener()
134
21.5k
  {
135
21.5k
    return m_parserState->m_spreadsheetListener;
136
21.5k
  }
137
  //! returns the text listener
138
  STOFFTextListenerPtr &getTextListener()
139
56.7k
  {
140
56.7k
    return m_parserState->m_textListener;
141
56.7k
  }
142
  //! a DebugFile used to write what we recognize when we parse the document
143
  libstoff::DebugFile &ascii()
144
47.0k
  {
145
47.0k
    return m_parserState->m_asciiFile;
146
47.0k
  }
147
protected:
148
  //! constructor (protected)
149
  STOFFParser(STOFFParserState::Type type, STOFFInputStreamPtr input, STOFFHeader *header);
150
  //! constructor using a state
151
0
  explicit STOFFParser(STOFFParserStatePtr &state) : m_parserState(state), m_asciiName("") { }
152
153
  //! sets the document's version
154
  void setVersion(int vers)
155
0
  {
156
0
    m_parserState->m_version = vers;
157
0
  }
158
  //! sets the graphic listener
159
  void setGraphicListener(STOFFGraphicListenerPtr &listener);
160
  //! resets the graphic listener
161
  void resetGraphicListener();
162
  //! sets the spreadsheet listener
163
  void setSpreadsheetListener(STOFFSpreadsheetListenerPtr &listener);
164
  //! resets the spreadsheet listener
165
  void resetSpreadsheetListener();
166
  //! sets the text listener
167
  void setTextListener(STOFFTextListenerPtr &listener);
168
  //! resets the text listener
169
  void resetTextListener();
170
  //! Debugging: change the default ascii file
171
  void setAsciiName(char const *name)
172
0
  {
173
0
    m_asciiName = name;
174
0
  }
175
  //! return the ascii file name
176
  std::string const &asciiName() const
177
0
  {
178
0
    return m_asciiName;
179
0
  }
180
181
private:
182
  //! private copy constructor: forbidden
183
  STOFFParser(const STOFFParser &);
184
  //! private operator=: forbidden
185
  STOFFParser &operator=(const STOFFParser &);
186
187
  //! the parser state
188
  STOFFParserStatePtr m_parserState;
189
  //! the debug file name
190
  std::string m_asciiName;
191
};
192
193
/** virtual class which defines the ancestor of all text zone parser */
194
class STOFFTextParser : public STOFFParser
195
{
196
public:
197
  //! virtual function used to parse the input
198
  virtual void parse(librevenge::RVNGTextInterface *documentInterface) = 0;
199
protected:
200
  //! constructor (protected)
201
38.0k
  STOFFTextParser(STOFFInputStreamPtr &input, STOFFHeader *header) : STOFFParser(STOFFParserState::Text, input, header) {}
202
  //! constructor using a state
203
0
  explicit STOFFTextParser(STOFFParserStatePtr &state) : STOFFParser(state) {}
204
  //! destructor
205
  ~STOFFTextParser() override;
206
};
207
208
/** virtual class which defines the ancestor of all graphic/presentation zone parser */
209
class STOFFGraphicParser : public STOFFParser
210
{
211
public:
212
  //! virtual function used to parse the input
213
  virtual void parse(librevenge::RVNGDrawingInterface *documentInterface);
214
  //! virtual function used to parse the input
215
  virtual void parse(librevenge::RVNGPresentationInterface *documentInterface);
216
protected:
217
  //! constructor (protected)
218
42.1k
  STOFFGraphicParser(STOFFInputStreamPtr &input, STOFFHeader *header) : STOFFParser(STOFFParserState::Graphic, input, header) {}
219
  //! constructor using a state
220
0
  explicit STOFFGraphicParser(STOFFParserStatePtr &state) : STOFFParser(state) {}
221
  //! destructor
222
  ~STOFFGraphicParser() override;
223
};
224
225
/** virtual class which defines the ancestor of all spreadsheet zone parser */
226
class STOFFSpreadsheetParser : public STOFFParser
227
{
228
public:
229
  //! virtual function used to parse the input
230
  virtual void parse(librevenge::RVNGSpreadsheetInterface *documentInterface) = 0;
231
protected:
232
  //! constructor (protected)
233
14.4k
  STOFFSpreadsheetParser(STOFFInputStreamPtr &input, STOFFHeader *header) : STOFFParser(STOFFParserState::Spreadsheet, input, header) {}
234
  //! constructor using a state
235
0
  explicit STOFFSpreadsheetParser(STOFFParserStatePtr &state) : STOFFParser(state) {}
236
  //! destructor
237
  ~STOFFSpreadsheetParser() override;
238
};
239
240
#endif /* STOFFPARSER_H */
241
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: