diff --git a/code/AssetLib/X3D/X3DImporter.cpp b/code/AssetLib/X3D/X3DImporter.cpp index fd61fc62c..7748532e8 100644 --- a/code/AssetLib/X3D/X3DImporter.cpp +++ b/code/AssetLib/X3D/X3DImporter.cpp @@ -133,7 +133,7 @@ struct WordIterator { const char *operator*() const { return mStart; } }; -static const char *WordIterator::whitespace = ", \t\r\n"; +const char *WordIterator::whitespace = ", \t\r\n"; X3DImporter::X3DImporter() : mNodeElementCur(nullptr), mReader(nullptr) { @@ -231,11 +231,14 @@ bool X3DImporter::FindNodeElement(const std::string &pID, const X3DNodeElementBa /************************************************************* Functions: XML set ************************************************************/ /*********************************************************************************************************************************************/ -void X3DImporter::XML_CheckNode_MustBeEmpty() { - if (!mReader->isEmptyElement()) throw DeadlyImportError(std::string("Node <") + mReader->getNodeName() + "> must be empty."); +void X3DImporter::XML_CheckNode_MustBeEmpty(XmlNode &node) { + if (!node.empty()) { + throw DeadlyImportError(std::string("Node <") + node.name() + "> must be empty."); + } + //if (!mReader->isEmptyElement()) throw DeadlyImportError(std::string("Node <") + mReader->getNodeName() + "> must be empty."); } -void X3DImporter::XML_CheckNode_SkipUnsupported(const std::string &pParentNodeName) { +void X3DImporter::XML_CheckNode_SkipUnsupported(XmlNode &node, const std::string &pParentNodeName) { static const size_t Uns_Skip_Len = 192; const char *Uns_Skip[Uns_Skip_Len] = { // CAD geometry component @@ -313,26 +316,26 @@ void X3DImporter::XML_CheckNode_SkipUnsupported(const std::string &pParentNodeNa "VolumeData" }; - const std::string nn(mReader->getNodeName()); + const std::string nn = node.name(); bool found = false; bool close_found = false; for (size_t i = 0; i < Uns_Skip_Len; i++) { if (nn == Uns_Skip[i]) { found = true; - if (mReader->isEmptyElement()) { + if (node.empty()) { close_found = true; goto casu_cres; } - while (mReader->read()) { + /*while (mReader->read()) { if ((mReader->getNodeType() == irr::io::EXN_ELEMENT_END) && (nn == mReader->getNodeName())) { close_found = true; goto casu_cres; } - } + }*/ } } @@ -346,12 +349,13 @@ casu_cres: Throw_CloseNotFound(nn); } -bool X3DImporter::XML_SearchNode(const std::string &pNodeName) { - while (mReader->read()) { +bool X3DImporter::XML_SearchNode(XmlNode &node, const std::string &pNodeName) { + return XmlParser::hasNode(node, pNodeName.c_str()); + /*while (mReader->read()) { if ((mReader->getNodeType() == irr::io::EXN_ELEMENT) && XML_CheckNode_NameEqual(pNodeName)) return true; } - return false; + return false;*/ } bool X3DImporter::XML_ReadNode_GetAttrVal_AsBool(const int pAttrIdx) { diff --git a/code/AssetLib/X3D/X3DImporter.hpp b/code/AssetLib/X3D/X3DImporter.hpp index 1e8127ab8..54538ad67 100644 --- a/code/AssetLib/X3D/X3DImporter.hpp +++ b/code/AssetLib/X3D/X3DImporter.hpp @@ -374,7 +374,7 @@ private: /***********************************************/ /// Check if current node is empty: . If not then exception will throwed. - void XML_CheckNode_MustBeEmpty(); + void XML_CheckNode_MustBeEmpty(XmlNode &node); /// Check if current node name is equal to pNodeName. /// \param [in] pNodeName - name for checking. @@ -383,12 +383,12 @@ private: /// Skip unsupported node and report about that. Depend on node name can be skipped begin tag of node all whole node. /// \param [in] pParentNodeName - parent node name. Used for reporting. - void XML_CheckNode_SkipUnsupported(const std::string& pParentNodeName); + void XML_CheckNode_SkipUnsupported(XmlNode &node, const std::string &pParentNodeName); /// Search for specified node in file. XML file read pointer(mReader) will point to found node or file end after search is end. /// \param [in] pNodeName - requested node name. /// return true - if node is found, else - false. - bool XML_SearchNode(const std::string& pNodeName); + bool XML_SearchNode(XmlNode &node, const std::string &pNodeName); /// Read attribute value. /// \param [in] pAttrIdx - attribute index (\ref mReader->getAttribute* set). diff --git a/code/AssetLib/XGL/XGLLoader.h b/code/AssetLib/XGL/XGLLoader.h index d8bef4f9c..1d1f02974 100644 --- a/code/AssetLib/XGL/XGLLoader.h +++ b/code/AssetLib/XGL/XGLLoader.h @@ -48,7 +48,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include -#include #include #include #include diff --git a/include/assimp/ParsingUtils.h b/include/assimp/ParsingUtils.h index 28c2f0e76..9fbcee105 100644 --- a/include/assimp/ParsingUtils.h +++ b/include/assimp/ParsingUtils.h @@ -39,7 +39,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ---------------------------------------------------------------------- */ - /** @file ParsingUtils.h * @brief Defines helper functions for text parsing */ @@ -55,6 +54,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include + namespace Assimp { // NOTE: the functions below are mostly intended as replacement for diff --git a/include/assimp/XmlParser.h b/include/assimp/XmlParser.h index 11f06d692..0738df871 100644 --- a/include/assimp/XmlParser.h +++ b/include/assimp/XmlParser.h @@ -72,6 +72,9 @@ public: } }; +using XmlNode = pugi::xml_node; +using XmlAttribute = pugi::xml_attribute; + template class TXmlParser { public: @@ -144,7 +147,17 @@ public: return mRoot; } -private: + static inline bool hasNode(XmlNode &node, const char *name) { + pugi::xml_node child = node.find_child(find_node_by_name_predicate(name)); + return !child.empty(); + } + + static inline bool hasAttribute(XmlNode &xmlNode, const char *name) { + pugi::xml_attribute attr = xmlNode.attribute(name); + return !attr.empty(); + } + + private: pugi::xml_document *mDoc; TNodeType *mRoot; TNodeType mCurrent; @@ -152,12 +165,7 @@ private: }; using XmlParser = TXmlParser; -using XmlNode = pugi::xml_node; -static inline bool hasAttribute(XmlNode &xmlNode, const char *name) { - pugi::xml_attribute attr = xmlNode.attribute(name); - return !attr.empty(); -} } // namespace Assimp diff --git a/include/assimp/irrXMLWrapper.h b/include/assimp/irrXMLWrapper.h deleted file mode 100644 index 52c174791..000000000 --- a/include/assimp/irrXMLWrapper.h +++ /dev/null @@ -1,149 +0,0 @@ -/* -Open Asset Import Library (assimp) ----------------------------------------------------------------------- - -Copyright (c) 2006-2020, assimp team - - -All rights reserved. - -Redistribution and use of this software in source and binary forms, -with or without modification, are permitted provided that the -following conditions are met: - -* Redistributions of source code must retain the above -copyright notice, this list of conditions and the -following disclaimer. - -* Redistributions in binary form must reproduce the above -copyright notice, this list of conditions and the -following disclaimer in the documentation and/or other -materials provided with the distribution. - -* Neither the name of the assimp team, nor the names of its -contributors may be used to endorse or promote products -derived from this software without specific prior -written permission of the assimp team. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - ----------------------------------------------------------------------- -*/ - -#ifndef INCLUDED_AI_IRRXML_WRAPPER -#define INCLUDED_AI_IRRXML_WRAPPER - -// some long includes .... -#ifdef ASSIMP_USE_HUNTER -# include -#else -# include -#endif -#include "IOStream.hpp" -#include "BaseImporter.h" -#include - -namespace Assimp { - -// --------------------------------------------------------------------------------- -/** @brief Utility class to make IrrXML work together with our custom IO system - * See the IrrXML docs for more details. - * - * Construct IrrXML-Reader in BaseImporter::InternReadFile(): - * @code - * // open the file - * std::unique_ptr file( pIOHandler->Open( pFile)); - * if( file.get() == nullptr ) { - * throw DeadlyImportError( "Failed to open file " + pFile + "."); - * } - * - * // generate a XML reader for it - * std::unique_ptr mIOWrapper( new CIrrXML_IOStreamReader( file.get())); - * mReader = irr::io::createIrrXMLReader( mIOWrapper.get()); - * if( !mReader) { - * ThrowException( "xxxx: Unable to open file."); - * } - * @endcode - **/ -class CIrrXML_IOStreamReader : public irr::io::IFileReadCallBack { -public: - - // ---------------------------------------------------------------------------------- - //! Construction from an existing IOStream - explicit CIrrXML_IOStreamReader(IOStream* _stream) - : stream (_stream) - , t (0) - { - - // Map the buffer into memory and convert it to UTF8. IrrXML provides its - // own conversion, which is merely a cast from uintNN_t to uint8_t. Thus, - // it is not suitable for our purposes and we have to do it BEFORE IrrXML - // gets the buffer. Sadly, this forces us to map the whole file into - // memory. - - data.resize(stream->FileSize()); - stream->Read(&data[0],data.size(),1); - - // Remove null characters from the input sequence otherwise the parsing will utterly fail - // std::find is usually much faster than manually iterating - // It is very unlikely that there will be any null characters - auto null_char_iter = std::find(data.begin(), data.end(), '\0'); - - while (null_char_iter != data.end()) - { - null_char_iter = data.erase(null_char_iter); - null_char_iter = std::find(null_char_iter, data.end(), '\0'); - } - - BaseImporter::ConvertToUTF8(data); - } - - // ---------------------------------------------------------------------------------- - //! Virtual destructor - virtual ~CIrrXML_IOStreamReader() {} - - // ---------------------------------------------------------------------------------- - //! Reads an amount of bytes from the file. - /** @param buffer: Pointer to output buffer. - * @param sizeToRead: Amount of bytes to read - * @return Returns how much bytes were read. */ - virtual int read(void* buffer, int sizeToRead) { - if(sizeToRead<0) { - return 0; - } - if(t+sizeToRead>data.size()) { - sizeToRead = static_cast(data.size()-t); - } - - memcpy(buffer,&data.front()+t,sizeToRead); - - t += sizeToRead; - return sizeToRead; - } - - // ---------------------------------------------------------------------------------- - //! Returns size of file in bytes - virtual int getSize() { - return (int)data.size(); - } - -private: - IOStream* stream; - std::vector data; - size_t t; - -}; // ! class CIrrXML_IOStreamReader - -} // ! Assimp - -#endif // !! INCLUDED_AI_IRRXML_WRAPPER