MWAWParser.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 /* libmwaw
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 MWAW_PARSER_H
35 #define MWAW_PARSER_H
36 
37 #include <ostream>
38 #include <string>
39 #include <vector>
40 
41 #include "MWAWDebug.hxx"
42 #include "MWAWInputStream.hxx"
43 
44 #include "MWAWEntry.hxx"
45 #include "MWAWHeader.hxx"
46 #include "MWAWPageSpan.hxx"
47 
50 {
51 public:
55  MWAWParserState(Type type, MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header);
72 
88  int m_version;
89 
92 
93 private:
94  MWAWParserState(MWAWParserState const &orig) = delete;
95  MWAWParserState &operator=(MWAWParserState const &orig) = delete;
96 };
97 
100 {
101 public:
103  virtual ~MWAWParser();
105  virtual bool checkHeader(MWAWHeader *header, bool strict=false) = 0;
106 
108  int version() const
109  {
110  return m_parserState->m_version;
111  }
114  {
115  return m_parserState;
116  }
119  {
120  return m_parserState->m_header;
121  }
124  {
125  return m_parserState->m_input;
126  }
131  {
132  return m_parserState->m_graphicListener;
133  }
136  {
137  return m_parserState->m_presentationListener;
138  }
141  {
142  return m_parserState->m_spreadsheetListener;
143  }
146  {
147  return m_parserState->m_textListener;
148  }
151  {
152  return m_parserState->m_fontConverter;
153  }
156  {
157  return m_parserState->m_fontManager;
158  }
160  MWAWPageSpan const &getPageSpan() const
161  {
162  return m_parserState->m_pageSpan;
163  }
166  {
167  return m_parserState->m_pageSpan;
168  }
170  double getFormLength() const
171  {
172  return m_parserState->m_pageSpan.getFormLength();
173  }
175  double getFormWidth() const
176  {
177  return m_parserState->m_pageSpan.getFormWidth();
178  }
180  double getPageLength() const
181  {
182  return m_parserState->m_pageSpan.getPageLength();
183  }
185  double getPageWidth() const
186  {
187  return m_parserState->m_pageSpan.getPageWidth();
188  }
191  {
192  return m_parserState->m_rsrcParser;
193  }
196  {
197  return m_parserState->m_asciiFile;
198  }
199 protected:
201  MWAWParser(MWAWParserState::Type type, MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header);
203  explicit MWAWParser(MWAWParserStatePtr const &state) : m_parserState(state), m_asciiName("") { }
204 
206  void setVersion(int vers)
207  {
208  m_parserState->m_version = vers;
209  }
213  void resetGraphicListener();
223  void setTextListener(MWAWTextListenerPtr &listener);
225  void resetTextListener();
227  void setAsciiName(char const *name)
228  {
229  m_asciiName = name;
230  }
232  std::string const &asciiName() const
233  {
234  return m_asciiName;
235  }
236 
237 private:
239  MWAWParser(const MWAWParser &) = delete;
241  MWAWParser &operator=(const MWAWParser &) = delete;
242 
246  std::string m_asciiName;
247 };
248 
251 {
252 public:
254  ~MWAWGraphicParser() override;
256  virtual void parse(librevenge::RVNGDrawingInterface *documentInterface) = 0;
257 protected:
259  MWAWGraphicParser(MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header) : MWAWParser(MWAWParserState::Graphic, input, rsrcParser, header) {}
261  explicit MWAWGraphicParser(MWAWParserStatePtr const &state)
262  : MWAWParser(state) {}
263 };
264 
267 {
268 public:
270  ~MWAWPresentationParser() override;
272  virtual void parse(librevenge::RVNGPresentationInterface *documentInterface) = 0;
273 protected:
275  MWAWPresentationParser(MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header) : MWAWParser(MWAWParserState::Presentation, input, rsrcParser, header) {}
278  : MWAWParser(state) {}
279 };
280 
283 {
284 public:
286  ~MWAWSpreadsheetParser() override;
288  virtual void parse(librevenge::RVNGSpreadsheetInterface *documentInterface) = 0;
289 protected:
291  MWAWSpreadsheetParser(MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header) : MWAWParser(MWAWParserState::Spreadsheet, input, rsrcParser, header) {}
294  : MWAWParser(state) {}
295 };
296 
299 {
300 public:
302  ~MWAWTextParser() override;
304  virtual void parse(librevenge::RVNGTextInterface *documentInterface) = 0;
305 protected:
307  MWAWTextParser(MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header) : MWAWParser(MWAWParserState::Text, input, rsrcParser, header) {}
309  explicit MWAWTextParser(MWAWParserStatePtr const &state)
310  : MWAWParser(state) {}
311 };
312 
313 #endif /* MWAWPARSER_H */
314 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
MWAWTextListenerPtr
std::shared_ptr< MWAWTextListener > MWAWTextListenerPtr
a smart pointer of MWAWTextListener
Definition: libmwaw_internal.hxx:567
MWAWParser::checkHeader
virtual bool checkHeader(MWAWHeader *header, bool strict=false)=0
virtual function used to check if the document header is correct (or not)
MWAWInputStreamPtr
std::shared_ptr< MWAWInputStream > MWAWInputStreamPtr
a smart pointer of MWAWInputStream
Definition: libmwaw_internal.hxx:551
MWAWTextParser
virtual class which defines the ancestor of all text zone parser
Definition: MWAWParser.hxx:299
MWAWSpreadsheetParser
virtual class which defines the ancestor of all spreadsheet zone parser
Definition: MWAWParser.hxx:283
MWAWParser::getFontConverter
MWAWFontConverterPtr & getFontConverter()
returns the font converter
Definition: MWAWParser.hxx:150
MWAWParserState::getMainListener
MWAWListenerPtr getMainListener()
returns the main listener
Definition: MWAWParser.cxx:91
MWAWFontManagerPtr
std::shared_ptr< MWAWFontManager > MWAWFontManagerPtr
a smart pointer of MWAWFontManager
Definition: libmwaw_internal.hxx:547
MWAWGraphicListenerPtr
std::shared_ptr< MWAWGraphicListener > MWAWGraphicListenerPtr
a smart pointer of MWAWGraphicListener
Definition: libmwaw_internal.hxx:549
MWAWFontConverterPtr
std::shared_ptr< MWAWFontConverter > MWAWFontConverterPtr
a smart pointer of MWAWFontConverter
Definition: libmwaw_internal.hxx:543