From 0ece989560d0100bc676598abc65be1e36ac9ddc Mon Sep 17 00:00:00 2001 From: OTHGMars Date: Mon, 11 Jan 2021 04:57:10 -0500 Subject: [PATCH] Updates SimXMLDocument, fsTiXmlDocument, Taml and TamlXmlParser for reading from zip. --- Engine/source/console/SimXMLDocument.cpp | 95 ++++++++++--------- Engine/source/console/SimXMLDocument.h | 12 +-- Engine/source/persistence/taml/fsTinyXml.cpp | 4 +- Engine/source/persistence/taml/taml.cpp | 2 +- .../persistence/taml/xml/tamlXmlParser.cpp | 13 +-- .../persistence/taml/xml/tamlXmlParser.h | 9 +- 6 files changed, 67 insertions(+), 68 deletions(-) diff --git a/Engine/source/console/SimXMLDocument.cpp b/Engine/source/console/SimXMLDocument.cpp index df45888d1..3e0259bfe 100644 --- a/Engine/source/console/SimXMLDocument.cpp +++ b/Engine/source/console/SimXMLDocument.cpp @@ -31,6 +31,7 @@ #include "console/consoleInternal.h" #include "console/SimXMLDocument.h" #include "console/engineAPI.h" +#include "persistence/taml/fsTinyXml.h" IMPLEMENT_CONOBJECT(SimXMLDocument); @@ -175,7 +176,7 @@ bool SimXMLDocument::onAdd() if(!m_qDocument) { - m_qDocument = new TiXmlDocument(); + m_qDocument = new fsTiXmlDocument(); } return true; } @@ -345,16 +346,16 @@ bool SimXMLDocument::pushFirstChildElement(const char* rName) m_CurrentAttribute = 0; // Push the first element found under the current element of the given name - TiXmlElement* pElement; + fsTiXmlElement* pElement; if(!m_paNode.empty()) { const S32 iLastElement = m_paNode.size() - 1; - TiXmlElement* pNode = m_paNode[iLastElement]; + fsTiXmlElement* pNode = m_paNode[iLastElement]; if(!pNode) { return false; } - pElement = pNode->FirstChildElement(rName); + pElement = (fsTiXmlElement*) pNode->FirstChildElement(rName); } else { @@ -362,7 +363,7 @@ bool SimXMLDocument::pushFirstChildElement(const char* rName) { return false; } - pElement = m_qDocument->FirstChildElement(rName); + pElement = (fsTiXmlElement*)m_qDocument->FirstChildElement(rName); } if(!pElement) @@ -409,22 +410,22 @@ bool SimXMLDocument::pushChildElement(S32 index) m_CurrentAttribute = 0; // Push the first element found under the current element of the given name - TiXmlElement* pElement; + fsTiXmlElement* pElement; if(!m_paNode.empty()) { const S32 iLastElement = m_paNode.size() - 1; - TiXmlElement* pNode = m_paNode[iLastElement]; + fsTiXmlElement* pNode = m_paNode[iLastElement]; if(!pNode) { return false; } - pElement = pNode->FirstChildElement(); + pElement = (fsTiXmlElement*) pNode->FirstChildElement(); for( S32 i = 0; i < index; i++ ) { if( !pElement ) return false; - pElement = pElement->NextSiblingElement(); + pElement = (fsTiXmlElement*)pElement->NextSiblingElement(); } } else @@ -433,13 +434,13 @@ bool SimXMLDocument::pushChildElement(S32 index) { return false; } - pElement = m_qDocument->FirstChildElement(); + pElement = (fsTiXmlElement*)m_qDocument->FirstChildElement(); for( S32 i = 0; i < index; i++ ) { if( !pElement ) return false; - pElement = pElement->NextSiblingElement(); + pElement = (fsTiXmlElement*)pElement->NextSiblingElement(); } } @@ -473,13 +474,13 @@ bool SimXMLDocument::nextSiblingElement(const char* rName) return false; } const S32 iLastElement = m_paNode.size() - 1; - TiXmlElement*& pElement = m_paNode[iLastElement]; + fsTiXmlElement*& pElement = m_paNode[iLastElement]; if(!pElement) { return false; } - pElement = pElement->NextSiblingElement(rName); + pElement = (fsTiXmlElement*)pElement->NextSiblingElement(rName); if(!pElement) { return false; @@ -507,7 +508,7 @@ const char* SimXMLDocument::elementValue() return StringTable->EmptyString(); } const S32 iLastElement = m_paNode.size() - 1; - TiXmlElement* pNode = m_paNode[iLastElement]; + fsTiXmlElement* pNode = m_paNode[iLastElement]; if(!pNode) { return StringTable->EmptyString(); @@ -548,7 +549,7 @@ const char* SimXMLDocument::attribute(const char* rAttribute) return StringTable->EmptyString(); } const S32 iLastElement = m_paNode.size() - 1; - TiXmlElement* pNode = m_paNode[iLastElement]; + fsTiXmlElement* pNode = m_paNode[iLastElement]; if(!pNode) { return StringTable->EmptyString(); @@ -599,7 +600,7 @@ bool SimXMLDocument::attributeExists(const char* rAttribute) return false; } const S32 iLastElement = m_paNode.size() - 1; - TiXmlElement* pNode = m_paNode[iLastElement]; + fsTiXmlElement* pNode = m_paNode[iLastElement]; if(!pNode) { return false; @@ -632,14 +633,14 @@ const char* SimXMLDocument::firstAttribute() return StringTable->EmptyString(); } const S32 iLastElement = m_paNode.size() - 1; - TiXmlElement* pNode = m_paNode[iLastElement]; + fsTiXmlElement* pNode = m_paNode[iLastElement]; if(!pNode) { return StringTable->EmptyString(); } // Gets its first attribute, if any - m_CurrentAttribute = pNode->FirstAttribute(); + m_CurrentAttribute = (fsTiXmlAttribute*)pNode->FirstAttribute(); if(!m_CurrentAttribute) { return StringTable->EmptyString(); @@ -669,14 +670,14 @@ const char* SimXMLDocument::lastAttribute() return StringTable->EmptyString(); } const S32 iLastElement = m_paNode.size() - 1; - TiXmlElement* pNode = m_paNode[iLastElement]; + fsTiXmlElement* pNode = m_paNode[iLastElement]; if(!pNode) { return StringTable->EmptyString(); } // Gets its last attribute, if any - m_CurrentAttribute = pNode->LastAttribute(); + m_CurrentAttribute = (fsTiXmlAttribute*)pNode->LastAttribute(); if(!m_CurrentAttribute) { return StringTable->EmptyString(); @@ -707,7 +708,7 @@ const char* SimXMLDocument::nextAttribute() } // Gets its next attribute, if any - m_CurrentAttribute = m_CurrentAttribute->Next(); + m_CurrentAttribute = (fsTiXmlAttribute*)m_CurrentAttribute->Next(); if(!m_CurrentAttribute) { return StringTable->EmptyString(); @@ -738,7 +739,7 @@ const char* SimXMLDocument::prevAttribute() } // Gets its next attribute, if any - m_CurrentAttribute = m_CurrentAttribute->Previous(); + m_CurrentAttribute = (fsTiXmlAttribute*)m_CurrentAttribute->Previous(); if(!m_CurrentAttribute) { return StringTable->EmptyString(); @@ -768,7 +769,7 @@ void SimXMLDocument::setAttribute(const char* rAttribute, const char* rVal) } const S32 iLastElement = m_paNode.size() - 1; - TiXmlElement* pElement = m_paNode[iLastElement]; + fsTiXmlElement* pElement = m_paNode[iLastElement]; if(!pElement) { return; @@ -800,13 +801,13 @@ void SimXMLDocument::setObjectAttributes(const char* objectID) return; const S32 iLastElement = m_paNode.size() - 1; - TiXmlElement* pElement = m_paNode[iLastElement]; + fsTiXmlElement* pElement = m_paNode[iLastElement]; if(!pElement) return; char textbuf[1024]; - TiXmlElement field( "Field" ); - TiXmlElement group( "FieldGroup" ); + fsTiXmlElement field( "Field" ); + fsTiXmlElement group( "FieldGroup" ); pElement->SetAttribute( "Name", pObject->getName() ); @@ -917,22 +918,22 @@ DefineEngineMethod( SimXMLDocument, setObjectAttributes, void, ( const char* obj // ----------------------------------------------------------------------------- void SimXMLDocument::pushNewElement(const char* rName) { - TiXmlElement cElement( rName ); - TiXmlElement* pStackTop = 0; + fsTiXmlElement cElement( rName ); + fsTiXmlElement* pStackTop = 0; if(m_paNode.empty()) { - pStackTop = dynamic_cast + pStackTop = dynamic_cast (m_qDocument->InsertEndChild( cElement ) ); } else { const S32 iFinalElement = m_paNode.size() - 1; - TiXmlElement* pNode = m_paNode[iFinalElement]; + fsTiXmlElement* pNode = m_paNode[iFinalElement]; if(!pNode) { return; } - pStackTop = dynamic_cast + pStackTop = dynamic_cast (pNode->InsertEndChild( cElement )); } if(!pStackTop) @@ -962,11 +963,11 @@ DefineEngineMethod( SimXMLDocument, pushNewElement, void, ( const char* name ),, // ----------------------------------------------------------------------------- void SimXMLDocument::addNewElement(const char* rName) { - TiXmlElement cElement( rName ); - TiXmlElement* pStackTop = 0; + fsTiXmlElement cElement( rName ); + fsTiXmlElement* pStackTop = 0; if(m_paNode.empty()) { - pStackTop = dynamic_cast + pStackTop = dynamic_cast (m_qDocument->InsertEndChild( cElement )); if(!pStackTop) { @@ -979,7 +980,7 @@ void SimXMLDocument::addNewElement(const char* rName) const S32 iParentElement = m_paNode.size() - 2; if(iParentElement < 0) { - pStackTop = dynamic_cast + pStackTop = dynamic_cast (m_qDocument->InsertEndChild( cElement )); if(!pStackTop) { @@ -990,12 +991,12 @@ void SimXMLDocument::addNewElement(const char* rName) } else { - TiXmlElement* pNode = m_paNode[iParentElement]; + fsTiXmlElement* pNode = m_paNode[iParentElement]; if(!pNode) { return; } - pStackTop = dynamic_cast + pStackTop = dynamic_cast (pNode->InsertEndChild( cElement )); if(!pStackTop) { @@ -1029,7 +1030,7 @@ DefineEngineMethod( SimXMLDocument, addNewElement, void, ( const char* name ),, // ----------------------------------------------------------------------------- void SimXMLDocument::addHeader(void) { - TiXmlDeclaration cDeclaration("1.0", "utf-8", "yes"); + fsTiXmlDeclaration cDeclaration("1.0", "utf-8", "yes"); m_qDocument->InsertEndChild(cDeclaration); } @@ -1057,7 +1058,7 @@ DefineEngineMethod( SimXMLDocument, addHeader, void, (),, void SimXMLDocument::addComment(const char* comment) { - TiXmlComment cComment; + fsTiXmlComment cComment; cComment.SetValue(comment); m_qDocument->InsertEndChild(cComment); } @@ -1093,7 +1094,7 @@ const char* SimXMLDocument::readComment( S32 index ) if(!m_paNode.empty()) { const S32 iLastElement = m_paNode.size() - 1; - TiXmlElement* pNode = m_paNode[iLastElement]; + fsTiXmlElement* pNode = m_paNode[iLastElement]; if(!pNode) { return ""; @@ -1161,11 +1162,11 @@ void SimXMLDocument::addText(const char* text) return; const S32 iFinalElement = m_paNode.size() - 1; - TiXmlElement* pNode = m_paNode[iFinalElement]; + fsTiXmlElement* pNode = m_paNode[iFinalElement]; if(!pNode) return; - TiXmlText cText(text); + fsTiXmlText cText(text); pNode->InsertEndChild( cText ); } @@ -1213,7 +1214,7 @@ const char* SimXMLDocument::getText() if(!pNode->FirstChild()) return ""; - TiXmlText* text = pNode->FirstChild()->ToText(); + fsTiXmlText* text = (fsTiXmlText*)pNode->FirstChild()->ToText(); if( !text ) return ""; @@ -1266,14 +1267,14 @@ void SimXMLDocument::removeText() return; const S32 iFinalElement = m_paNode.size() - 1; - TiXmlElement* pNode = m_paNode[iFinalElement]; + fsTiXmlElement* pNode = m_paNode[iFinalElement]; if(!pNode) return; if( !pNode->FirstChild() ) return; - TiXmlText* text = pNode->FirstChild()->ToText(); + fsTiXmlText* text = (fsTiXmlText*)pNode->FirstChild()->ToText(); if( !text ) return; @@ -1302,11 +1303,11 @@ void SimXMLDocument::addData(const char* text) return; const S32 iFinalElement = m_paNode.size() - 1; - TiXmlElement* pNode = m_paNode[iFinalElement]; + fsTiXmlElement* pNode = m_paNode[iFinalElement]; if(!pNode) return; - TiXmlText cText(text); + fsTiXmlText cText(text); pNode->InsertEndChild( cText ); } diff --git a/Engine/source/console/SimXMLDocument.h b/Engine/source/console/SimXMLDocument.h index 342917cff..fcc0274dc 100644 --- a/Engine/source/console/SimXMLDocument.h +++ b/Engine/source/console/SimXMLDocument.h @@ -36,9 +36,9 @@ #endif // _TVECTOR_H_ -class TiXmlDocument; -class TiXmlElement; -class TiXmlAttribute; +class fsTiXmlDocument; +class fsTiXmlElement; +class fsTiXmlAttribute; class SimXMLDocument: public SimObject @@ -136,11 +136,11 @@ class SimXMLDocument: public SimObject private: // Document. - TiXmlDocument* m_qDocument; + fsTiXmlDocument* m_qDocument; // Stack of nodes. - Vector m_paNode; + Vector m_paNode; // The current attribute - TiXmlAttribute* m_CurrentAttribute; + fsTiXmlAttribute* m_CurrentAttribute; public: DECLARE_CONOBJECT(SimXMLDocument); diff --git a/Engine/source/persistence/taml/fsTinyXml.cpp b/Engine/source/persistence/taml/fsTinyXml.cpp index ffc069613..a43eb1345 100644 --- a/Engine/source/persistence/taml/fsTinyXml.cpp +++ b/Engine/source/persistence/taml/fsTinyXml.cpp @@ -27,7 +27,7 @@ bool fsTiXmlDocument::LoadFile( const char * pFilename, TiXmlEncoding encoding ) { // Expand the file-path. char filenameBuffer[1024]; - Con::expandToolScriptFilename( filenameBuffer, sizeof(filenameBuffer), pFilename ); + Con::expandScriptFilename( filenameBuffer, sizeof(filenameBuffer), pFilename ); FileStream stream; @@ -62,7 +62,7 @@ bool fsTiXmlDocument::SaveFile( const char * pFilename ) const { // Expand the file-name into the file-path buffer. char filenameBuffer[1024]; - Con::expandToolScriptFilename( filenameBuffer, sizeof(filenameBuffer), pFilename ); + Con::expandScriptFilename(filenameBuffer, sizeof(filenameBuffer), pFilename); FileStream stream; diff --git a/Engine/source/persistence/taml/taml.cpp b/Engine/source/persistence/taml/taml.cpp index b8390a70c..14557dbac 100644 --- a/Engine/source/persistence/taml/taml.cpp +++ b/Engine/source/persistence/taml/taml.cpp @@ -254,7 +254,7 @@ ImplementEnumType(_TamlFormatMode, AssertFatal(pFilename != NULL, "Cannot read from a NULL filename."); // Expand the file-name into the file-path buffer. - Con::expandToolScriptFilename(mFilePathBuffer, sizeof(mFilePathBuffer), pFilename); + Con::expandScriptFilename(mFilePathBuffer, sizeof(mFilePathBuffer), pFilename); FileStream stream; diff --git a/Engine/source/persistence/taml/xml/tamlXmlParser.cpp b/Engine/source/persistence/taml/xml/tamlXmlParser.cpp index 6ba33dd98..8644eb191 100644 --- a/Engine/source/persistence/taml/xml/tamlXmlParser.cpp +++ b/Engine/source/persistence/taml/xml/tamlXmlParser.cpp @@ -21,6 +21,7 @@ //----------------------------------------------------------------------------- #include "persistence/taml/xml/tamlXmlParser.h" +#include "persistence/taml/fsTinyXml.h" #include "persistence/taml/tamlVisitor.h" #include "console/console.h" @@ -45,7 +46,7 @@ bool TamlXmlParser::accept( const char* pFilename, TamlVisitor& visitor ) char filenameBuffer[1024]; // TODO: Make sure this is a proper substitute for // Con::expandPath (T2D) - Con::expandToolScriptFilename( filenameBuffer, sizeof(filenameBuffer), pFilename ); + Con::expandScriptFilename( filenameBuffer, sizeof(filenameBuffer), pFilename ); /** T2D uses a custom version of TinyXML that supports FileStream. * We don't so we can't do this * @@ -67,7 +68,7 @@ bool TamlXmlParser::accept( const char* pFilename, TamlVisitor& visitor ) */ - TiXmlDocument xmlDocument; + fsTiXmlDocument xmlDocument; // Load document from stream. if ( !xmlDocument.LoadFile( filenameBuffer ) ) @@ -87,7 +88,7 @@ bool TamlXmlParser::accept( const char* pFilename, TamlVisitor& visitor ) mDocumentDirty = false; // Parse root element. - parseElement( xmlDocument.RootElement(), visitor ); + parseElement( (fsTiXmlElement*)xmlDocument.RootElement(), visitor ); // Reset parsing filename. setParsingFilename( StringTable->EmptyString() ); @@ -120,7 +121,7 @@ bool TamlXmlParser::accept( const char* pFilename, TamlVisitor& visitor ) //----------------------------------------------------------------------------- -inline bool TamlXmlParser::parseElement( TiXmlElement* pXmlElement, TamlVisitor& visitor ) +inline bool TamlXmlParser::parseElement( fsTiXmlElement* pXmlElement, TamlVisitor& visitor ) { // Debug Profiling. PROFILE_SCOPE(TamlXmlParser_ParseElement); @@ -140,7 +141,7 @@ inline bool TamlXmlParser::parseElement( TiXmlElement* pXmlElement, TamlVisitor& if ( pChildXmlNode != NULL && pChildXmlNode->Type() == TiXmlNode::TINYXML_ELEMENT ) { // Iterate children. - for ( TiXmlElement* pChildXmlElement = dynamic_cast( pChildXmlNode ); pChildXmlElement; pChildXmlElement = pChildXmlElement->NextSiblingElement() ) + for ( fsTiXmlElement* pChildXmlElement = dynamic_cast( pChildXmlNode ); pChildXmlElement; pChildXmlElement = (fsTiXmlElement*)pChildXmlElement->NextSiblingElement() ) { // Parse element (stop processing if instructed). if ( !parseElement( pChildXmlElement, visitor ) ) @@ -153,7 +154,7 @@ inline bool TamlXmlParser::parseElement( TiXmlElement* pXmlElement, TamlVisitor& //----------------------------------------------------------------------------- -inline bool TamlXmlParser::parseAttributes( TiXmlElement* pXmlElement, TamlVisitor& visitor ) +inline bool TamlXmlParser::parseAttributes( fsTiXmlElement* pXmlElement, TamlVisitor& visitor ) { // Debug Profiling. PROFILE_SCOPE(TamlXmlParser_ParseAttribute); diff --git a/Engine/source/persistence/taml/xml/tamlXmlParser.h b/Engine/source/persistence/taml/xml/tamlXmlParser.h index 467fcba3a..40cfea91c 100644 --- a/Engine/source/persistence/taml/xml/tamlXmlParser.h +++ b/Engine/source/persistence/taml/xml/tamlXmlParser.h @@ -27,11 +27,8 @@ #include "persistence/taml/tamlParser.h" #endif -#ifndef TINYXML_INCLUDED -#include "tinyxml/tinyxml.h" -#endif - //----------------------------------------------------------------------------- +class fsTiXmlElement; /// @ingroup tamlGroup /// @see tamlGroup @@ -48,8 +45,8 @@ public: virtual bool accept( const char* pFilename, TamlVisitor& visitor ); private: - inline bool parseElement( TiXmlElement* pXmlElement, TamlVisitor& visitor ); - inline bool parseAttributes( TiXmlElement* pXmlElement, TamlVisitor& visitor ); + inline bool parseElement( fsTiXmlElement* pXmlElement, TamlVisitor& visitor ); + inline bool parseAttributes( fsTiXmlElement* pXmlElement, TamlVisitor& visitor ); bool mDocumentDirty; };