Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

CEGUITinyXMLParser.cpp

Go to the documentation of this file.
00001 /************************************************************************
00002     filename:   CEGUITinyXMLParser.cpp
00003     created:    Sun Mar 13 2005
00004     author:     Paul D Turner
00005 *************************************************************************/
00006 /*************************************************************************
00007     Crazy Eddie's GUI System (http://www.cegui.org.uk)
00008     Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
00009  
00010     This library is free software; you can redistribute it and/or
00011     modify it under the terms of the GNU Lesser General Public
00012     License as published by the Free Software Foundation; either
00013     version 2.1 of the License, or (at your option) any later version.
00014  
00015     This library is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018     Lesser General Public License for more details.
00019  
00020     You should have received a copy of the GNU Lesser General Public
00021     License along with this library; if not, write to the Free Software
00022     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023 *************************************************************************/
00024 #include "CEGUITinyXMLParser.h"
00025 #include "CEGUIResourceProvider.h"
00026 #include "CEGUISystem.h"
00027 #include "CEGUIXMLHandler.h"
00028 #include "CEGUIXMLAttributes.h"
00029 #include "CEGUILogger.h"
00030 #include "tinyxml/tinyxml.h"
00031 
00032 // Start of CEGUI namespace section
00033 namespace CEGUI
00034 {
00035     class TinyXMLDocument : public TiXmlDocument
00036     {
00037     public:
00038         TinyXMLDocument(XMLHandler& handler, const String& filename, const String& schemaName, const String& resourceGroup);
00039         ~TinyXMLDocument()
00040         {}
00041     protected:
00042         void processElement(const TiXmlElement* element);
00043 
00044     private:
00045         XMLHandler* d_handler;
00046     };
00047 
00048     TinyXMLDocument::TinyXMLDocument(XMLHandler& handler, const String& filename, const String& schemaName, const String& resourceGroup)
00049     {
00050         d_handler = &handler;
00051 
00052         // use resource provider to load file data
00053         // TODO: Fix null termination issue.
00054         RawDataContainer rawXMLData;
00055         System::getSingleton().getResourceProvider()->loadRawDataContainer(filename, rawXMLData, resourceGroup);
00056 
00057         TiXmlDocument doc;
00058         doc.Parse((const char*)rawXMLData.getDataPtr());
00059 
00060         const TiXmlElement* currElement = doc.RootElement();
00061 
00062         if (currElement)
00063         {
00064             // function called recursively to parse xml data
00065             processElement(currElement);
00066         }
00067 
00068         System::getSingleton().getResourceProvider()->unloadRawDataContainer(rawXMLData);
00069     }
00070 
00071     void TinyXMLDocument::processElement(const TiXmlElement* element)
00072     {
00073         // build attributes block for the element
00074         XMLAttributes attrs;
00075         const TiXmlAttribute *currAttr = element->FirstAttribute();
00076 
00077         while (currAttr)
00078         {
00079             attrs.add((utf8*)currAttr->Name(), (utf8*)currAttr->Value());
00080             currAttr = currAttr->Next();
00081         }
00082 
00083         // start element
00084         d_handler->elementStart((utf8*)element->Value(), attrs);
00085 
00086         // do children
00087         const TiXmlElement* childElement = element->FirstChildElement();
00088 
00089         while (childElement)
00090         {
00091             processElement(childElement);
00092             childElement = childElement->NextSiblingElement();
00093         }
00094 
00095         // end element
00096         d_handler->elementEnd(element->Value());
00097     }
00098 
00099 
00100     TinyXMLParser::TinyXMLParser(void)
00101     {
00102         // set ID string
00103         d_identifierString = "CEGUI::TinyXMLParser - Official tinyXML based parser module for CEGUI";
00104     }
00105 
00106     TinyXMLParser::~TinyXMLParser(void)
00107     {}
00108 
00109     void TinyXMLParser::parseXMLFile(XMLHandler& handler, const String& filename, const String& schemaName, const String& resourceGroup)
00110     {
00111         TinyXMLDocument doc(handler, filename, schemaName, resourceGroup);
00112     }
00113 
00114 
00115     bool TinyXMLParser::initialiseImpl(void)
00116     {
00117         return true;
00118     }
00119 
00120     void TinyXMLParser::cleanupImpl(void)
00121     {}
00122 
00123 } // End of  CEGUI namespace section

Generated on Wed Sep 7 09:56:34 2005 for Crazy Eddies GUI System by  doxygen 1.4.3