PDXParser.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* libe-book
00003  * Version: MPL 2.0 / LGPLv2.1+
00004  *
00005  * This Source Code Form is subject to the terms of the Mozilla Public
00006  * License, v. 2.0. If a copy of the MPL was not distributed with this
00007  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
00008  *
00009  * Alternatively, the contents of this file may be used under the terms
00010  * of the GNU Lesser General Public License Version 2.1 or later
00011  * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
00012  * applicable instead of those above.
00013  *
00014  * For further information visit http://libebook.sourceforge.net
00015  */
00016 
00017 #ifndef PDXPARSER_H_INCLUDED
00018 #define PDXPARSER_H_INCLUDED
00019 
00020 #include <boost/scoped_ptr.hpp>
00021 
00022 class WPXDocumentInterface;
00023 class WPXInputStream;
00024 
00025 #define PDX_CODE(s) ((s[0] << 24) | (s[1] << 16) | (s[2] << 8) | s[3])
00026 
00027 namespace libebook
00028 {
00029 
00030 struct PDXParserImpl;
00031 
00032 class PDXParser
00033 {
00034 // disable copying
00035   PDXParser(const PDXParser &other);
00036   PDXParser &operator=(const PDXParser &other);
00037 
00038 public:
00039   virtual ~PDXParser() = 0;
00040 
00048   bool isSupported();
00049 
00054   bool parse();
00055 
00056 protected:
00062   PDXParser(WPXInputStream *input, WPXDocumentInterface *document);
00063 
00068   WPXDocumentInterface *getDocument() const;
00069 
00070   const char *getName() const;
00071 
00080   WPXInputStream *getAppInfoRecord() const;
00081 
00089   WPXInputStream *getIndexRecord() const;
00090 
00095   unsigned getDataRecordCount() const;
00096 
00102   WPXInputStream *getDataRecord(unsigned n) const;
00103 
00108   WPXInputStream *getDataRecords() const;
00109 
00117   WPXInputStream *getDataRecords(unsigned first, unsigned last) const;
00118 
00119 private:
00127   virtual bool isFormatSupported(unsigned type, unsigned creator) = 0;
00128 
00129   virtual void readAppInfoRecord(WPXInputStream *record) = 0;
00130   virtual void readSortInfoRecord(WPXInputStream *record) = 0;
00131   virtual void readIndexRecord(WPXInputStream *record) = 0;
00132   virtual void readDataRecord(WPXInputStream *record, bool last = false) = 0;
00133 
00134   virtual void readDataRecords();
00135 
00136   void readHeader();
00137 
00138   WPXInputStream *getRecordStream(unsigned n) const;
00139 
00140 private:
00141   boost::scoped_ptr<PDXParserImpl> m_impl;
00142 };
00143 
00144 }
00145 
00146 #endif // PDXPARSER_H_INCLUDED
00147 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */