next step.s

pull/2966/head
Kim Kulling 2020-08-18 20:44:06 +02:00
parent 394651e640
commit 554ed1bf91
6 changed files with 34 additions and 171 deletions

View File

@ -133,7 +133,7 @@ struct WordIterator {
const char *operator*() const { return mStart; } const char *operator*() const { return mStart; }
}; };
static const char *WordIterator::whitespace = ", \t\r\n"; const char *WordIterator::whitespace = ", \t\r\n";
X3DImporter::X3DImporter() : X3DImporter::X3DImporter() :
mNodeElementCur(nullptr), mReader(nullptr) { mNodeElementCur(nullptr), mReader(nullptr) {
@ -231,11 +231,14 @@ bool X3DImporter::FindNodeElement(const std::string &pID, const X3DNodeElementBa
/************************************************************* Functions: XML set ************************************************************/ /************************************************************* Functions: XML set ************************************************************/
/*********************************************************************************************************************************************/ /*********************************************************************************************************************************************/
void X3DImporter::XML_CheckNode_MustBeEmpty() { void X3DImporter::XML_CheckNode_MustBeEmpty(XmlNode &node) {
if (!mReader->isEmptyElement()) throw DeadlyImportError(std::string("Node <") + mReader->getNodeName() + "> must be empty."); 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; static const size_t Uns_Skip_Len = 192;
const char *Uns_Skip[Uns_Skip_Len] = { const char *Uns_Skip[Uns_Skip_Len] = {
// CAD geometry component // CAD geometry component
@ -313,26 +316,26 @@ void X3DImporter::XML_CheckNode_SkipUnsupported(const std::string &pParentNodeNa
"VolumeData" "VolumeData"
}; };
const std::string nn(mReader->getNodeName()); const std::string nn = node.name();
bool found = false; bool found = false;
bool close_found = false; bool close_found = false;
for (size_t i = 0; i < Uns_Skip_Len; i++) { for (size_t i = 0; i < Uns_Skip_Len; i++) {
if (nn == Uns_Skip[i]) { if (nn == Uns_Skip[i]) {
found = true; found = true;
if (mReader->isEmptyElement()) { if (node.empty()) {
close_found = true; close_found = true;
goto casu_cres; goto casu_cres;
} }
while (mReader->read()) { /*while (mReader->read()) {
if ((mReader->getNodeType() == irr::io::EXN_ELEMENT_END) && (nn == mReader->getNodeName())) { if ((mReader->getNodeType() == irr::io::EXN_ELEMENT_END) && (nn == mReader->getNodeName())) {
close_found = true; close_found = true;
goto casu_cres; goto casu_cres;
} }
} }*/
} }
} }
@ -346,12 +349,13 @@ casu_cres:
Throw_CloseNotFound(nn); Throw_CloseNotFound(nn);
} }
bool X3DImporter::XML_SearchNode(const std::string &pNodeName) { bool X3DImporter::XML_SearchNode(XmlNode &node, const std::string &pNodeName) {
while (mReader->read()) { return XmlParser::hasNode(node, pNodeName.c_str());
/*while (mReader->read()) {
if ((mReader->getNodeType() == irr::io::EXN_ELEMENT) && XML_CheckNode_NameEqual(pNodeName)) return true; 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) { bool X3DImporter::XML_ReadNode_GetAttrVal_AsBool(const int pAttrIdx) {

View File

@ -374,7 +374,7 @@ private:
/***********************************************/ /***********************************************/
/// Check if current node is empty: <node />. If not then exception will throwed. /// Check if current node is empty: <node />. 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. /// Check if current node name is equal to pNodeName.
/// \param [in] pNodeName - name for checking. /// \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. /// 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. /// \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. /// 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. /// \param [in] pNodeName - requested node name.
/// return true - if node is found, else - false. /// 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. /// Read attribute value.
/// \param [in] pAttrIdx - attribute index (\ref mReader->getAttribute* set). /// \param [in] pAttrIdx - attribute index (\ref mReader->getAttribute* set).

View File

@ -48,7 +48,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <assimp/BaseImporter.h> #include <assimp/BaseImporter.h>
#include <assimp/XmlParser.h> #include <assimp/XmlParser.h>
#include <assimp/LogAux.h> #include <assimp/LogAux.h>
#include <assimp/irrXMLWrapper.h>
#include <assimp/light.h> #include <assimp/light.h>
#include <assimp/material.h> #include <assimp/material.h>
#include <assimp/mesh.h> #include <assimp/mesh.h>

View File

@ -39,7 +39,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------- ----------------------------------------------------------------------
*/ */
/** @file ParsingUtils.h /** @file ParsingUtils.h
* @brief Defines helper functions for text parsing * @brief Defines helper functions for text parsing
*/ */
@ -55,6 +54,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <assimp/StringUtils.h> #include <assimp/StringUtils.h>
#include <assimp/defs.h> #include <assimp/defs.h>
#include <vector>
namespace Assimp { namespace Assimp {
// NOTE: the functions below are mostly intended as replacement for // NOTE: the functions below are mostly intended as replacement for

View File

@ -72,6 +72,9 @@ public:
} }
}; };
using XmlNode = pugi::xml_node;
using XmlAttribute = pugi::xml_attribute;
template<class TNodeType> template<class TNodeType>
class TXmlParser { class TXmlParser {
public: public:
@ -144,6 +147,16 @@ public:
return mRoot; return mRoot;
} }
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: private:
pugi::xml_document *mDoc; pugi::xml_document *mDoc;
TNodeType *mRoot; TNodeType *mRoot;
@ -152,12 +165,7 @@ private:
}; };
using XmlParser = TXmlParser<pugi::xml_node>; using XmlParser = TXmlParser<pugi::xml_node>;
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 } // namespace Assimp

View File

@ -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 <irrXML/irrXML.h>
#else
# include <irrXML.h>
#endif
#include "IOStream.hpp"
#include "BaseImporter.h"
#include <vector>
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<IOStream> file( pIOHandler->Open( pFile));
* if( file.get() == nullptr ) {
* throw DeadlyImportError( "Failed to open file " + pFile + ".");
* }
*
* // generate a XML reader for it
* std::unique_ptr<CIrrXML_IOStreamReader> 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<int>(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<char> data;
size_t t;
}; // ! class CIrrXML_IOStreamReader
} // ! Assimp
#endif // !! INCLUDED_AI_IRRXML_WRAPPER