Reader.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) Jürgen Riegel          (juergen.riegel@web.de)          *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 #ifndef BASE_READER_H
00024 #define BASE_READER_H
00025 
00026 
00027 #include <string>
00028 #include <map>
00029 
00030 #include <xercesc/framework/XMLPScanToken.hpp>
00031 #include <xercesc/sax2/Attributes.hpp>
00032 #include <xercesc/sax2/DefaultHandler.hpp>
00033 
00034 #include "FileInfo.h"
00035 #include "Writer.h"
00036 
00037 namespace zipios {
00038 class ZipInputStream;
00039 }
00040 
00041 XERCES_CPP_NAMESPACE_BEGIN
00042     class DefaultHandler;
00043     class SAX2XMLReader;
00044 XERCES_CPP_NAMESPACE_END
00045 
00046 namespace Base
00047 {
00048 
00049 
00115 class BaseExport XMLReader : public XERCES_CPP_NAMESPACE_QUALIFIER DefaultHandler
00116 {
00117 public:
00119     XMLReader(const char* FileName, std::istream&);
00120     ~XMLReader();
00121 
00122     bool isValid() const { return _valid; }
00123 
00126 
00127     const char* localName(void) const;
00129     void readElement   (const char* ElementName=0);
00131     void readEndElement(const char* ElementName=0);
00133     void readCharacters(void);
00135 
00138 
00139     unsigned int getAttributeCount(void) const;
00141     bool hasAttribute(const char* AttrName) const;
00143     long getAttributeAsInteger(const char* AttrName) const;
00144     unsigned long getAttributeAsUnsigned(const char* AttrName) const;
00146     double getAttributeAsFloat(const char* AttrName) const;
00148     const char* getAttribute(const char* AttrName) const;
00150 
00153 
00154     const char *addFile(const char* Name, Base::Persistence *Object);
00156     void readFiles(zipios::ZipInputStream &zipstream) const;
00158     const std::vector<std::string>& getFilenames() const;
00159     bool isRegistered(Base::Persistence *Object) const;
00161 
00163     int DocumentSchema;
00164 
00165 protected:
00167     bool read(void);
00168 
00169     // -----------------------------------------------------------------------
00170     //  Handlers for the SAX ContentHandler interface
00171     // -----------------------------------------------------------------------
00172     virtual void startElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname, const XERCES_CPP_NAMESPACE_QUALIFIER Attributes& attrs);
00173     virtual void endElement  (const XMLCh* const uri, const XMLCh *const localname, const XMLCh *const qname);
00174     virtual void characters  (const XMLCh* const chars, const unsigned int length);
00175     virtual void ignorableWhitespace(const XMLCh* const chars, const unsigned int length);
00176     virtual void resetDocument();
00177 
00178 
00179     // -----------------------------------------------------------------------
00180     //  Handlers for the SAX ErrorHandler interface
00181     // -----------------------------------------------------------------------
00182     void warning(const XERCES_CPP_NAMESPACE_QUALIFIER SAXParseException& exc);
00183     void error(const XERCES_CPP_NAMESPACE_QUALIFIER SAXParseException& exc);
00184     void fatalError(const XERCES_CPP_NAMESPACE_QUALIFIER SAXParseException& exc);
00185     void resetErrors();
00186 
00187 
00188     int Level;
00189     std::string LocalName;
00190     std::string Characters;
00191     unsigned int CharacterCount;
00192 
00193     std::map<std::string,std::string> AttrMap;
00194     typedef std::map<std::string,std::string> AttrMapType;
00195 
00196     enum {
00197         None = 0,
00198         Chars,
00199         StartElement,
00200         StartEndElement,
00201         EndElement
00202     }   ReadType;
00203 
00204 
00205     FileInfo _File;
00206     XERCES_CPP_NAMESPACE_QUALIFIER SAX2XMLReader* parser;
00207     XERCES_CPP_NAMESPACE_QUALIFIER XMLPScanToken token;
00208     bool _valid;
00209 
00210     struct FileEntry {
00211         std::string FileName;
00212         Base::Persistence *Object;
00213     };
00214     std::vector<FileEntry> FileList;
00215     std::vector<std::string> FileNames;
00216 };
00217 
00218 }
00219 
00220 
00221 #endif

Generated on Wed Nov 23 19:00:35 2011 for FreeCAD by  doxygen 1.6.1