Merge branch 'master' into patch-1
commit
df768bdd99
|
@ -578,10 +578,6 @@ ELSE ()
|
||||||
ADD_DEFINITIONS( -DASSIMP_BUILD_NO_C4D_IMPORTER )
|
ADD_DEFINITIONS( -DASSIMP_BUILD_NO_C4D_IMPORTER )
|
||||||
ENDIF ()
|
ENDIF ()
|
||||||
|
|
||||||
#IF(NOT ASSIMP_HUNTER_ENABLED)
|
|
||||||
ADD_SUBDIRECTORY(contrib)
|
|
||||||
#ENDIF()
|
|
||||||
|
|
||||||
ADD_SUBDIRECTORY( code/ )
|
ADD_SUBDIRECTORY( code/ )
|
||||||
IF ( ASSIMP_BUILD_ASSIMP_TOOLS )
|
IF ( ASSIMP_BUILD_ASSIMP_TOOLS )
|
||||||
# The viewer for windows only
|
# The viewer for windows only
|
||||||
|
|
|
@ -139,7 +139,6 @@ void DNAParser::Parse() {
|
||||||
dna.structures.push_back(Structure());
|
dna.structures.push_back(Structure());
|
||||||
Structure &s = dna.structures.back();
|
Structure &s = dna.structures.back();
|
||||||
s.name = types[n].name;
|
s.name = types[n].name;
|
||||||
//s.index = dna.structures.size()-1;
|
|
||||||
|
|
||||||
n = stream.GetI2();
|
n = stream.GetI2();
|
||||||
s.fields.reserve(n);
|
s.fields.reserve(n);
|
||||||
|
|
|
@ -83,10 +83,9 @@ class ObjectCache;
|
||||||
* ancestry. */
|
* ancestry. */
|
||||||
// -------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------
|
||||||
struct Error : DeadlyImportError {
|
struct Error : DeadlyImportError {
|
||||||
template<typename... T>
|
template <typename... T>
|
||||||
explicit Error(T&&... args)
|
explicit Error(T &&...args) :
|
||||||
: DeadlyImportError(args...)
|
DeadlyImportError(args...) {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -187,7 +186,7 @@ struct Field {
|
||||||
};
|
};
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------
|
||||||
/** Range of possible behaviours for fields absend in the input file. Some are
|
/** Range of possible behaviors for fields absence in the input file. Some are
|
||||||
* mission critical so we need them, while others can silently be default
|
* mission critical so we need them, while others can silently be default
|
||||||
* initialized and no animations are harmed. */
|
* initialized and no animations are harmed. */
|
||||||
// -------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------
|
||||||
|
@ -395,7 +394,7 @@ private:
|
||||||
|
|
||||||
// --------------------------------------------------------
|
// --------------------------------------------------------
|
||||||
template <>
|
template <>
|
||||||
struct Structure ::_defaultInitializer<ErrorPolicy_Warn> {
|
struct Structure::_defaultInitializer<ErrorPolicy_Warn> {
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void operator()(T &out, const char *reason = "<add reason>") {
|
void operator()(T &out, const char *reason = "<add reason>") {
|
||||||
|
@ -407,7 +406,7 @@ struct Structure ::_defaultInitializer<ErrorPolicy_Warn> {
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct Structure ::_defaultInitializer<ErrorPolicy_Fail> {
|
struct Structure::_defaultInitializer<ErrorPolicy_Fail> {
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void operator()(T & /*out*/, const char * = "") {
|
void operator()(T & /*out*/, const char * = "") {
|
||||||
|
|
|
@ -106,51 +106,18 @@ class BlenderImporter : public BaseImporter, public LogFunctions<BlenderImporter
|
||||||
public:
|
public:
|
||||||
BlenderImporter();
|
BlenderImporter();
|
||||||
~BlenderImporter();
|
~BlenderImporter();
|
||||||
|
bool CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const;
|
||||||
public:
|
|
||||||
|
|
||||||
// --------------------
|
|
||||||
bool CanRead( const std::string& pFile,
|
|
||||||
IOSystem* pIOHandler,
|
|
||||||
bool checkSig
|
|
||||||
) const;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
// --------------------
|
|
||||||
const aiImporterDesc* GetInfo () const;
|
const aiImporterDesc* GetInfo () const;
|
||||||
|
|
||||||
// --------------------
|
|
||||||
void GetExtensionList(std::set<std::string>& app);
|
void GetExtensionList(std::set<std::string>& app);
|
||||||
|
|
||||||
// --------------------
|
|
||||||
void SetupProperties(const Importer* pImp);
|
void SetupProperties(const Importer* pImp);
|
||||||
|
void InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler);
|
||||||
// --------------------
|
void ParseBlendFile(Blender::FileDatabase& out, std::shared_ptr<IOStream> stream);
|
||||||
void InternReadFile( const std::string& pFile,
|
void ExtractScene(Blender::Scene& out, const Blender::FileDatabase& file);
|
||||||
aiScene* pScene,
|
void ConvertBlendFile(aiScene* out, const Blender::Scene& in, const Blender::FileDatabase& file);
|
||||||
IOSystem* pIOHandler
|
|
||||||
);
|
|
||||||
|
|
||||||
// --------------------
|
|
||||||
void ParseBlendFile(Blender::FileDatabase& out,
|
|
||||||
std::shared_ptr<IOStream> stream
|
|
||||||
);
|
|
||||||
|
|
||||||
// --------------------
|
|
||||||
void ExtractScene(Blender::Scene& out,
|
|
||||||
const Blender::FileDatabase& file
|
|
||||||
);
|
|
||||||
|
|
||||||
// --------------------
|
|
||||||
void ConvertBlendFile(aiScene* out,
|
|
||||||
const Blender::Scene& in,
|
|
||||||
const Blender::FileDatabase& file
|
|
||||||
);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// --------------------
|
|
||||||
aiNode* ConvertNode(const Blender::Scene& in,
|
aiNode* ConvertNode(const Blender::Scene& in,
|
||||||
const Blender::Object* obj,
|
const Blender::Object* obj,
|
||||||
Blender::ConversionData& conv_info,
|
Blender::ConversionData& conv_info,
|
||||||
|
|
|
@ -155,7 +155,7 @@ struct World : ElemBase {
|
||||||
// -------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------
|
||||||
struct MVert : ElemBase {
|
struct MVert : ElemBase {
|
||||||
float co[3] FAIL;
|
float co[3] FAIL;
|
||||||
float no[3] FAIL; // readed as short and divided through / 32767.f
|
float no[3] FAIL; // read as short and divided through / 32767.f
|
||||||
char flag;
|
char flag;
|
||||||
int mat_nr WARN;
|
int mat_nr WARN;
|
||||||
int bweight;
|
int bweight;
|
||||||
|
@ -228,7 +228,10 @@ struct TFace : ElemBase {
|
||||||
// -------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------
|
||||||
struct MTFace : ElemBase {
|
struct MTFace : ElemBase {
|
||||||
MTFace() :
|
MTFace() :
|
||||||
flag(0), mode(0), tile(0), unwrap(0) {
|
flag(0),
|
||||||
|
mode(0),
|
||||||
|
tile(0),
|
||||||
|
unwrap(0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
float uv[4][2] FAIL;
|
float uv[4][2] FAIL;
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -40,7 +40,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
---------------------------------------------------------------------------
|
---------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Actually just a dummy, used by the compiler to build the precompiled header.
|
// Actually just a dummy, used by the compiler to build the pre-compiled header.
|
||||||
|
|
||||||
#include "ScenePrivate.h"
|
#include "ScenePrivate.h"
|
||||||
#include <assimp/scene.h>
|
#include <assimp/scene.h>
|
||||||
|
@ -51,13 +51,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
// --------------------------------------------------------------------------------
|
// --------------------------------------------------------------------------------
|
||||||
// Legal information string - don't remove this.
|
// Legal information string - don't remove this.
|
||||||
static const char *LEGAL_INFORMATION =
|
static const char *LEGAL_INFORMATION =
|
||||||
|
|
||||||
"Open Asset Import Library (Assimp).\n"
|
"Open Asset Import Library (Assimp).\n"
|
||||||
"A free C/C++ library to import various 3D file formats into applications\n\n"
|
"A free C/C++ library to import various 3D file formats into applications\n\n"
|
||||||
|
|
||||||
"(c) 2006-2020, assimp team\n"
|
"(c) 2006-2020, assimp team\n"
|
||||||
"License under the terms and conditions of the 3-clause BSD license\n"
|
"License under the terms and conditions of the 3-clause BSD license\n"
|
||||||
"http://assimp.org\n";
|
"https://www.assimp.org\n";
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Get legal string
|
// Get legal string
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
|
|
|
@ -6,20 +6,12 @@ SET ( OPENDDL_PARSER_VERSION_PATCH 0 )
|
||||||
SET ( OPENDDL_PARSER_VERSION ${OPENDDL_PARSER_VERSION_MAJOR}.${OPENDDL_PARSER_VERSION_MINOR}.${OPENDDL_PARSER_VERSION_PATCH} )
|
SET ( OPENDDL_PARSER_VERSION ${OPENDDL_PARSER_VERSION_MAJOR}.${OPENDDL_PARSER_VERSION_MINOR}.${OPENDDL_PARSER_VERSION_PATCH} )
|
||||||
SET ( PROJECT_VERSION "${OPENDDL_PARSER_VERSION}" )
|
SET ( PROJECT_VERSION "${OPENDDL_PARSER_VERSION}" )
|
||||||
|
|
||||||
option( DDL_USE_CPP11 "Set to ON to use C++11 features ( always on on windows )." ON )
|
|
||||||
option( DDL_DEBUG_OUTPUT "Set to ON to use output debug texts" OFF )
|
option( DDL_DEBUG_OUTPUT "Set to ON to use output debug texts" OFF )
|
||||||
option( DDL_STATIC_LIBRARY "Set to ON to build static libary of OpenDDL Parser." ON )
|
option( DDL_STATIC_LIBRARY "Set to ON to build static libary of OpenDDL Parser." ON )
|
||||||
option( COVERALLS "Generate coveralls data" OFF )
|
option( COVERALLS "Generate coveralls data" OFF )
|
||||||
|
|
||||||
if ( DDL_USE_CPP11 )
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
if( CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX )
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
set( OPENDDL_CXXFLAGS -std=c++0x )
|
|
||||||
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
|
||||||
set( OPENDDL_CXXFLAGS --std=c++11 )
|
|
||||||
endif()
|
|
||||||
else( DDL_USE_CPP11 )
|
|
||||||
add_definitions( -DOPENDDL_NO_USE_CPP11 )
|
|
||||||
endif( DDL_USE_CPP11)
|
|
||||||
|
|
||||||
if( CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX )
|
if( CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX )
|
||||||
find_package(Threads)
|
find_package(Threads)
|
||||||
|
@ -31,6 +23,11 @@ if ( DDL_STATIC_LIBRARY )
|
||||||
add_definitions( -DOPENDDL_STATIC_LIBARY )
|
add_definitions( -DOPENDDL_STATIC_LIBARY )
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if (MSVC)
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING")
|
||||||
|
add_definitions(-DGTEST_HAS_TR1_TUPLE=0)
|
||||||
|
endif()
|
||||||
|
|
||||||
add_definitions( -DOPENDDLPARSER_BUILD )
|
add_definitions( -DOPENDDLPARSER_BUILD )
|
||||||
add_definitions( -D_VARIADIC_MAX=10 )
|
add_definitions( -D_VARIADIC_MAX=10 )
|
||||||
add_definitions( -DGTEST_HAS_PTHREAD=0 )
|
add_definitions( -DGTEST_HAS_PTHREAD=0 )
|
||||||
|
@ -49,7 +46,7 @@ link_directories(
|
||||||
${CMAKE_HOME_DIRECTORY}/lib
|
${CMAKE_HOME_DIRECTORY}/lib
|
||||||
)
|
)
|
||||||
|
|
||||||
set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake )
|
SET( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake )
|
||||||
SET( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_HOME_DIRECTORY}/lib )
|
SET( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_HOME_DIRECTORY}/lib )
|
||||||
SET( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_HOME_DIRECTORY}/lib )
|
SET( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_HOME_DIRECTORY}/lib )
|
||||||
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_HOME_DIRECTORY}/bin )
|
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_HOME_DIRECTORY}/bin )
|
||||||
|
@ -97,6 +94,7 @@ SET ( openddl_parser_src
|
||||||
include/openddlparser/OpenDDLStream.h
|
include/openddlparser/OpenDDLStream.h
|
||||||
include/openddlparser/DDLNode.h
|
include/openddlparser/DDLNode.h
|
||||||
include/openddlparser/Value.h
|
include/openddlparser/Value.h
|
||||||
|
include/openddlparser/TPoolAllocator.h
|
||||||
README.md
|
README.md
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -123,7 +121,6 @@ SET ( gtest_src
|
||||||
${GTEST_PATH}/src/gtest-test-part.cc
|
${GTEST_PATH}/src/gtest-test-part.cc
|
||||||
${GTEST_PATH}/src/gtest-typed-test.cc
|
${GTEST_PATH}/src/gtest-typed-test.cc
|
||||||
${GTEST_PATH}/src/gtest.cc
|
${GTEST_PATH}/src/gtest.cc
|
||||||
${GTEST_PATH}/src/gtest_main.cc
|
|
||||||
)
|
)
|
||||||
|
|
||||||
SET( openddl_parser_unittest_src
|
SET( openddl_parser_unittest_src
|
||||||
|
@ -137,7 +134,10 @@ SET( openddl_parser_unittest_src
|
||||||
test/OpenDDLIntegrationTest.cpp
|
test/OpenDDLIntegrationTest.cpp
|
||||||
test/ValueTest.cpp
|
test/ValueTest.cpp
|
||||||
test/OpenDDLDefectsTest.cpp
|
test/OpenDDLDefectsTest.cpp
|
||||||
|
test/OssFuzzTest.cpp
|
||||||
|
test/main.cpp
|
||||||
)
|
)
|
||||||
|
add_definitions(-DOPENDDL_TEST_DATA="${CMAKE_CURRENT_LIST_DIR}/test/TestData")
|
||||||
|
|
||||||
SOURCE_GROUP( code FILES ${openddl_parser_unittest_src} )
|
SOURCE_GROUP( code FILES ${openddl_parser_unittest_src} )
|
||||||
SOURCE_GROUP( gtest FILES ${gtest_src} )
|
SOURCE_GROUP( gtest FILES ${gtest_src} )
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*-----------------------------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------------------------
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2014-2015 Kim Kulling
|
Copyright (c) 2014-2020 Kim Kulling
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
this software and associated documentation files (the "Software"), to deal in
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
@ -22,6 +22,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
-----------------------------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------------------------*/
|
||||||
#include <openddlparser/DDLNode.h>
|
#include <openddlparser/DDLNode.h>
|
||||||
#include <openddlparser/OpenDDLParser.h>
|
#include <openddlparser/OpenDDLParser.h>
|
||||||
|
#include <openddlparser/OpenDDLStream.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
@ -29,77 +30,76 @@ BEGIN_ODDLPARSER_NS
|
||||||
|
|
||||||
DDLNode::DllNodeList DDLNode::s_allocatedNodes;
|
DDLNode::DllNodeList DDLNode::s_allocatedNodes;
|
||||||
|
|
||||||
template<class T>
|
template <class T>
|
||||||
inline
|
inline static void releaseDataType(T *ptr) {
|
||||||
static void releaseDataType( T *ptr ) {
|
if (nullptr == ptr) {
|
||||||
if( ddl_nullptr == ptr ) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
T *current( ddl_nullptr );
|
T *current(nullptr);
|
||||||
while( ptr ) {
|
while (ptr) {
|
||||||
current = ptr;
|
current = ptr;
|
||||||
ptr = ptr->m_next;
|
ptr = ptr->m_next;
|
||||||
delete current;
|
delete current;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void releaseReferencedNames( Reference *ref ) {
|
static void releaseReferencedNames(Reference *ref) {
|
||||||
if( ddl_nullptr == ref ) {
|
if (nullptr == ref) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete ref;
|
delete ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
DDLNode::DDLNode( const std::string &type, const std::string &name, size_t idx, DDLNode *parent )
|
DDLNode::DDLNode(const std::string &type, const std::string &name, size_t idx, DDLNode *parent) :
|
||||||
: m_type( type )
|
m_type(type),
|
||||||
, m_name( name )
|
m_name(name),
|
||||||
, m_parent( parent )
|
m_parent(parent),
|
||||||
, m_children()
|
m_children(),
|
||||||
, m_properties( ddl_nullptr )
|
m_properties(nullptr),
|
||||||
, m_value( ddl_nullptr )
|
m_value(nullptr),
|
||||||
, m_dtArrayList( ddl_nullptr )
|
m_dtArrayList(nullptr),
|
||||||
, m_references( ddl_nullptr )
|
m_references(nullptr),
|
||||||
, m_idx( idx ) {
|
m_idx(idx) {
|
||||||
if( m_parent ) {
|
if (m_parent) {
|
||||||
m_parent->m_children.push_back( this );
|
m_parent->m_children.push_back(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DDLNode::~DDLNode() {
|
DDLNode::~DDLNode() {
|
||||||
delete m_properties;
|
delete m_properties;
|
||||||
delete m_value;
|
delete m_value;
|
||||||
releaseReferencedNames( m_references );
|
releaseReferencedNames(m_references);
|
||||||
|
|
||||||
delete m_dtArrayList;
|
delete m_dtArrayList;
|
||||||
m_dtArrayList = ddl_nullptr;
|
m_dtArrayList = nullptr;
|
||||||
if( s_allocatedNodes[ m_idx ] == this ) {
|
if (s_allocatedNodes[m_idx] == this) {
|
||||||
s_allocatedNodes[ m_idx ] = ddl_nullptr;
|
s_allocatedNodes[m_idx] = nullptr;
|
||||||
}
|
}
|
||||||
for ( size_t i = 0; i<m_children.size(); i++ ){
|
for (size_t i = 0; i < m_children.size(); i++) {
|
||||||
delete m_children[ i ];
|
delete m_children[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DDLNode::attachParent( DDLNode *parent ) {
|
void DDLNode::attachParent(DDLNode *parent) {
|
||||||
if( m_parent == parent ) {
|
if (m_parent == parent) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_parent = parent;
|
m_parent = parent;
|
||||||
if( ddl_nullptr != m_parent ) {
|
if (nullptr != m_parent) {
|
||||||
m_parent->m_children.push_back( this );
|
m_parent->m_children.push_back(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DDLNode::detachParent() {
|
void DDLNode::detachParent() {
|
||||||
if( ddl_nullptr != m_parent ) {
|
if (nullptr != m_parent) {
|
||||||
DDLNodeIt it = std::find( m_parent->m_children.begin(), m_parent->m_children.end(), this );
|
DDLNodeIt it = std::find(m_parent->m_children.begin(), m_parent->m_children.end(), this);
|
||||||
if( m_parent->m_children.end() != it ) {
|
if (m_parent->m_children.end() != it) {
|
||||||
m_parent->m_children.erase( it );
|
m_parent->m_children.erase(it);
|
||||||
}
|
}
|
||||||
m_parent = ddl_nullptr;
|
m_parent = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ const DDLNode::DllNodeList &DDLNode::getChildNodeList() const {
|
||||||
return m_children;
|
return m_children;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DDLNode::setType( const std::string &type ) {
|
void DDLNode::setType(const std::string &type) {
|
||||||
m_type = type;
|
m_type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ const std::string &DDLNode::getType() const {
|
||||||
return m_type;
|
return m_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DDLNode::setName( const std::string &name ) {
|
void DDLNode::setName(const std::string &name) {
|
||||||
m_name = name;
|
m_name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,8 +127,8 @@ const std::string &DDLNode::getName() const {
|
||||||
return m_name;
|
return m_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DDLNode::setProperties( Property *prop ) {
|
void DDLNode::setProperties(Property *prop) {
|
||||||
if(m_properties!=ddl_nullptr)
|
if (m_properties != nullptr)
|
||||||
delete m_properties;
|
delete m_properties;
|
||||||
m_properties = prop;
|
m_properties = prop;
|
||||||
}
|
}
|
||||||
|
@ -137,37 +137,37 @@ Property *DDLNode::getProperties() const {
|
||||||
return m_properties;
|
return m_properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DDLNode::hasProperty( const std::string &name ) {
|
bool DDLNode::hasProperty(const std::string &name) {
|
||||||
const Property *prop( findPropertyByName( name ) );
|
const Property *prop(findPropertyByName(name));
|
||||||
return ( ddl_nullptr != prop );
|
return (nullptr != prop);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DDLNode::hasProperties() const {
|
bool DDLNode::hasProperties() const {
|
||||||
return( ddl_nullptr != m_properties );
|
return (nullptr != m_properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
Property *DDLNode::findPropertyByName( const std::string &name ) {
|
Property *DDLNode::findPropertyByName(const std::string &name) {
|
||||||
if( name.empty() ) {
|
if (name.empty()) {
|
||||||
return ddl_nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ddl_nullptr == m_properties ) {
|
if (nullptr == m_properties) {
|
||||||
return ddl_nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Property *current( m_properties );
|
Property *current(m_properties);
|
||||||
while( ddl_nullptr != current ) {
|
while (nullptr != current) {
|
||||||
int res = strncmp( current->m_key->m_buffer, name.c_str(), name.size() );
|
int res = strncmp(current->m_key->m_buffer, name.c_str(), name.size());
|
||||||
if( 0 == res ) {
|
if (0 == res) {
|
||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
current = current->m_next;
|
current = current->m_next;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ddl_nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DDLNode::setValue( Value *val ) {
|
void DDLNode::setValue(Value *val) {
|
||||||
m_value = val;
|
m_value = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,7 +175,7 @@ Value *DDLNode::getValue() const {
|
||||||
return m_value;
|
return m_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DDLNode::setDataArrayList( DataArrayList *dtArrayList ) {
|
void DDLNode::setDataArrayList(DataArrayList *dtArrayList) {
|
||||||
m_dtArrayList = dtArrayList;
|
m_dtArrayList = dtArrayList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,7 +183,7 @@ DataArrayList *DDLNode::getDataArrayList() const {
|
||||||
return m_dtArrayList;
|
return m_dtArrayList;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DDLNode::setReferences( Reference *refs ) {
|
void DDLNode::setReferences(Reference *refs) {
|
||||||
m_references = refs;
|
m_references = refs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,22 +191,32 @@ Reference *DDLNode::getReferences() const {
|
||||||
return m_references;
|
return m_references;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DDLNode::dump(IOStreamBase &/*stream*/) {
|
void DDLNode::dump(IOStreamBase &stream) {
|
||||||
// Todo!
|
if (!stream.isOpen()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string &type = this->getType();
|
||||||
|
stream.write("type = " + type);
|
||||||
|
Value::Iterator it(getValue());
|
||||||
|
while (it.hasNext()) {
|
||||||
|
Value *v = it.getNext();
|
||||||
|
v->dump(stream);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DDLNode *DDLNode::create( const std::string &type, const std::string &name, DDLNode *parent ) {
|
DDLNode *DDLNode::create(const std::string &type, const std::string &name, DDLNode *parent) {
|
||||||
const size_t idx( s_allocatedNodes.size() );
|
const size_t idx(s_allocatedNodes.size());
|
||||||
DDLNode *node = new DDLNode( type, name, idx, parent );
|
DDLNode *node = new DDLNode(type, name, idx, parent);
|
||||||
s_allocatedNodes.push_back( node );
|
s_allocatedNodes.push_back(node);
|
||||||
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DDLNode::releaseNodes() {
|
void DDLNode::releaseNodes() {
|
||||||
if( s_allocatedNodes.size() > 0 ) {
|
if (s_allocatedNodes.size() > 0) {
|
||||||
for( DDLNodeIt it = s_allocatedNodes.begin(); it != s_allocatedNodes.end(); it++ ) {
|
for (DDLNodeIt it = s_allocatedNodes.begin(); it != s_allocatedNodes.end(); it++) {
|
||||||
if( *it ) {
|
if (*it) {
|
||||||
delete *it;
|
delete *it;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*-----------------------------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------------------------
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2014-2015 Kim Kulling
|
Copyright (c) 2014-2020 Kim Kulling
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
this software and associated documentation files (the "Software"), to deal in
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
@ -20,17 +20,17 @@ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
-----------------------------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------------------------*/
|
||||||
#include <openddlparser/OpenDDLCommon.h>
|
|
||||||
#include <openddlparser/DDLNode.h>
|
#include <openddlparser/DDLNode.h>
|
||||||
|
#include <openddlparser/OpenDDLCommon.h>
|
||||||
#include <openddlparser/Value.h>
|
#include <openddlparser/Value.h>
|
||||||
|
|
||||||
BEGIN_ODDLPARSER_NS
|
BEGIN_ODDLPARSER_NS
|
||||||
|
|
||||||
Text::Text( const char *buffer, size_t numChars )
|
Text::Text(const char *buffer, size_t numChars) :
|
||||||
: m_capacity( 0 )
|
m_capacity(0),
|
||||||
, m_len( 0 )
|
m_len(0),
|
||||||
, m_buffer( ddl_nullptr ) {
|
m_buffer(nullptr) {
|
||||||
set( buffer, numChars );
|
set(buffer, numChars);
|
||||||
}
|
}
|
||||||
|
|
||||||
Text::~Text() {
|
Text::~Text() {
|
||||||
|
@ -39,103 +39,98 @@ Text::~Text() {
|
||||||
|
|
||||||
void Text::clear() {
|
void Text::clear() {
|
||||||
delete[] m_buffer;
|
delete[] m_buffer;
|
||||||
m_buffer = ddl_nullptr;
|
m_buffer = nullptr;
|
||||||
m_capacity = 0;
|
m_capacity = 0;
|
||||||
m_len = 0;
|
m_len = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Text::set( const char *buffer, size_t numChars ) {
|
void Text::set(const char *buffer, size_t numChars) {
|
||||||
clear();
|
clear();
|
||||||
if( numChars > 0 ) {
|
if (numChars > 0) {
|
||||||
m_len = numChars;
|
m_len = numChars;
|
||||||
m_capacity = m_len + 1;
|
m_capacity = m_len + 1;
|
||||||
m_buffer = new char[ m_capacity ];
|
m_buffer = new char[m_capacity];
|
||||||
strncpy( m_buffer, buffer, numChars );
|
strncpy(m_buffer, buffer, numChars);
|
||||||
m_buffer[ numChars ] = '\0';
|
m_buffer[numChars] = '\0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Text::operator == ( const std::string &name ) const {
|
bool Text::operator==(const std::string &name) const {
|
||||||
if( m_len != name.size() ) {
|
if (m_len != name.size()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const int res( strncmp( m_buffer, name.c_str(), name.size() ) );
|
const int res(strncmp(m_buffer, name.c_str(), name.size()));
|
||||||
|
|
||||||
return ( 0 == res );
|
return (0 == res);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Text::operator == ( const Text &rhs ) const {
|
bool Text::operator==(const Text &rhs) const {
|
||||||
if( m_len != rhs.m_len ) {
|
if (m_len != rhs.m_len) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int res( strncmp( m_buffer, rhs.m_buffer, m_len ) );
|
const int res(strncmp(m_buffer, rhs.m_buffer, m_len));
|
||||||
|
|
||||||
return ( 0 == res );
|
return (0 == res);
|
||||||
}
|
}
|
||||||
|
|
||||||
Name::Name( NameType type, Text *id )
|
Name::Name(NameType type, Text *id) :
|
||||||
: m_type( type )
|
m_type(type), m_id(id) {
|
||||||
, m_id( id ) {
|
|
||||||
// empty
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
Name::~Name() {
|
Name::~Name() {
|
||||||
delete m_id;
|
delete m_id;
|
||||||
m_id = ddl_nullptr;
|
m_id = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Name::Name( const Name &name ){
|
Name::Name(const Name &name) {
|
||||||
m_type=name.m_type;
|
m_type = name.m_type;
|
||||||
m_id=new Text(name.m_id->m_buffer,name.m_id->m_len);
|
m_id = new Text(name.m_id->m_buffer, name.m_id->m_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference::Reference() :
|
||||||
|
m_numRefs(0), m_referencedName(nullptr) {
|
||||||
Reference::Reference()
|
|
||||||
: m_numRefs( 0 )
|
|
||||||
, m_referencedName( ddl_nullptr ) {
|
|
||||||
// empty
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference::Reference( size_t numrefs, Name **names )
|
Reference::Reference(size_t numrefs, Name **names) :
|
||||||
: m_numRefs( numrefs )
|
m_numRefs(numrefs), m_referencedName(nullptr) {
|
||||||
, m_referencedName( ddl_nullptr ) {
|
if (numrefs > 0) {
|
||||||
if ( numrefs > 0 ) {
|
m_referencedName = new Name *[numrefs];
|
||||||
m_referencedName = new Name *[ numrefs ];
|
for (size_t i = 0; i < numrefs; i++) {
|
||||||
for ( size_t i = 0; i < numrefs; i++ ) {
|
m_referencedName[i] = names[i];
|
||||||
m_referencedName[ i ] = names[i];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference::Reference(const Reference &ref) {
|
Reference::Reference(const Reference &ref) {
|
||||||
m_numRefs=ref.m_numRefs;
|
m_numRefs = ref.m_numRefs;
|
||||||
if(m_numRefs!=0){
|
if (m_numRefs != 0) {
|
||||||
m_referencedName = new Name*[m_numRefs];
|
m_referencedName = new Name *[m_numRefs];
|
||||||
for ( size_t i = 0; i < m_numRefs; i++ ) {
|
for (size_t i = 0; i < m_numRefs; i++) {
|
||||||
m_referencedName[i] = new Name(*ref.m_referencedName[i]);
|
m_referencedName[i] = new Name(*ref.m_referencedName[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference::~Reference() {
|
Reference::~Reference() {
|
||||||
for( size_t i = 0; i < m_numRefs; i++ ) {
|
for (size_t i = 0; i < m_numRefs; i++) {
|
||||||
delete m_referencedName[ i ];
|
delete m_referencedName[i];
|
||||||
}
|
}
|
||||||
m_numRefs = 0;
|
m_numRefs = 0;
|
||||||
delete [] m_referencedName;
|
delete[] m_referencedName;
|
||||||
m_referencedName = ddl_nullptr;
|
m_referencedName = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Reference::sizeInBytes() {
|
size_t Reference::sizeInBytes() {
|
||||||
if ( 0 == m_numRefs ) {
|
if (0 == m_numRefs) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t size( 0 );
|
size_t size(0);
|
||||||
for ( size_t i = 0; i < m_numRefs; i++ ) {
|
for (size_t i = 0; i < m_numRefs; i++) {
|
||||||
Name *name( m_referencedName[ i ] );
|
Name *name(m_referencedName[i]);
|
||||||
if ( ddl_nullptr != name ) {
|
if (nullptr != name) {
|
||||||
size += name->m_id->m_len;
|
size += name->m_id->m_len;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,60 +138,53 @@ size_t Reference::sizeInBytes() {
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
Property::Property( Text *id )
|
Property::Property(Text *id) :
|
||||||
: m_key( id )
|
m_key(id), m_value(nullptr), m_ref(nullptr), m_next(nullptr) {
|
||||||
, m_value( ddl_nullptr )
|
|
||||||
, m_ref( ddl_nullptr )
|
|
||||||
, m_next( ddl_nullptr ) {
|
|
||||||
// empty
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
Property::~Property() {
|
Property::~Property() {
|
||||||
delete m_key;
|
delete m_key;
|
||||||
if(m_value!=ddl_nullptr)
|
if (m_value != nullptr)
|
||||||
delete m_value;
|
delete m_value;
|
||||||
if(m_ref!=ddl_nullptr)
|
if (m_ref != nullptr)
|
||||||
delete(m_ref);
|
delete (m_ref);
|
||||||
if(m_next!=ddl_nullptr)
|
if (m_next != nullptr)
|
||||||
delete m_next;
|
delete m_next;
|
||||||
}
|
}
|
||||||
|
|
||||||
DataArrayList::DataArrayList()
|
DataArrayList::DataArrayList() :
|
||||||
: m_numItems( 0 )
|
m_numItems(0), m_dataList(nullptr), m_next(nullptr), m_refs(nullptr), m_numRefs(0) {
|
||||||
, m_dataList( ddl_nullptr )
|
|
||||||
, m_next( ddl_nullptr )
|
|
||||||
, m_refs(ddl_nullptr)
|
|
||||||
, m_numRefs(0){
|
|
||||||
// empty
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
DataArrayList::~DataArrayList() {
|
DataArrayList::~DataArrayList() {
|
||||||
delete m_dataList;
|
delete m_dataList;
|
||||||
if(m_next!=ddl_nullptr)
|
if (m_next != nullptr)
|
||||||
delete m_next;
|
delete m_next;
|
||||||
if(m_refs!=ddl_nullptr)
|
if (m_refs != nullptr)
|
||||||
delete m_refs;
|
delete m_refs;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t DataArrayList::size() {
|
size_t DataArrayList::size() {
|
||||||
size_t result( 0 );
|
size_t result(0);
|
||||||
if ( ddl_nullptr == m_next ) {
|
if (nullptr == m_next) {
|
||||||
if ( m_dataList != ddl_nullptr ) {
|
if (m_dataList != nullptr) {
|
||||||
result = 1;
|
result = 1;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
DataArrayList *n( m_next );
|
DataArrayList *n(m_next);
|
||||||
while( ddl_nullptr != n ) {
|
while (nullptr != n) {
|
||||||
result++;
|
result++;
|
||||||
n = n->m_next;
|
n = n->m_next;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Context::Context()
|
Context::Context() :
|
||||||
: m_root( ddl_nullptr ) {
|
m_root(nullptr) {
|
||||||
// empty
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,7 +194,7 @@ Context::~Context() {
|
||||||
|
|
||||||
void Context::clear() {
|
void Context::clear() {
|
||||||
delete m_root;
|
delete m_root;
|
||||||
m_root = ddl_nullptr;
|
m_root = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
END_ODDLPARSER_NS
|
END_ODDLPARSER_NS
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*-----------------------------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------------------------
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2014-2015 Kim Kulling
|
Copyright (c) 2014-2020 Kim Kulling
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
this software and associated documentation files (the "Software"), to deal in
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
@ -20,10 +20,10 @@ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
-----------------------------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------------------------*/
|
||||||
#include <openddlparser/OpenDDLExport.h>
|
|
||||||
#include <openddlparser/DDLNode.h>
|
#include <openddlparser/DDLNode.h>
|
||||||
#include <openddlparser/Value.h>
|
#include <openddlparser/OpenDDLExport.h>
|
||||||
#include <openddlparser/OpenDDLParser.h>
|
#include <openddlparser/OpenDDLParser.h>
|
||||||
|
#include <openddlparser/Value.h>
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
@ -33,9 +33,8 @@ struct DDLNodeIterator {
|
||||||
const DDLNode::DllNodeList &m_childs;
|
const DDLNode::DllNodeList &m_childs;
|
||||||
size_t m_idx;
|
size_t m_idx;
|
||||||
|
|
||||||
DDLNodeIterator( const DDLNode::DllNodeList &childs )
|
DDLNodeIterator(const DDLNode::DllNodeList &childs) :
|
||||||
: m_childs( childs )
|
m_childs(childs), m_idx(0) {
|
||||||
, m_idx( 0 ) {
|
|
||||||
// empty
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,10 +42,10 @@ struct DDLNodeIterator {
|
||||||
// empty
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
bool getNext( DDLNode **node ) {
|
bool getNext(DDLNode **node) {
|
||||||
if( m_childs.size() > (m_idx+1) ) {
|
if (m_childs.size() > (m_idx + 1)) {
|
||||||
m_idx++;
|
m_idx++;
|
||||||
*node = m_childs[ m_idx ];
|
*node = m_childs[m_idx];
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,65 +54,65 @@ struct DDLNodeIterator {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DDLNodeIterator() ddl_no_copy;
|
DDLNodeIterator() ddl_no_copy;
|
||||||
DDLNodeIterator &operator = ( const DDLNodeIterator & ) ddl_no_copy;
|
DDLNodeIterator &operator=(const DDLNodeIterator &) ddl_no_copy;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void writeLineEnd( std::string &statement ) {
|
static void writeLineEnd(std::string &statement) {
|
||||||
statement += "\n";
|
statement += "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
OpenDDLExport::OpenDDLExport( IOStreamBase *stream )
|
OpenDDLExport::OpenDDLExport(IOStreamBase *stream) :
|
||||||
: m_stream( stream ) {
|
m_stream(stream) {
|
||||||
if (ddl_nullptr == m_stream) {
|
if (nullptr == m_stream) {
|
||||||
m_stream = new IOStreamBase();
|
m_stream = new IOStreamBase();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OpenDDLExport::~OpenDDLExport() {
|
OpenDDLExport::~OpenDDLExport() {
|
||||||
if (ddl_nullptr != m_stream) {
|
if (nullptr != m_stream) {
|
||||||
m_stream->close();
|
m_stream->close();
|
||||||
}
|
}
|
||||||
delete m_stream;
|
delete m_stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OpenDDLExport::exportContext( Context *ctx, const std::string &filename ) {
|
bool OpenDDLExport::exportContext(Context *ctx, const std::string &filename) {
|
||||||
if( ddl_nullptr == ctx ) {
|
if (nullptr == ctx) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
DDLNode *root( ctx->m_root );
|
DDLNode *root(ctx->m_root);
|
||||||
if ( ddl_nullptr == root ) {
|
if (nullptr == root) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!filename.empty()) {
|
if (!filename.empty()) {
|
||||||
if (!m_stream->open( filename )) {
|
if (!m_stream->open(filename)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool retValue( handleNode( root ) );
|
const bool retValue(handleNode(root));
|
||||||
|
|
||||||
return retValue;
|
return retValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OpenDDLExport::handleNode( DDLNode *node ) {
|
bool OpenDDLExport::handleNode(DDLNode *node) {
|
||||||
if( ddl_nullptr == node ) {
|
if (nullptr == node) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const DDLNode::DllNodeList &childs = node->getChildNodeList();
|
const DDLNode::DllNodeList &childs = node->getChildNodeList();
|
||||||
if( childs.empty() ) {
|
if (childs.empty()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
DDLNode *current( ddl_nullptr );
|
DDLNode *current(nullptr);
|
||||||
DDLNodeIterator it( childs );
|
DDLNodeIterator it(childs);
|
||||||
std::string statement;
|
std::string statement;
|
||||||
bool success( true );
|
bool success(true);
|
||||||
while( it.getNext( ¤t ) ) {
|
while (it.getNext(¤t)) {
|
||||||
if( ddl_nullptr != current ) {
|
if (nullptr != current) {
|
||||||
success |= writeNode( current, statement );
|
success |= writeNode(current, statement);
|
||||||
if( !handleNode( current ) ) {
|
if (!handleNode(current)) {
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,56 +121,57 @@ bool OpenDDLExport::handleNode( DDLNode *node ) {
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OpenDDLExport::writeToStream( const std::string &statement ) {
|
bool OpenDDLExport::writeToStream(const std::string &statement) {
|
||||||
if (ddl_nullptr == m_stream ) {
|
if (nullptr == m_stream) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !statement.empty()) {
|
if (!statement.empty()) {
|
||||||
m_stream->write( statement );
|
m_stream->write(statement);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OpenDDLExport::writeNode( DDLNode *node, std::string &statement ) {
|
bool OpenDDLExport::writeNode(DDLNode *node, std::string &statement) {
|
||||||
writeNodeHeader( node, statement );
|
bool success(true);
|
||||||
|
writeNodeHeader(node, statement);
|
||||||
if (node->hasProperties()) {
|
if (node->hasProperties()) {
|
||||||
writeProperties( node, statement );
|
success |= writeProperties(node, statement);
|
||||||
}
|
}
|
||||||
writeLineEnd( statement );
|
writeLineEnd(statement);
|
||||||
|
|
||||||
statement = "}";
|
statement = "}";
|
||||||
DataArrayList *al( node->getDataArrayList() );
|
DataArrayList *al(node->getDataArrayList());
|
||||||
if ( ddl_nullptr != al ) {
|
if (nullptr != al) {
|
||||||
writeValueType( al->m_dataList->m_type, al->m_numItems, statement );
|
writeValueType(al->m_dataList->m_type, al->m_numItems, statement);
|
||||||
writeValueArray( al, statement );
|
writeValueArray(al, statement);
|
||||||
}
|
}
|
||||||
Value *v( node->getValue() );
|
Value *v(node->getValue());
|
||||||
if (ddl_nullptr != v ) {
|
if (nullptr != v) {
|
||||||
writeValueType( v->m_type, 1, statement );
|
writeValueType(v->m_type, 1, statement);
|
||||||
statement = "{";
|
statement = "{";
|
||||||
writeLineEnd( statement );
|
writeLineEnd(statement);
|
||||||
writeValue( v, statement );
|
writeValue(v, statement);
|
||||||
statement = "}";
|
statement = "}";
|
||||||
writeLineEnd( statement );
|
writeLineEnd(statement);
|
||||||
}
|
}
|
||||||
statement = "}";
|
statement = "}";
|
||||||
writeLineEnd( statement );
|
writeLineEnd(statement);
|
||||||
|
|
||||||
writeToStream( statement );
|
writeToStream(statement);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OpenDDLExport::writeNodeHeader( DDLNode *node, std::string &statement ) {
|
bool OpenDDLExport::writeNodeHeader(DDLNode *node, std::string &statement) {
|
||||||
if (ddl_nullptr == node) {
|
if (nullptr == node) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
statement += node->getType();
|
statement += node->getType();
|
||||||
const std::string &name( node->getName() );
|
const std::string &name(node->getName());
|
||||||
if ( !name.empty() ) {
|
if (!name.empty()) {
|
||||||
statement += " ";
|
statement += " ";
|
||||||
statement += "$";
|
statement += "$";
|
||||||
statement += name;
|
statement += name;
|
||||||
|
@ -180,30 +180,30 @@ bool OpenDDLExport::writeNodeHeader( DDLNode *node, std::string &statement ) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OpenDDLExport::writeProperties( DDLNode *node, std::string &statement ) {
|
bool OpenDDLExport::writeProperties(DDLNode *node, std::string &statement) {
|
||||||
if ( ddl_nullptr == node ) {
|
if (nullptr == node) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Property *prop( node->getProperties() );
|
Property *prop(node->getProperties());
|
||||||
// if no properties are there, return
|
// if no properties are there, return
|
||||||
if ( ddl_nullptr == prop ) {
|
if (nullptr == prop) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ddl_nullptr != prop ) {
|
if (nullptr != prop) {
|
||||||
// for instance (attrib = "position", bla=2)
|
// for instance (attrib = "position", bla=2)
|
||||||
statement += "(";
|
statement += "(";
|
||||||
bool first( true );
|
bool first(true);
|
||||||
while ( ddl_nullptr != prop ) {
|
while (nullptr != prop) {
|
||||||
if (!first) {
|
if (!first) {
|
||||||
statement += ", ";
|
statement += ", ";
|
||||||
} else {
|
} else {
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
statement += std::string( prop->m_key->m_buffer );
|
statement += std::string(prop->m_key->m_buffer);
|
||||||
statement += " = ";
|
statement += " = ";
|
||||||
writeValue( prop->m_value, statement );
|
writeValue(prop->m_value, statement);
|
||||||
prop = prop->m_next;
|
prop = prop->m_next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,19 +213,19 @@ bool OpenDDLExport::writeProperties( DDLNode *node, std::string &statement ) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OpenDDLExport::writeValueType( Value::ValueType type, size_t numItems, std::string &statement ) {
|
bool OpenDDLExport::writeValueType(Value::ValueType type, size_t numItems, std::string &statement) {
|
||||||
if ( Value::ddl_types_max == type) {
|
if (Value::ValueType::ddl_types_max == type) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string typeStr( getTypeToken( type ) );
|
const std::string typeStr(getTypeToken(type));
|
||||||
statement += typeStr;
|
statement += typeStr;
|
||||||
// if we have an array to write
|
// if we have an array to write
|
||||||
if ( numItems > 1 ) {
|
if (numItems > 1) {
|
||||||
statement += "[";
|
statement += "[";
|
||||||
char buffer[ 256 ];
|
char buffer[256];
|
||||||
::memset( buffer, '\0', 256 * sizeof( char ) );
|
::memset(buffer, '\0', 256 * sizeof(char));
|
||||||
sprintf( buffer, "%d", static_cast<int>( numItems ) );
|
sprintf(buffer, "%d", static_cast<int>(numItems));
|
||||||
statement += buffer;
|
statement += buffer;
|
||||||
statement += "]";
|
statement += "]";
|
||||||
}
|
}
|
||||||
|
@ -233,115 +233,93 @@ bool OpenDDLExport::writeValueType( Value::ValueType type, size_t numItems, std:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OpenDDLExport::writeValue( Value *val, std::string &statement ) {
|
bool OpenDDLExport::writeValue(Value *val, std::string &statement) {
|
||||||
if (ddl_nullptr == val) {
|
if (nullptr == val) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ( val->m_type ) {
|
switch (val->m_type) {
|
||||||
case Value::ddl_bool:
|
case Value::ValueType::ddl_bool:
|
||||||
if ( true == val->getBool() ) {
|
if (true == val->getBool()) {
|
||||||
statement += "true";
|
statement += "true";
|
||||||
} else {
|
} else {
|
||||||
statement += "false";
|
statement += "false";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Value::ddl_int8:
|
case Value::ValueType::ddl_int8 : {
|
||||||
{
|
std::stringstream stream;
|
||||||
std::stringstream stream;
|
const int i = static_cast<int>(val->getInt8());
|
||||||
const int i = static_cast<int>( val->getInt8() );
|
stream << i;
|
||||||
stream << i;
|
statement += stream.str();
|
||||||
statement += stream.str();
|
} break;
|
||||||
}
|
case Value::ValueType::ddl_int16: {
|
||||||
|
std::stringstream stream;
|
||||||
|
char buffer[256];
|
||||||
|
::memset(buffer, '\0', 256 * sizeof(char));
|
||||||
|
sprintf(buffer, "%d", val->getInt16());
|
||||||
|
statement += buffer;
|
||||||
|
} break;
|
||||||
|
case Value::ValueType::ddl_int32: {
|
||||||
|
std::stringstream stream;
|
||||||
|
char buffer[256];
|
||||||
|
::memset(buffer, '\0', 256 * sizeof(char));
|
||||||
|
const int i = static_cast<int>(val->getInt32());
|
||||||
|
sprintf(buffer, "%d", i);
|
||||||
|
statement += buffer;
|
||||||
|
} break;
|
||||||
|
case Value::ValueType::ddl_int64: {
|
||||||
|
std::stringstream stream;
|
||||||
|
const int i = static_cast<int>(val->getInt64());
|
||||||
|
stream << i;
|
||||||
|
statement += stream.str();
|
||||||
|
} break;
|
||||||
|
case Value::ValueType::ddl_unsigned_int8: {
|
||||||
|
std::stringstream stream;
|
||||||
|
const int i = static_cast<unsigned int>(val->getUnsignedInt8());
|
||||||
|
stream << i;
|
||||||
|
statement += stream.str();
|
||||||
|
} break;
|
||||||
|
case Value::ValueType::ddl_unsigned_int16: {
|
||||||
|
std::stringstream stream;
|
||||||
|
const int i = static_cast<unsigned int>(val->getUnsignedInt16());
|
||||||
|
stream << i;
|
||||||
|
statement += stream.str();
|
||||||
|
} break;
|
||||||
|
case Value::ValueType::ddl_unsigned_int32: {
|
||||||
|
std::stringstream stream;
|
||||||
|
const int i = static_cast<unsigned int>(val->getUnsignedInt32());
|
||||||
|
stream << i;
|
||||||
|
statement += stream.str();
|
||||||
|
} break;
|
||||||
|
case Value::ValueType::ddl_unsigned_int64: {
|
||||||
|
std::stringstream stream;
|
||||||
|
const int i = static_cast<unsigned int>(val->getUnsignedInt64());
|
||||||
|
stream << i;
|
||||||
|
statement += stream.str();
|
||||||
|
} break;
|
||||||
|
case Value::ValueType::ddl_half:
|
||||||
break;
|
break;
|
||||||
case Value::ddl_int16:
|
case Value::ValueType::ddl_float: {
|
||||||
{
|
std::stringstream stream;
|
||||||
std::stringstream stream;
|
stream << val->getFloat();
|
||||||
char buffer[ 256 ];
|
statement += stream.str();
|
||||||
::memset( buffer, '\0', 256 * sizeof( char ) );
|
} break;
|
||||||
sprintf( buffer, "%d", val->getInt16() );
|
case Value::ValueType::ddl_double: {
|
||||||
statement += buffer;
|
std::stringstream stream;
|
||||||
}
|
stream << val->getDouble();
|
||||||
|
statement += stream.str();
|
||||||
|
} break;
|
||||||
|
case Value::ValueType::ddl_string: {
|
||||||
|
std::stringstream stream;
|
||||||
|
stream << val->getString();
|
||||||
|
statement += "\"";
|
||||||
|
statement += stream.str();
|
||||||
|
statement += "\"";
|
||||||
|
} break;
|
||||||
|
case Value::ValueType::ddl_ref:
|
||||||
break;
|
break;
|
||||||
case Value::ddl_int32:
|
case Value::ValueType::ddl_none:
|
||||||
{
|
case Value::ValueType::ddl_types_max:
|
||||||
std::stringstream stream;
|
|
||||||
char buffer[ 256 ];
|
|
||||||
::memset( buffer, '\0', 256 * sizeof( char ) );
|
|
||||||
const int i = static_cast< int >( val->getInt32() );
|
|
||||||
sprintf( buffer, "%d", i );
|
|
||||||
statement += buffer;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Value::ddl_int64:
|
|
||||||
{
|
|
||||||
std::stringstream stream;
|
|
||||||
const int i = static_cast< int >( val->getInt64() );
|
|
||||||
stream << i;
|
|
||||||
statement += stream.str();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Value::ddl_unsigned_int8:
|
|
||||||
{
|
|
||||||
std::stringstream stream;
|
|
||||||
const int i = static_cast< unsigned int >( val->getUnsignedInt8() );
|
|
||||||
stream << i;
|
|
||||||
statement += stream.str();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Value::ddl_unsigned_int16:
|
|
||||||
{
|
|
||||||
std::stringstream stream;
|
|
||||||
const int i = static_cast< unsigned int >( val->getUnsignedInt16() );
|
|
||||||
stream << i;
|
|
||||||
statement += stream.str();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Value::ddl_unsigned_int32:
|
|
||||||
{
|
|
||||||
std::stringstream stream;
|
|
||||||
const int i = static_cast< unsigned int >( val->getUnsignedInt32() );
|
|
||||||
stream << i;
|
|
||||||
statement += stream.str();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Value::ddl_unsigned_int64:
|
|
||||||
{
|
|
||||||
std::stringstream stream;
|
|
||||||
const int i = static_cast< unsigned int >( val->getUnsignedInt64() );
|
|
||||||
stream << i;
|
|
||||||
statement += stream.str();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Value::ddl_half:
|
|
||||||
break;
|
|
||||||
case Value::ddl_float:
|
|
||||||
{
|
|
||||||
std::stringstream stream;
|
|
||||||
stream << val->getFloat();
|
|
||||||
statement += stream.str();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Value::ddl_double:
|
|
||||||
{
|
|
||||||
std::stringstream stream;
|
|
||||||
stream << val->getDouble();
|
|
||||||
statement += stream.str();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Value::ddl_string:
|
|
||||||
{
|
|
||||||
std::stringstream stream;
|
|
||||||
stream << val->getString();
|
|
||||||
statement += "\"";
|
|
||||||
statement += stream.str();
|
|
||||||
statement += "\"";
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Value::ddl_ref:
|
|
||||||
break;
|
|
||||||
case Value::ddl_none:
|
|
||||||
case Value::ddl_types_max:
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -349,8 +327,8 @@ bool OpenDDLExport::writeValue( Value *val, std::string &statement ) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OpenDDLExport::writeValueArray( DataArrayList *al, std::string &statement ) {
|
bool OpenDDLExport::writeValueArray(DataArrayList *al, std::string &statement) {
|
||||||
if (ddl_nullptr == al) {
|
if (nullptr == al) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -358,17 +336,18 @@ bool OpenDDLExport::writeValueArray( DataArrayList *al, std::string &statement )
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
DataArrayList *nextDataArrayList = al ;
|
DataArrayList *nextDataArrayList = al;
|
||||||
while (ddl_nullptr != nextDataArrayList) {
|
Value *nextValue(nextDataArrayList->m_dataList);
|
||||||
if (ddl_nullptr != nextDataArrayList) {
|
while (nullptr != nextDataArrayList) {
|
||||||
|
if (nullptr != nextDataArrayList) {
|
||||||
statement += "{ ";
|
statement += "{ ";
|
||||||
Value *nextValue( nextDataArrayList->m_dataList );
|
nextValue = nextDataArrayList->m_dataList;
|
||||||
size_t idx( 0 );
|
size_t idx(0);
|
||||||
while (ddl_nullptr != nextValue) {
|
while (nullptr != nextValue) {
|
||||||
if (idx > 0) {
|
if (idx > 0) {
|
||||||
statement += ", ";
|
statement += ", ";
|
||||||
}
|
}
|
||||||
writeValue( nextValue, statement );
|
writeValue(nextValue, statement);
|
||||||
nextValue = nextValue->m_next;
|
nextValue = nextValue->m_next;
|
||||||
idx++;
|
idx++;
|
||||||
}
|
}
|
||||||
|
@ -381,4 +360,3 @@ bool OpenDDLExport::writeValueArray( DataArrayList *al, std::string &statement )
|
||||||
}
|
}
|
||||||
|
|
||||||
END_ODDLPARSER_NS
|
END_ODDLPARSER_NS
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,7 +1,7 @@
|
||||||
/*-----------------------------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------------------------
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2014-2015 Kim Kulling
|
Copyright (c) 2014-2020 Kim Kulling
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
this software and associated documentation files (the "Software"), to deal in
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
@ -37,22 +37,22 @@ std::string StreamFormatterBase::format(const std::string &statement) {
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
IOStreamBase::IOStreamBase(StreamFormatterBase *formatter)
|
IOStreamBase::IOStreamBase(StreamFormatterBase *formatter) :
|
||||||
: m_formatter(formatter)
|
m_formatter(formatter),
|
||||||
, m_file(ddl_nullptr) {
|
m_file(nullptr) {
|
||||||
if (ddl_nullptr == m_formatter) {
|
if (nullptr == m_formatter) {
|
||||||
m_formatter = new StreamFormatterBase;
|
m_formatter = new StreamFormatterBase;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IOStreamBase::~IOStreamBase() {
|
IOStreamBase::~IOStreamBase() {
|
||||||
delete m_formatter;
|
delete m_formatter;
|
||||||
m_formatter = ddl_nullptr;
|
m_formatter = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IOStreamBase::open(const std::string &name) {
|
bool IOStreamBase::open(const std::string &name) {
|
||||||
m_file = ::fopen(name.c_str(), "a");
|
m_file = ::fopen(name.c_str(), "a");
|
||||||
if (m_file == ddl_nullptr) {
|
if (m_file == nullptr) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,33 +60,33 @@ bool IOStreamBase::open(const std::string &name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IOStreamBase::close() {
|
bool IOStreamBase::close() {
|
||||||
if (ddl_nullptr == m_file) {
|
if (nullptr == m_file) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
::fclose(m_file);
|
::fclose(m_file);
|
||||||
m_file = ddl_nullptr;
|
m_file = nullptr;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IOStreamBase::isOpen() const {
|
bool IOStreamBase::isOpen() const {
|
||||||
return ( ddl_nullptr != m_file );
|
return (nullptr != m_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t IOStreamBase::read( size_t sizeToRead, std::string &statement ) {
|
size_t IOStreamBase::read(size_t sizeToRead, std::string &statement) {
|
||||||
if (ddl_nullptr == m_file) {
|
if (nullptr == m_file) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
statement.resize(sizeToRead);
|
statement.resize(sizeToRead);
|
||||||
const size_t readBytes = ::fread( &statement[0], 1, sizeToRead, m_file );
|
const size_t readBytes = ::fread(&statement[0], 1, sizeToRead, m_file);
|
||||||
|
|
||||||
return readBytes;
|
return readBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t IOStreamBase::write(const std::string &statement) {
|
size_t IOStreamBase::write(const std::string &statement) {
|
||||||
if (ddl_nullptr == m_file) {
|
if (nullptr == m_file) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
std::string formatStatement = m_formatter->format(statement);
|
std::string formatStatement = m_formatter->format(statement);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*-----------------------------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------------------------
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2014-2015 Kim Kulling
|
Copyright (c) 2014-2020 Kim Kulling
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
this software and associated documentation files (the "Software"), to deal in
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
@ -20,30 +20,30 @@ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
-----------------------------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------------------------*/
|
||||||
|
#include <openddlparser/OpenDDLStream.h>
|
||||||
#include <openddlparser/Value.h>
|
#include <openddlparser/Value.h>
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
BEGIN_ODDLPARSER_NS
|
BEGIN_ODDLPARSER_NS
|
||||||
|
|
||||||
static Value::Iterator end( ddl_nullptr );
|
static Value::Iterator end(nullptr);
|
||||||
|
|
||||||
Value::Iterator::Iterator()
|
Value::Iterator::Iterator() :
|
||||||
: m_start( ddl_nullptr )
|
m_start(nullptr),
|
||||||
, m_current( ddl_nullptr ) {
|
m_current(nullptr) {
|
||||||
// empty
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
Value::Iterator::Iterator( Value *start )
|
Value::Iterator::Iterator(Value *start) :
|
||||||
: m_start( start )
|
m_start(start),
|
||||||
, m_current( start ) {
|
m_current(start) {
|
||||||
// empty
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
Value::Iterator::Iterator( const Iterator &rhs )
|
Value::Iterator::Iterator(const Iterator &rhs) :
|
||||||
: m_start( rhs.m_start )
|
m_start(rhs.m_start),
|
||||||
, m_current( rhs.m_current ) {
|
m_current(rhs.m_current) {
|
||||||
// empty
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,36 +52,36 @@ Value::Iterator::~Iterator() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Value::Iterator::hasNext() const {
|
bool Value::Iterator::hasNext() const {
|
||||||
if( ddl_nullptr == m_current ) {
|
if (nullptr == m_current) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return ( ddl_nullptr != m_current->getNext() );
|
return (nullptr != m_current->getNext());
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *Value::Iterator::getNext() {
|
Value *Value::Iterator::getNext() {
|
||||||
if( !hasNext() ) {
|
if (!hasNext()) {
|
||||||
return ddl_nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *v( m_current->getNext() );
|
Value *v(m_current->getNext());
|
||||||
m_current = v;
|
m_current = v;
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Value::Iterator Value::Iterator::operator++( int ) {
|
const Value::Iterator Value::Iterator::operator++(int) {
|
||||||
if( ddl_nullptr == m_current ) {
|
if (nullptr == m_current) {
|
||||||
return end;
|
return end;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_current = m_current->getNext();
|
m_current = m_current->getNext();
|
||||||
Iterator inst( m_current );
|
Iterator inst(m_current);
|
||||||
|
|
||||||
return inst;
|
return inst;
|
||||||
}
|
}
|
||||||
|
|
||||||
Value::Iterator &Value::Iterator::operator++( ) {
|
Value::Iterator &Value::Iterator::operator++() {
|
||||||
if( ddl_nullptr == m_current ) {
|
if (nullptr == m_current) {
|
||||||
return end;
|
return end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,263 +90,261 @@ Value::Iterator &Value::Iterator::operator++( ) {
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Value::Iterator::operator == ( const Iterator &rhs ) const {
|
bool Value::Iterator::operator==(const Iterator &rhs) const {
|
||||||
return ( m_current == rhs.m_current );
|
return (m_current == rhs.m_current);
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *Value::Iterator::operator->( ) const {
|
Value *Value::Iterator::operator->() const {
|
||||||
if(ddl_nullptr == m_current ) {
|
if (nullptr == m_current) {
|
||||||
return ddl_nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return m_current;
|
return m_current;
|
||||||
}
|
}
|
||||||
|
|
||||||
Value::Value( ValueType type )
|
Value::Value(ValueType type) :
|
||||||
: m_type( type )
|
m_type(type),
|
||||||
, m_size( 0 )
|
m_size(0),
|
||||||
, m_data( ddl_nullptr )
|
m_data(nullptr),
|
||||||
, m_next( ddl_nullptr ) {
|
m_next(nullptr) {
|
||||||
// empty
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
Value::~Value() {
|
Value::~Value() {
|
||||||
if(m_data!=ddl_nullptr) {
|
if (m_data != nullptr) {
|
||||||
if (m_type == ddl_ref ) {
|
if (m_type == ValueType::ddl_ref) {
|
||||||
Reference *tmp = (Reference *) m_data;
|
Reference *tmp = (Reference *)m_data;
|
||||||
if (tmp != ddl_nullptr)
|
if (tmp != nullptr)
|
||||||
delete tmp;
|
delete tmp;
|
||||||
}else
|
} else
|
||||||
delete[] m_data;
|
delete[] m_data;
|
||||||
|
|
||||||
}
|
}
|
||||||
if(m_next!=ddl_nullptr)
|
if (m_next != nullptr)
|
||||||
delete m_next;
|
delete m_next;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Value::setBool( bool value ) {
|
void Value::setBool(bool value) {
|
||||||
assert( ddl_bool == m_type );
|
assert(ValueType::ddl_bool == m_type);
|
||||||
::memcpy( m_data, &value, m_size );
|
::memcpy(m_data, &value, m_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Value::getBool() {
|
bool Value::getBool() {
|
||||||
assert( ddl_bool == m_type );
|
assert(ValueType::ddl_bool == m_type);
|
||||||
return ( *m_data == 1 );
|
return (*m_data == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Value::setInt8( int8 value ) {
|
void Value::setInt8(int8 value) {
|
||||||
assert( ddl_int8 == m_type );
|
assert(ValueType::ddl_int8 == m_type);
|
||||||
::memcpy( m_data, &value, m_size );
|
::memcpy(m_data, &value, m_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
int8 Value::getInt8() {
|
int8 Value::getInt8() {
|
||||||
assert( ddl_int8 == m_type );
|
assert(ValueType::ddl_int8 == m_type);
|
||||||
return ( int8 ) ( *m_data );
|
return (int8)(*m_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Value::setInt16( int16 value ) {
|
void Value::setInt16(int16 value) {
|
||||||
assert( ddl_int16 == m_type );
|
assert(ValueType::ddl_int16 == m_type);
|
||||||
::memcpy( m_data, &value, m_size );
|
::memcpy(m_data, &value, m_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
int16 Value::getInt16() {
|
int16 Value::getInt16() {
|
||||||
assert( ddl_int16 == m_type );
|
assert(ValueType::ddl_int16 == m_type);
|
||||||
int16 i;
|
int16 i;
|
||||||
::memcpy( &i, m_data, m_size );
|
::memcpy(&i, m_data, m_size);
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Value::setInt32( int32 value ) {
|
void Value::setInt32(int32 value) {
|
||||||
assert( ddl_int32 == m_type );
|
assert(ValueType::ddl_int32 == m_type);
|
||||||
::memcpy( m_data, &value, m_size );
|
::memcpy(m_data, &value, m_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32 Value::getInt32() {
|
int32 Value::getInt32() {
|
||||||
assert( ddl_int32 == m_type );
|
assert(ValueType::ddl_int32 == m_type);
|
||||||
int32 i;
|
int32 i;
|
||||||
::memcpy( &i, m_data, m_size );
|
::memcpy(&i, m_data, m_size);
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Value::setInt64( int64 value ) {
|
void Value::setInt64(int64 value) {
|
||||||
assert( ddl_int64 == m_type );
|
assert(ValueType::ddl_int64 == m_type);
|
||||||
::memcpy( m_data, &value, m_size );
|
::memcpy(m_data, &value, m_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64 Value::getInt64() {
|
int64 Value::getInt64() {
|
||||||
assert( ddl_int64 == m_type );
|
assert(ValueType::ddl_int64 == m_type);
|
||||||
int64 i;
|
int64 i;
|
||||||
::memcpy( &i, m_data, m_size );
|
::memcpy(&i, m_data, m_size);
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Value::setUnsignedInt8( uint8 value ) {
|
void Value::setUnsignedInt8(uint8 value) {
|
||||||
assert( ddl_unsigned_int8 == m_type );
|
assert(ValueType::ddl_unsigned_int8 == m_type);
|
||||||
::memcpy( m_data, &value, m_size );
|
::memcpy(m_data, &value, m_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8 Value::getUnsignedInt8() const {
|
uint8 Value::getUnsignedInt8() const {
|
||||||
assert( ddl_unsigned_int8 == m_type );
|
assert(ValueType::ddl_unsigned_int8 == m_type);
|
||||||
uint8 i;
|
uint8 i;
|
||||||
::memcpy( &i, m_data, m_size );
|
::memcpy(&i, m_data, m_size);
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Value::setUnsignedInt16( uint16 value ) {
|
void Value::setUnsignedInt16(uint16 value) {
|
||||||
assert( ddl_unsigned_int16 == m_type );
|
assert(ValueType::ddl_unsigned_int16 == m_type);
|
||||||
::memcpy( m_data, &value, m_size );
|
::memcpy(m_data, &value, m_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16 Value::getUnsignedInt16() const {
|
uint16 Value::getUnsignedInt16() const {
|
||||||
assert( ddl_unsigned_int16 == m_type );
|
assert(ValueType::ddl_unsigned_int16 == m_type);
|
||||||
uint16 i;
|
uint16 i;
|
||||||
::memcpy( &i, m_data, m_size );
|
::memcpy(&i, m_data, m_size);
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Value::setUnsignedInt32( uint32 value ) {
|
void Value::setUnsignedInt32(uint32 value) {
|
||||||
assert( ddl_unsigned_int32 == m_type );
|
assert(ValueType::ddl_unsigned_int32 == m_type);
|
||||||
::memcpy( m_data, &value, m_size );
|
::memcpy(m_data, &value, m_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 Value::getUnsignedInt32() const {
|
uint32 Value::getUnsignedInt32() const {
|
||||||
assert( ddl_unsigned_int32 == m_type );
|
assert(ValueType::ddl_unsigned_int32 == m_type);
|
||||||
uint32 i;
|
uint32 i;
|
||||||
::memcpy( &i, m_data, m_size );
|
::memcpy(&i, m_data, m_size);
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Value::setUnsignedInt64( uint64 value ) {
|
void Value::setUnsignedInt64(uint64 value) {
|
||||||
assert( ddl_unsigned_int64 == m_type );
|
assert(ValueType::ddl_unsigned_int64 == m_type);
|
||||||
::memcpy( m_data, &value, m_size );
|
::memcpy(m_data, &value, m_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64 Value::getUnsignedInt64() const {
|
uint64 Value::getUnsignedInt64() const {
|
||||||
assert( ddl_unsigned_int64 == m_type );
|
assert(ValueType::ddl_unsigned_int64 == m_type);
|
||||||
uint64 i;
|
uint64 i;
|
||||||
::memcpy( &i, m_data, m_size );
|
::memcpy(&i, m_data, m_size);
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Value::setFloat( float value ) {
|
void Value::setFloat(float value) {
|
||||||
assert( ddl_float == m_type );
|
assert(ValueType::ddl_float == m_type);
|
||||||
::memcpy( m_data, &value, m_size );
|
::memcpy(m_data, &value, m_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
float Value::getFloat() const {
|
float Value::getFloat() const {
|
||||||
if( m_type == ddl_float ) {
|
if (m_type == ValueType::ddl_float) {
|
||||||
float v;
|
float v;
|
||||||
::memcpy( &v, m_data, m_size );
|
::memcpy(&v, m_data, m_size);
|
||||||
return ( float ) v;
|
return (float)v;
|
||||||
} else {
|
} else {
|
||||||
float tmp;
|
float tmp;
|
||||||
::memcpy( &tmp, m_data, 4 );
|
::memcpy(&tmp, m_data, 4);
|
||||||
return ( float ) tmp;
|
return (float)tmp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Value::setDouble( double value ) {
|
void Value::setDouble(double value) {
|
||||||
assert( ddl_double == m_type );
|
assert(ValueType::ddl_double == m_type);
|
||||||
::memcpy( m_data, &value, m_size );
|
::memcpy(m_data, &value, m_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
double Value::getDouble() const {
|
double Value::getDouble() const {
|
||||||
if ( m_type == ddl_double ) {
|
if (m_type == ValueType::ddl_double) {
|
||||||
double v;
|
double v;
|
||||||
::memcpy( &v, m_data, m_size );
|
::memcpy(&v, m_data, m_size);
|
||||||
return ( float ) v;
|
return (float)v;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
double tmp;
|
double tmp;
|
||||||
::memcpy( &tmp, m_data, 4 );
|
::memcpy(&tmp, m_data, 4);
|
||||||
return ( double ) tmp;
|
return (double)tmp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Value::setString( const std::string &str ) {
|
void Value::setString(const std::string &str) {
|
||||||
assert( ddl_string == m_type );
|
assert(ValueType::ddl_string == m_type);
|
||||||
::memcpy( m_data, str.c_str(), str.size() );
|
::memcpy(m_data, str.c_str(), str.size());
|
||||||
m_data[ str.size() ] = '\0';
|
m_data[str.size()] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *Value::getString() const {
|
const char *Value::getString() const {
|
||||||
assert( ddl_string == m_type );
|
assert(ValueType::ddl_string == m_type);
|
||||||
return (const char*) m_data;
|
return (const char *)m_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Value::setRef( Reference *ref ) {
|
void Value::setRef(Reference *ref) {
|
||||||
assert( ddl_ref == m_type );
|
assert(ValueType::ddl_ref == m_type);
|
||||||
|
|
||||||
if ( ddl_nullptr != ref ) {
|
if (nullptr != ref) {
|
||||||
const size_t sizeInBytes( ref->sizeInBytes() );
|
const size_t sizeInBytes(ref->sizeInBytes());
|
||||||
if ( sizeInBytes > 0 ) {
|
if (sizeInBytes > 0) {
|
||||||
if ( ddl_nullptr != m_data ) {
|
if (nullptr != m_data) {
|
||||||
delete [] m_data;
|
delete[] m_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_data = (unsigned char*) new Reference(*ref);
|
m_data = (unsigned char *)new Reference(*ref);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference *Value::getRef() const {
|
Reference *Value::getRef() const {
|
||||||
assert( ddl_ref == m_type );
|
assert(ValueType::ddl_ref == m_type);
|
||||||
|
|
||||||
return (Reference*) m_data;
|
return (Reference *)m_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Value::dump( IOStreamBase &/*stream*/ ) {
|
void Value::dump(IOStreamBase &stream) {
|
||||||
switch( m_type ) {
|
switch (m_type) {
|
||||||
case ddl_none:
|
case ValueType::ddl_none:
|
||||||
std::cout << "None" << std::endl;
|
stream.write("None\n");
|
||||||
break;
|
break;
|
||||||
case ddl_bool:
|
case ValueType::ddl_bool:
|
||||||
std::cout << getBool() << std::endl;
|
stream.write(std::to_string(getBool()) + "\n");
|
||||||
break;
|
break;
|
||||||
case ddl_int8:
|
case ValueType::ddl_int8:
|
||||||
std::cout << getInt8() << std::endl;
|
stream.write(std::to_string(getInt8()) + "\n");
|
||||||
break;
|
break;
|
||||||
case ddl_int16:
|
case ValueType::ddl_int16:
|
||||||
std::cout << getInt16() << std::endl;
|
stream.write(std::to_string(getInt16()) + "\n");
|
||||||
break;
|
break;
|
||||||
case ddl_int32:
|
case ValueType::ddl_int32:
|
||||||
std::cout << getInt32() << std::endl;
|
stream.write(std::to_string(getInt32()) + "\n");
|
||||||
break;
|
break;
|
||||||
case ddl_int64:
|
case ValueType::ddl_int64:
|
||||||
std::cout << getInt64() << std::endl;
|
stream.write(std::to_string(getInt64()) + "\n");
|
||||||
break;
|
break;
|
||||||
case ddl_unsigned_int8:
|
case ValueType::ddl_unsigned_int8:
|
||||||
std::cout << "Not supported" << std::endl;
|
stream.write("Not supported\n");
|
||||||
break;
|
break;
|
||||||
case ddl_unsigned_int16:
|
case ValueType::ddl_unsigned_int16:
|
||||||
std::cout << "Not supported" << std::endl;
|
stream.write("Not supported\n");
|
||||||
break;
|
break;
|
||||||
case ddl_unsigned_int32:
|
case ValueType::ddl_unsigned_int32:
|
||||||
std::cout << "Not supported" << std::endl;
|
stream.write("Not supported\n");
|
||||||
break;
|
break;
|
||||||
case ddl_unsigned_int64:
|
case ValueType::ddl_unsigned_int64:
|
||||||
std::cout << "Not supported" << std::endl;
|
stream.write("Not supported\n");
|
||||||
break;
|
break;
|
||||||
case ddl_half:
|
case ValueType::ddl_half:
|
||||||
std::cout << "Not supported" << std::endl;
|
stream.write("Not supported\n");
|
||||||
break;
|
break;
|
||||||
case ddl_float:
|
case ValueType::ddl_float:
|
||||||
std::cout << getFloat() << std::endl;
|
stream.write(std::to_string(getFloat()) + "\n");
|
||||||
break;
|
break;
|
||||||
case ddl_double:
|
case ValueType::ddl_double:
|
||||||
std::cout << getDouble() << std::endl;
|
stream.write(std::to_string(getDouble()) + "\n");
|
||||||
break;
|
break;
|
||||||
case ddl_string:
|
case ValueType::ddl_string:
|
||||||
std::cout << getString() << std::endl;
|
stream.write(std::string(getString()) + "\n");
|
||||||
break;
|
break;
|
||||||
case ddl_ref:
|
case ValueType::ddl_ref:
|
||||||
std::cout << "Not supported" << std::endl;
|
stream.write("Not supported\n");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Value::setNext( Value *next ) {
|
void Value::setNext(Value *next) {
|
||||||
m_next = next;
|
m_next = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -354,86 +352,86 @@ Value *Value::getNext() const {
|
||||||
return m_next;
|
return m_next;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Value::size() const{
|
size_t Value::size() const {
|
||||||
size_t result=1;
|
size_t result = 1;
|
||||||
Value *n=m_next;
|
Value *n = m_next;
|
||||||
while( n!=ddl_nullptr) {
|
while (n != nullptr) {
|
||||||
result++;
|
result++;
|
||||||
n=n->m_next;
|
n = n->m_next;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *ValueAllocator::allocPrimData( Value::ValueType type, size_t len ) {
|
Value *ValueAllocator::allocPrimData(Value::ValueType type, size_t len) {
|
||||||
if( type == Value::ddl_none || Value::ddl_types_max == type ) {
|
if (type == Value::ValueType::ddl_none || Value::ValueType::ddl_types_max == type) {
|
||||||
return ddl_nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *data = new Value( type );
|
Value *data = new Value(type);
|
||||||
switch( type ) {
|
switch (type) {
|
||||||
case Value::ddl_bool:
|
case Value::ValueType::ddl_bool:
|
||||||
data->m_size = sizeof( bool );
|
data->m_size = sizeof(bool);
|
||||||
break;
|
break;
|
||||||
case Value::ddl_int8:
|
case Value::ValueType::ddl_int8:
|
||||||
data->m_size = sizeof( int8 );
|
data->m_size = sizeof(int8);
|
||||||
break;
|
break;
|
||||||
case Value::ddl_int16:
|
case Value::ValueType::ddl_int16:
|
||||||
data->m_size = sizeof( int16 );
|
data->m_size = sizeof(int16);
|
||||||
break;
|
break;
|
||||||
case Value::ddl_int32:
|
case Value::ValueType::ddl_int32:
|
||||||
data->m_size = sizeof( int32 );
|
data->m_size = sizeof(int32);
|
||||||
break;
|
break;
|
||||||
case Value::ddl_int64:
|
case Value::ValueType::ddl_int64:
|
||||||
data->m_size = sizeof( int64 );
|
data->m_size = sizeof(int64);
|
||||||
break;
|
break;
|
||||||
case Value::ddl_unsigned_int8:
|
case Value::ValueType::ddl_unsigned_int8:
|
||||||
data->m_size = sizeof( uint8 );
|
data->m_size = sizeof(uint8);
|
||||||
break;
|
break;
|
||||||
case Value::ddl_unsigned_int16:
|
case Value::ValueType::ddl_unsigned_int16:
|
||||||
data->m_size = sizeof( uint16 );
|
data->m_size = sizeof(uint16);
|
||||||
break;
|
break;
|
||||||
case Value::ddl_unsigned_int32:
|
case Value::ValueType::ddl_unsigned_int32:
|
||||||
data->m_size = sizeof( uint32 );
|
data->m_size = sizeof(uint32);
|
||||||
break;
|
break;
|
||||||
case Value::ddl_unsigned_int64:
|
case Value::ValueType::ddl_unsigned_int64:
|
||||||
data->m_size = sizeof( uint64 );
|
data->m_size = sizeof(uint64);
|
||||||
break;
|
break;
|
||||||
case Value::ddl_half:
|
case Value::ValueType::ddl_half:
|
||||||
data->m_size = sizeof( short );
|
data->m_size = sizeof(short);
|
||||||
break;
|
break;
|
||||||
case Value::ddl_float:
|
case Value::ValueType::ddl_float:
|
||||||
data->m_size = sizeof( float );
|
data->m_size = sizeof(float);
|
||||||
break;
|
break;
|
||||||
case Value::ddl_double:
|
case Value::ValueType::ddl_double:
|
||||||
data->m_size = sizeof( double );
|
data->m_size = sizeof(double);
|
||||||
break;
|
break;
|
||||||
case Value::ddl_string:
|
case Value::ValueType::ddl_string:
|
||||||
data->m_size = sizeof( char )*(len+1);
|
data->m_size = sizeof(char) * (len + 1);
|
||||||
break;
|
break;
|
||||||
case Value::ddl_ref:
|
case Value::ValueType::ddl_ref:
|
||||||
data->m_size = 0;
|
data->m_size = 0;
|
||||||
break;
|
break;
|
||||||
case Value::ddl_none:
|
case Value::ValueType::ddl_none:
|
||||||
case Value::ddl_types_max:
|
case Value::ValueType::ddl_types_max:
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( data->m_size ) {
|
if (data->m_size) {
|
||||||
data->m_data = new unsigned char[ data->m_size ];
|
data->m_data = new unsigned char[data->m_size];
|
||||||
::memset(data->m_data,0,data->m_size);
|
::memset(data->m_data, 0, data->m_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ValueAllocator::releasePrimData( Value **data ) {
|
void ValueAllocator::releasePrimData(Value **data) {
|
||||||
if( !data ) {
|
if (!data) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete *data;
|
delete *data;
|
||||||
*data = ddl_nullptr;
|
*data = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
END_ODDLPARSER_NS
|
END_ODDLPARSER_NS
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*-----------------------------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------------------------
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2014-2015 Kim Kulling
|
Copyright (c) 2014-2020 Kim Kulling
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
this software and associated documentation files (the "Software"), to deal in
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
@ -24,8 +24,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
#include <openddlparser/OpenDDLCommon.h>
|
#include <openddlparser/OpenDDLCommon.h>
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
BEGIN_ODDLPARSER_NS
|
BEGIN_ODDLPARSER_NS
|
||||||
|
|
||||||
|
@ -53,10 +53,10 @@ public:
|
||||||
friend class OpenDDLParser;
|
friend class OpenDDLParser;
|
||||||
|
|
||||||
/// @brief The child-node-list type.
|
/// @brief The child-node-list type.
|
||||||
typedef std::vector<DDLNode*> DllNodeList;
|
typedef std::vector<DDLNode *> DllNodeList;
|
||||||
|
|
||||||
/// @brief The child-node-list iterator.
|
/// @brief The child-node-list iterator.
|
||||||
typedef std::vector<DDLNode*>::iterator DDLNodeIt;
|
typedef std::vector<DDLNode *>::iterator DDLNodeIt;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// @brief The class destructor.
|
/// @brief The class destructor.
|
||||||
|
@ -64,7 +64,7 @@ public:
|
||||||
|
|
||||||
/// @brief Will attach a parent node instance, an older one will be released.
|
/// @brief Will attach a parent node instance, an older one will be released.
|
||||||
/// @param parent [in] The parent node instance.
|
/// @param parent [in] The parent node instance.
|
||||||
void attachParent( DDLNode *parent );
|
void attachParent(DDLNode *parent);
|
||||||
|
|
||||||
/// @brief Will try to detach a parent node instance, if there is any.
|
/// @brief Will try to detach a parent node instance, if there is any.
|
||||||
void detachParent();
|
void detachParent();
|
||||||
|
@ -79,7 +79,7 @@ public:
|
||||||
|
|
||||||
/// Set the type of the DDLNode instance.
|
/// Set the type of the DDLNode instance.
|
||||||
/// @param type [in] The type.
|
/// @param type [in] The type.
|
||||||
void setType( const std::string &type );
|
void setType(const std::string &type);
|
||||||
|
|
||||||
/// @brief Returns the type of the DDLNode instance.
|
/// @brief Returns the type of the DDLNode instance.
|
||||||
/// @return The type of the DDLNode instance.
|
/// @return The type of the DDLNode instance.
|
||||||
|
@ -87,7 +87,7 @@ public:
|
||||||
|
|
||||||
/// Set the name of the DDLNode instance.
|
/// Set the name of the DDLNode instance.
|
||||||
/// @param name [in] The name.
|
/// @param name [in] The name.
|
||||||
void setName( const std::string &name );
|
void setName(const std::string &name);
|
||||||
|
|
||||||
/// @brief Returns the name of the DDLNode instance.
|
/// @brief Returns the name of the DDLNode instance.
|
||||||
/// @return The name of the DDLNode instance.
|
/// @return The name of the DDLNode instance.
|
||||||
|
@ -95,7 +95,7 @@ public:
|
||||||
|
|
||||||
/// @brief Set a new property set.
|
/// @brief Set a new property set.
|
||||||
/// @param prop [in] The first element of the property set.
|
/// @param prop [in] The first element of the property set.
|
||||||
void setProperties( Property *prop );
|
void setProperties(Property *prop);
|
||||||
|
|
||||||
/// @brief Returns the first element of the assigned property set.
|
/// @brief Returns the first element of the assigned property set.
|
||||||
/// @return The first property of the assigned property set.
|
/// @return The first property of the assigned property set.
|
||||||
|
@ -104,7 +104,7 @@ public:
|
||||||
/// @brief Looks for a given property.
|
/// @brief Looks for a given property.
|
||||||
/// @param name [in] The name for the property to look for.
|
/// @param name [in] The name for the property to look for.
|
||||||
/// @return true, if a corresponding property is assigned to the node, false if not.
|
/// @return true, if a corresponding property is assigned to the node, false if not.
|
||||||
bool hasProperty( const std::string &name );
|
bool hasProperty(const std::string &name);
|
||||||
|
|
||||||
/// @brief Will return true, if any properties are assigned to the node instance.
|
/// @brief Will return true, if any properties are assigned to the node instance.
|
||||||
/// @return True, if properties are assigned.
|
/// @return True, if properties are assigned.
|
||||||
|
@ -113,11 +113,11 @@ public:
|
||||||
/// @brief Search for a given property and returns it. Will return ddl_nullptr if no property was found.
|
/// @brief Search for a given property and returns it. Will return ddl_nullptr if no property was found.
|
||||||
/// @param name [in] The name for the property to look for.
|
/// @param name [in] The name for the property to look for.
|
||||||
/// @return The property or ddl_nullptr if no property was found.
|
/// @return The property or ddl_nullptr if no property was found.
|
||||||
Property *findPropertyByName( const std::string &name );
|
Property *findPropertyByName(const std::string &name);
|
||||||
|
|
||||||
/// @brief Set a new value set.
|
/// @brief Set a new value set.
|
||||||
/// @param val [in] The first value instance of the value set.
|
/// @param val [in] The first value instance of the value set.
|
||||||
void setValue( Value *val );
|
void setValue(Value *val);
|
||||||
|
|
||||||
/// @brief Returns the first element of the assigned value set.
|
/// @brief Returns the first element of the assigned value set.
|
||||||
/// @return The first property of the assigned value set.
|
/// @return The first property of the assigned value set.
|
||||||
|
@ -125,7 +125,7 @@ public:
|
||||||
|
|
||||||
/// @brief Set a new DataArrayList.
|
/// @brief Set a new DataArrayList.
|
||||||
/// @param dtArrayList [in] The DataArrayList instance.
|
/// @param dtArrayList [in] The DataArrayList instance.
|
||||||
void setDataArrayList( DataArrayList *dtArrayList );
|
void setDataArrayList(DataArrayList *dtArrayList);
|
||||||
|
|
||||||
/// @brief Returns the DataArrayList.
|
/// @brief Returns the DataArrayList.
|
||||||
/// @return The DataArrayList.
|
/// @return The DataArrayList.
|
||||||
|
@ -133,7 +133,7 @@ public:
|
||||||
|
|
||||||
/// @brief Set a new Reference set.
|
/// @brief Set a new Reference set.
|
||||||
/// @param refs [in] The first value instance of the Reference set.
|
/// @param refs [in] The first value instance of the Reference set.
|
||||||
void setReferences( Reference *refs );
|
void setReferences(Reference *refs);
|
||||||
|
|
||||||
/// @brief Returns the first element of the assigned Reference set.
|
/// @brief Returns the first element of the assigned Reference set.
|
||||||
/// @return The first property of the assigned Reference set.
|
/// @return The first property of the assigned Reference set.
|
||||||
|
@ -148,20 +148,20 @@ public:
|
||||||
/// @param name [in] The name for the new DDLNode instance.
|
/// @param name [in] The name for the new DDLNode instance.
|
||||||
/// @param parent [in] The parent node instance or ddl_nullptr if no parent node is there.
|
/// @param parent [in] The parent node instance or ddl_nullptr if no parent node is there.
|
||||||
/// @return The new created node instance.
|
/// @return The new created node instance.
|
||||||
static DDLNode *create( const std::string &type, const std::string &name, DDLNode *parent = ddl_nullptr );
|
static DDLNode *create(const std::string &type, const std::string &name, DDLNode *parent = nullptr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DDLNode( const std::string &type, const std::string &name, size_t idx, DDLNode *parent = ddl_nullptr );
|
DDLNode(const std::string &type, const std::string &name, size_t idx, DDLNode *parent = nullptr);
|
||||||
DDLNode();
|
DDLNode();
|
||||||
DDLNode( const DDLNode & ) ddl_no_copy;
|
DDLNode(const DDLNode &) ddl_no_copy;
|
||||||
DDLNode &operator = ( const DDLNode & ) ddl_no_copy;
|
DDLNode &operator=(const DDLNode &) ddl_no_copy;
|
||||||
static void releaseNodes();
|
static void releaseNodes();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_type;
|
std::string m_type;
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
DDLNode *m_parent;
|
DDLNode *m_parent;
|
||||||
std::vector<DDLNode*> m_children;
|
std::vector<DDLNode *> m_children;
|
||||||
Property *m_properties;
|
Property *m_properties;
|
||||||
Value *m_value;
|
Value *m_value;
|
||||||
DataArrayList *m_dtArrayList;
|
DataArrayList *m_dtArrayList;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*-----------------------------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------------------------
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2014-2015 Kim Kulling
|
Copyright (c) 2014-2020 Kim Kulling
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
this software and associated documentation files (the "Software"), to deal in
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
@ -23,49 +23,49 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
# include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(_MSC_VER) && !defined( OPENDDL_STATIC_LIBARY )
|
#if defined(_MSC_VER) && !defined(OPENDDL_STATIC_LIBARY)
|
||||||
|
|
||||||
# define TAG_DLL_EXPORT __declspec(dllexport)
|
#define TAG_DLL_EXPORT __declspec(dllexport)
|
||||||
# define TAG_DLL_IMPORT __declspec(dllimport )
|
#define TAG_DLL_IMPORT __declspec(dllimport)
|
||||||
# ifdef OPENDDLPARSER_BUILD
|
#ifdef OPENDDLPARSER_BUILD
|
||||||
# define DLL_ODDLPARSER_EXPORT TAG_DLL_EXPORT
|
#define DLL_ODDLPARSER_EXPORT TAG_DLL_EXPORT
|
||||||
# else
|
|
||||||
# define DLL_ODDLPARSER_EXPORT TAG_DLL_IMPORT
|
|
||||||
# endif // OPENDDLPARSER_BUILD
|
|
||||||
# pragma warning( disable : 4251 )
|
|
||||||
#else
|
#else
|
||||||
# define DLL_ODDLPARSER_EXPORT
|
#define DLL_ODDLPARSER_EXPORT TAG_DLL_IMPORT
|
||||||
|
#endif // OPENDDLPARSER_BUILD
|
||||||
|
#pragma warning(disable : 4251)
|
||||||
|
#else
|
||||||
|
#define DLL_ODDLPARSER_EXPORT
|
||||||
#endif // _WIN32
|
#endif // _WIN32
|
||||||
|
|
||||||
// Namespace declarations, override this to avoid any conflicts
|
// Namespace declarations, override this to avoid any conflicts
|
||||||
#define BEGIN_ODDLPARSER_NS namespace ODDLParser {
|
#define BEGIN_ODDLPARSER_NS namespace ODDLParser {
|
||||||
#define END_ODDLPARSER_NS } // namespace ODDLParser
|
#define END_ODDLPARSER_NS } // namespace ODDLParser
|
||||||
#define USE_ODDLPARSER_NS using namespace ODDLParser;
|
#define USE_ODDLPARSER_NS using namespace ODDLParser;
|
||||||
|
|
||||||
BEGIN_ODDLPARSER_NS
|
BEGIN_ODDLPARSER_NS
|
||||||
|
|
||||||
// We will use C++11 optional
|
// We will use C++11 optional
|
||||||
#ifndef OPENDDL_NO_USE_CPP11
|
#ifndef OPENDDL_NO_USE_CPP11
|
||||||
// All C++11 constructs
|
// All C++11 constructs
|
||||||
# define ddl_nullptr nullptr
|
#define nullptr nullptr
|
||||||
# define ddl_override override
|
#define ddl_override override
|
||||||
# define ddl_final final
|
#define ddl_final final
|
||||||
# define ddl_no_copy = delete
|
#define ddl_no_copy = delete
|
||||||
#else
|
#else
|
||||||
// Fall-back for older compilers
|
// Fall-back for older compilers
|
||||||
# define ddl_nullptr NULL
|
#define nullptr NULL
|
||||||
# define ddl_override
|
#define ddl_override
|
||||||
# define ddl_final
|
#define ddl_final
|
||||||
# define ddl_no_copy
|
#define ddl_no_copy
|
||||||
#endif // OPENDDL_NO_USE_CPP11
|
#endif // OPENDDL_NO_USE_CPP11
|
||||||
|
|
||||||
// Forward declarations
|
// Forward declarations
|
||||||
|
@ -80,36 +80,36 @@ struct DataArrayList;
|
||||||
|
|
||||||
// Platform-specific typedefs
|
// Platform-specific typedefs
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
typedef signed __int64 int64_impl;
|
typedef signed __int64 int64_impl;
|
||||||
typedef unsigned __int64 uint64_impl;
|
typedef unsigned __int64 uint64_impl;
|
||||||
#else
|
#else
|
||||||
typedef int64_t int64_impl;
|
typedef int64_t int64_impl;
|
||||||
typedef uint64_t uint64_impl;
|
typedef uint64_t uint64_impl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// OpenDDL-specific data typedefs
|
// OpenDDL-specific data typedefs
|
||||||
typedef signed char int8; ///< Signed integer, 1 byte
|
using int8 = signed char; ///< Signed integer, 1 byte
|
||||||
typedef signed short int16; ///< Signed integer, 2 byte
|
using int16 = signed short; ///< Signed integer, 2 byte
|
||||||
typedef signed int int32; ///< Signed integer, 4 byte
|
using int32 = signed int; ///< Signed integer, 4 byte
|
||||||
typedef int64_impl int64; ///< Signed integer, 8 byte
|
using int64 = int64_impl; ///< Signed integer, 8 byte
|
||||||
typedef unsigned char uint8; ///< Unsigned integer, 1 byte
|
using uint8 = unsigned char; ///< Unsigned integer, 1 byte
|
||||||
typedef unsigned short uint16; ///< Unsigned integer, 2 byte
|
using uint16 = unsigned short ; ///< Unsigned integer, 2 byte
|
||||||
typedef unsigned int uint32; ///< Unsigned integer, 4 byte
|
using uint32 = unsigned int; ///< Unsigned integer, 4 byte
|
||||||
typedef uint64_impl uint64; ///< Unsigned integer, 8 byte
|
using uint64 = uint64_impl ; ///< Unsigned integer, 8 byte
|
||||||
|
|
||||||
/// @brief Stores a text.
|
/// @brief Stores a text.
|
||||||
///
|
///
|
||||||
/// A text is stored in a simple character buffer. Texts buffer can be
|
/// A text is stored in a simple character buffer. Texts buffer can be
|
||||||
/// greater than the number of stored characters in them.
|
/// greater than the number of stored characters in them.
|
||||||
struct DLL_ODDLPARSER_EXPORT Text {
|
struct DLL_ODDLPARSER_EXPORT Text {
|
||||||
size_t m_capacity; ///< The capacity of the text.
|
size_t m_capacity; ///< The capacity of the text.
|
||||||
size_t m_len; ///< The length of the text.
|
size_t m_len; ///< The length of the text.
|
||||||
char *m_buffer; ///< The buffer with the text.
|
char *m_buffer; ///< The buffer with the text.
|
||||||
|
|
||||||
/// @brief The constructor with a given text buffer.
|
/// @brief The constructor with a given text buffer.
|
||||||
/// @param buffer [in] The buffer.
|
/// @param buffer [in] The buffer.
|
||||||
/// @param numChars [in] The number of characters in the buffer.
|
/// @param numChars [in] The number of characters in the buffer.
|
||||||
Text( const char *buffer, size_t numChars );
|
Text(const char *buffer, size_t numChars);
|
||||||
|
|
||||||
/// @brief The destructor.
|
/// @brief The destructor.
|
||||||
~Text();
|
~Text();
|
||||||
|
@ -120,55 +120,54 @@ struct DLL_ODDLPARSER_EXPORT Text {
|
||||||
/// @brief Set a new text.
|
/// @brief Set a new text.
|
||||||
/// @param buffer [in] The buffer.
|
/// @param buffer [in] The buffer.
|
||||||
/// @param numChars [in] The number of characters in the buffer.
|
/// @param numChars [in] The number of characters in the buffer.
|
||||||
void set( const char *buffer, size_t numChars );
|
void set(const char *buffer, size_t numChars);
|
||||||
|
|
||||||
/// @brief The compare operator for std::strings.
|
/// @brief The compare operator for std::strings.
|
||||||
bool operator == ( const std::string &name ) const;
|
bool operator==(const std::string &name) const;
|
||||||
|
|
||||||
/// @brief The compare operator for Texts.
|
/// @brief The compare operator for Texts.
|
||||||
bool operator == ( const Text &rhs ) const;
|
bool operator==(const Text &rhs) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Text( const Text & ) ddl_no_copy;
|
Text(const Text &) ddl_no_copy;
|
||||||
Text &operator = ( const Text & ) ddl_no_copy;
|
Text &operator=(const Text &) ddl_no_copy;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief Description of the type of a name.
|
/// @brief Description of the type of a name.
|
||||||
enum NameType {
|
enum NameType {
|
||||||
GlobalName, ///< Name is global.
|
GlobalName, ///< Name is global.
|
||||||
LocalName ///< Name is local.
|
LocalName ///< Name is local.
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief Stores an OpenDDL-specific name
|
/// @brief Stores an OpenDDL-specific name
|
||||||
struct DLL_ODDLPARSER_EXPORT Name {
|
struct DLL_ODDLPARSER_EXPORT Name {
|
||||||
NameType m_type; ///< The type of the name ( @see NameType ).
|
NameType m_type; ///< The type of the name ( @see NameType ).
|
||||||
Text *m_id; ///< The id.
|
Text *m_id; ///< The id.
|
||||||
|
|
||||||
/// @brief The constructor with the type and the id.
|
/// @brief The constructor with the type and the id.
|
||||||
/// @param type [in] The name type.
|
/// @param type [in] The name type.
|
||||||
/// @param id [in] The id.
|
/// @param id [in] The id.
|
||||||
Name( NameType type, Text *id );
|
Name(NameType type, Text *id);
|
||||||
Name( const Name &name );
|
Name(const Name &name);
|
||||||
/// @brief The destructor.
|
/// @brief The destructor.
|
||||||
~Name();
|
~Name();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Name &operator=(const Name &) ddl_no_copy;
|
||||||
Name &operator = ( const Name& ) ddl_no_copy;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief Stores a bundle of references.
|
/// @brief Stores a bundle of references.
|
||||||
struct DLL_ODDLPARSER_EXPORT Reference {
|
struct DLL_ODDLPARSER_EXPORT Reference {
|
||||||
size_t m_numRefs; ///< The number of stored references.
|
size_t m_numRefs; ///< The number of stored references.
|
||||||
Name **m_referencedName; ///< The reference names.
|
Name **m_referencedName; ///< The reference names.
|
||||||
|
|
||||||
/// @brief The default constructor.
|
/// @brief The default constructor.
|
||||||
Reference();
|
Reference();
|
||||||
Reference( const Reference &ref );
|
Reference(const Reference &ref);
|
||||||
/// @brief The constructor with an array of ref names.
|
/// @brief The constructor with an array of ref names.
|
||||||
/// @param numrefs [in] The number of ref names.
|
/// @param numrefs [in] The number of ref names.
|
||||||
/// @param names [in] The ref names.
|
/// @param names [in] The ref names.
|
||||||
Reference( size_t numrefs, Name **names );
|
Reference(size_t numrefs, Name **names);
|
||||||
|
|
||||||
/// @brief The destructor.
|
/// @brief The destructor.
|
||||||
~Reference();
|
~Reference();
|
||||||
|
@ -178,38 +177,38 @@ struct DLL_ODDLPARSER_EXPORT Reference {
|
||||||
size_t sizeInBytes();
|
size_t sizeInBytes();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Reference &operator = ( const Reference & ) ddl_no_copy;
|
Reference &operator=(const Reference &) ddl_no_copy;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief Stores a property list.
|
/// @brief Stores a property list.
|
||||||
struct DLL_ODDLPARSER_EXPORT Property {
|
struct DLL_ODDLPARSER_EXPORT Property {
|
||||||
Text *m_key; ///< The identifier / key of the property.
|
Text *m_key; ///< The identifier / key of the property.
|
||||||
Value *m_value; ///< The value assigned to its key / id ( ddl_nullptr if none ).
|
Value *m_value; ///< The value assigned to its key / id ( ddl_nullptr if none ).
|
||||||
Reference *m_ref; ///< References assigned to its key / id ( ddl_nullptr if none ).
|
Reference *m_ref; ///< References assigned to its key / id ( ddl_nullptr if none ).
|
||||||
Property *m_next; ///< The next property ( ddl_nullptr if none ).
|
Property *m_next; ///< The next property ( ddl_nullptr if none ).
|
||||||
|
|
||||||
/// @brief The default constructor.
|
/// @brief The default constructor.
|
||||||
Property();
|
Property();
|
||||||
|
|
||||||
/// @brief The constructor for initialization.
|
/// @brief The constructor for initialization.
|
||||||
/// @param id [in] The identifier
|
/// @param id [in] The identifier
|
||||||
Property( Text *id );
|
Property(Text *id);
|
||||||
|
|
||||||
/// @brief The destructor.
|
/// @brief The destructor.
|
||||||
~Property();
|
~Property();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Property( const Property & ) ddl_no_copy;
|
Property(const Property &) ddl_no_copy;
|
||||||
Property &operator = ( const Property & ) ddl_no_copy;
|
Property &operator=(const Property &) ddl_no_copy;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief Stores a data array list.
|
/// @brief Stores a data array list.
|
||||||
struct DLL_ODDLPARSER_EXPORT DataArrayList {
|
struct DLL_ODDLPARSER_EXPORT DataArrayList {
|
||||||
size_t m_numItems; ///< The number of items in the list.
|
size_t m_numItems; ///< The number of items in the list.
|
||||||
Value *m_dataList; ///< The data list ( a Value ).
|
Value *m_dataList; ///< The data list ( a Value ).
|
||||||
DataArrayList *m_next; ///< The next data array list ( ddl_nullptr if last ).
|
DataArrayList *m_next; ///< The next data array list ( ddl_nullptr if last ).
|
||||||
Reference *m_refs;
|
Reference *m_refs;
|
||||||
size_t m_numRefs;
|
size_t m_numRefs;
|
||||||
|
|
||||||
/// @brief The default constructor for initialization.
|
/// @brief The default constructor for initialization.
|
||||||
DataArrayList();
|
DataArrayList();
|
||||||
|
@ -221,13 +220,13 @@ struct DLL_ODDLPARSER_EXPORT DataArrayList {
|
||||||
size_t size();
|
size_t size();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DataArrayList( const DataArrayList & ) ddl_no_copy;
|
DataArrayList(const DataArrayList &) ddl_no_copy;
|
||||||
DataArrayList &operator = ( const DataArrayList & ) ddl_no_copy;
|
DataArrayList &operator=(const DataArrayList &) ddl_no_copy;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief Stores the context of a parsed OpenDDL declaration.
|
/// @brief Stores the context of a parsed OpenDDL declaration.
|
||||||
struct DLL_ODDLPARSER_EXPORT Context {
|
struct DLL_ODDLPARSER_EXPORT Context {
|
||||||
DDLNode *m_root; ///< The root node of the OpenDDL node tree.
|
DDLNode *m_root; ///< The root node of the OpenDDL node tree.
|
||||||
|
|
||||||
/// @brief Constructor for initialization.
|
/// @brief Constructor for initialization.
|
||||||
Context();
|
Context();
|
||||||
|
@ -239,8 +238,8 @@ struct DLL_ODDLPARSER_EXPORT Context {
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Context( const Context & ) ddl_no_copy;
|
Context(const Context &) ddl_no_copy;
|
||||||
Context &operator = ( const Context & ) ddl_no_copy;
|
Context &operator=(const Context &) ddl_no_copy;
|
||||||
};
|
};
|
||||||
|
|
||||||
END_ODDLPARSER_NS
|
END_ODDLPARSER_NS
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*-----------------------------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------------------------
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2014-2015 Kim Kulling
|
Copyright (c) 2014-2020 Kim Kulling
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
this software and associated documentation files (the "Software"), to deal in
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
@ -40,7 +40,7 @@ class IOStreamBase;
|
||||||
class DLL_ODDLPARSER_EXPORT OpenDDLExport {
|
class DLL_ODDLPARSER_EXPORT OpenDDLExport {
|
||||||
public:
|
public:
|
||||||
/// @brief The class constructor
|
/// @brief The class constructor
|
||||||
OpenDDLExport( IOStreamBase *stream = ddl_nullptr );
|
OpenDDLExport(IOStreamBase *stream = nullptr);
|
||||||
|
|
||||||
/// @brief The class destructor.
|
/// @brief The class destructor.
|
||||||
~OpenDDLExport();
|
~OpenDDLExport();
|
||||||
|
@ -49,29 +49,29 @@ public:
|
||||||
/// @param ctx [in] Pointer to the context.
|
/// @param ctx [in] Pointer to the context.
|
||||||
/// @param filename [in] The filename for the export.
|
/// @param filename [in] The filename for the export.
|
||||||
/// @return True in case of success, false in case of an error.
|
/// @return True in case of success, false in case of an error.
|
||||||
bool exportContext( Context *ctx, const std::string &filename );
|
bool exportContext(Context *ctx, const std::string &filename);
|
||||||
|
|
||||||
/// @brief Handles a node export.
|
/// @brief Handles a node export.
|
||||||
/// @param node [in] The node to handle with.
|
/// @param node [in] The node to handle with.
|
||||||
/// @return True in case of success, false in case of an error.
|
/// @return True in case of success, false in case of an error.
|
||||||
bool handleNode( DDLNode *node );
|
bool handleNode(DDLNode *node);
|
||||||
|
|
||||||
/// @brief Writes the statement to the stream.
|
/// @brief Writes the statement to the stream.
|
||||||
/// @param statement [in] The content to write.
|
/// @param statement [in] The content to write.
|
||||||
/// @return True in case of success, false in case of an error.
|
/// @return True in case of success, false in case of an error.
|
||||||
bool writeToStream( const std::string &statement );
|
bool writeToStream(const std::string &statement);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool writeNode( DDLNode *node, std::string &statement );
|
bool writeNode(DDLNode *node, std::string &statement);
|
||||||
bool writeNodeHeader( DDLNode *node, std::string &statement );
|
bool writeNodeHeader(DDLNode *node, std::string &statement);
|
||||||
bool writeProperties( DDLNode *node, std::string &statement );
|
bool writeProperties(DDLNode *node, std::string &statement);
|
||||||
bool writeValueType( Value::ValueType type, size_t numItems, std::string &statement );
|
bool writeValueType(Value::ValueType type, size_t numItems, std::string &statement);
|
||||||
bool writeValue( Value *val, std::string &statement );
|
bool writeValue(Value *val, std::string &statement);
|
||||||
bool writeValueArray( DataArrayList *al, std::string &statement );
|
bool writeValueArray(DataArrayList *al, std::string &statement);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
OpenDDLExport( const OpenDDLExport & ) ddl_no_copy;
|
OpenDDLExport(const OpenDDLExport &) ddl_no_copy;
|
||||||
OpenDDLExport &operator = ( const OpenDDLExport & ) ddl_no_copy;
|
OpenDDLExport &operator=(const OpenDDLExport &) ddl_no_copy;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IOStreamBase *m_stream;
|
IOStreamBase *m_stream;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*-----------------------------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------------------------
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2014-2015 Kim Kulling
|
Copyright (c) 2014-2020 Kim Kulling
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
this software and associated documentation files (the "Software"), to deal in
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
@ -22,13 +22,13 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
-----------------------------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------------------------*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <openddlparser/OpenDDLCommon.h>
|
|
||||||
#include <openddlparser/DDLNode.h>
|
#include <openddlparser/DDLNode.h>
|
||||||
|
#include <openddlparser/OpenDDLCommon.h>
|
||||||
#include <openddlparser/OpenDDLParserUtils.h>
|
#include <openddlparser/OpenDDLParserUtils.h>
|
||||||
#include <openddlparser/Value.h>
|
#include <openddlparser/Value.h>
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
BEGIN_ODDLPARSER_NS
|
BEGIN_ODDLPARSER_NS
|
||||||
|
|
||||||
|
@ -39,14 +39,9 @@ struct Identifier;
|
||||||
struct Reference;
|
struct Reference;
|
||||||
struct Property;
|
struct Property;
|
||||||
|
|
||||||
template<class T>
|
template <class T>
|
||||||
inline
|
inline bool isEmbeddedCommentOpenTag(T *in, T *end) {
|
||||||
bool isEmbeddedCommentOpenTag( T *in, T *end ) {
|
if (in == '/' && in + 1 == '*') {
|
||||||
if ( in == end ) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( in == '/' && in+1 == '*' ) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,11 +53,10 @@ bool isEmbeddedCommentOpenTag( T *in, T *end ) {
|
||||||
/// @param end [in] The end position in the buffer.
|
/// @param end [in] The end position in the buffer.
|
||||||
/// @return Pointer showing to the next token or the end of the buffer.
|
/// @return Pointer showing to the next token or the end of the buffer.
|
||||||
/// @detail Will not increase buffer when already a valid buffer was found.
|
/// @detail Will not increase buffer when already a valid buffer was found.
|
||||||
template<class T>
|
template <class T>
|
||||||
inline
|
inline T *lookForNextToken(T *in, T *end) {
|
||||||
T *lookForNextToken( T *in, T *end ) {
|
while ((in != end) && (isSpace(*in) || isNewLine(*in) || ',' == *in)) {
|
||||||
while( ( in != end ) && ( isSpace( *in ) || isNewLine( *in ) || ',' == *in ) ) {
|
++in;
|
||||||
in++;
|
|
||||||
}
|
}
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
@ -72,26 +66,25 @@ T *lookForNextToken( T *in, T *end ) {
|
||||||
/// @param end [in] The end position in the buffer.
|
/// @param end [in] The end position in the buffer.
|
||||||
/// @return Pointer showing to the next token or the end of the buffer.
|
/// @return Pointer showing to the next token or the end of the buffer.
|
||||||
/// @detail Will increase buffer by a minimum of one.
|
/// @detail Will increase buffer by a minimum of one.
|
||||||
template<class T>
|
template <class T>
|
||||||
inline
|
inline T *getNextToken(T *in, T *end) {
|
||||||
T *getNextToken( T *in, T *end ) {
|
T *tmp(in);
|
||||||
T *tmp( in );
|
in = lookForNextToken(in, end);
|
||||||
in = lookForNextToken( in, end );
|
if (tmp == in) {
|
||||||
if( tmp == in ) {
|
++in;
|
||||||
in++;
|
|
||||||
}
|
}
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Defines the log severity.
|
/// @brief Defines the log severity.
|
||||||
enum LogSeverity {
|
enum LogSeverity {
|
||||||
ddl_debug_msg = 0, ///< Debug message, for debugging
|
ddl_debug_msg = 0, ///< Debug message, for debugging
|
||||||
ddl_info_msg, ///< Info messages, normal mode
|
ddl_info_msg, ///< Info messages, normal mode
|
||||||
ddl_warn_msg, ///< Parser warnings
|
ddl_warn_msg, ///< Parser warnings
|
||||||
ddl_error_msg ///< Parser errors
|
ddl_error_msg ///< Parser errors
|
||||||
};
|
};
|
||||||
|
|
||||||
DLL_ODDLPARSER_EXPORT const char *getTypeToken( Value::ValueType type );
|
DLL_ODDLPARSER_EXPORT const char *getTypeToken(Value::ValueType type);
|
||||||
|
|
||||||
//-------------------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------------------
|
||||||
/// @class OpenDDLParser
|
/// @class OpenDDLParser
|
||||||
|
@ -105,7 +98,7 @@ DLL_ODDLPARSER_EXPORT const char *getTypeToken( Value::ValueType type );
|
||||||
class DLL_ODDLPARSER_EXPORT OpenDDLParser {
|
class DLL_ODDLPARSER_EXPORT OpenDDLParser {
|
||||||
public:
|
public:
|
||||||
/// @brief The log callback function pointer.
|
/// @brief The log callback function pointer.
|
||||||
typedef void( *logCallback )( LogSeverity severity, const std::string &msg );
|
typedef void (*logCallback)(LogSeverity severity, const std::string &msg);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// @brief The default class constructor.
|
/// @brief The default class constructor.
|
||||||
|
@ -114,14 +107,14 @@ public:
|
||||||
/// @brief The class constructor.
|
/// @brief The class constructor.
|
||||||
/// @param buffer [in] The buffer
|
/// @param buffer [in] The buffer
|
||||||
/// @param len [in] Size of the buffer
|
/// @param len [in] Size of the buffer
|
||||||
OpenDDLParser( const char *buffer, size_t len );
|
OpenDDLParser(const char *buffer, size_t len);
|
||||||
|
|
||||||
/// @brief The class destructor.
|
/// @brief The class destructor.
|
||||||
~OpenDDLParser();
|
~OpenDDLParser();
|
||||||
|
|
||||||
/// @brief Setter for an own log callback function.
|
/// @brief Setter for an own log callback function.
|
||||||
/// @param callback [in] The own callback.
|
/// @param callback [in] The own callback.
|
||||||
void setLogCallback( logCallback callback );
|
void setLogCallback(logCallback callback);
|
||||||
|
|
||||||
/// @brief Getter for the log callback.
|
/// @brief Getter for the log callback.
|
||||||
/// @return The current log callback.
|
/// @return The current log callback.
|
||||||
|
@ -130,11 +123,11 @@ public:
|
||||||
/// @brief Assigns a new buffer to parse.
|
/// @brief Assigns a new buffer to parse.
|
||||||
/// @param buffer [in] The buffer
|
/// @param buffer [in] The buffer
|
||||||
/// @param len [in] Size of the buffer
|
/// @param len [in] Size of the buffer
|
||||||
void setBuffer( const char *buffer, size_t len );
|
void setBuffer(const char *buffer, size_t len);
|
||||||
|
|
||||||
/// @brief Assigns a new buffer to parse.
|
/// @brief Assigns a new buffer to parse.
|
||||||
/// @param buffer [in] The buffer as a std::vector.
|
/// @param buffer [in] The buffer as a std::vector.
|
||||||
void setBuffer( const std::vector<char> &buffer );
|
void setBuffer(const std::vector<char> &buffer);
|
||||||
|
|
||||||
/// @brief Returns the buffer pointer.
|
/// @brief Returns the buffer pointer.
|
||||||
/// @return The buffer pointer.
|
/// @return The buffer pointer.
|
||||||
|
@ -147,12 +140,15 @@ public:
|
||||||
/// @brief Clears all parser data, including buffer and active context.
|
/// @brief Clears all parser data, including buffer and active context.
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
|
bool validate();
|
||||||
|
|
||||||
/// @brief Starts the parsing of the OpenDDL-file.
|
/// @brief Starts the parsing of the OpenDDL-file.
|
||||||
/// @return True in case of success, false in case of an error.
|
/// @return True in case of success, false in case of an error.
|
||||||
/// @remark In case of errors check log.
|
/// @remark In case of errors check log.
|
||||||
bool parse();
|
bool parse();
|
||||||
|
|
||||||
bool exportContext( Context *ctx, const std::string &filename );
|
|
||||||
|
bool exportContext(Context *ctx, const std::string &filename);
|
||||||
|
|
||||||
/// @brief Returns the root node.
|
/// @brief Returns the root node.
|
||||||
/// @return The root node.
|
/// @return The root node.
|
||||||
|
@ -163,37 +159,37 @@ public:
|
||||||
Context *getContext() const;
|
Context *getContext() const;
|
||||||
|
|
||||||
public: // parser helpers
|
public: // parser helpers
|
||||||
char *parseNextNode( char *current, char *end );
|
char *parseNextNode(char *current, char *end);
|
||||||
char *parseHeader( char *in, char *end );
|
char *parseHeader(char *in, char *end);
|
||||||
char *parseStructure( char *in, char *end );
|
char *parseStructure(char *in, char *end);
|
||||||
char *parseStructureBody( char *in, char *end, bool &error );
|
char *parseStructureBody(char *in, char *end, bool &error);
|
||||||
void pushNode( DDLNode *node );
|
void pushNode(DDLNode *node);
|
||||||
DDLNode *popNode();
|
DDLNode *popNode();
|
||||||
DDLNode *top();
|
DDLNode *top();
|
||||||
static void normalizeBuffer( std::vector<char> &buffer );
|
static void normalizeBuffer(std::vector<char> &buffer);
|
||||||
static char *parseName( char *in, char *end, Name **name );
|
static char *parseName(char *in, char *end, Name **name);
|
||||||
static char *parseIdentifier( char *in, char *end, Text **id );
|
static char *parseIdentifier(char *in, char *end, Text **id);
|
||||||
static char *parsePrimitiveDataType( char *in, char *end, Value::ValueType &type, size_t &len );
|
static char *parsePrimitiveDataType(char *in, char *end, Value::ValueType &type, size_t &len);
|
||||||
static char *parseReference( char *in, char *end, std::vector<Name*> &names );
|
static char *parseReference(char *in, char *end, std::vector<Name *> &names);
|
||||||
static char *parseBooleanLiteral( char *in, char *end, Value **boolean );
|
static char *parseBooleanLiteral(char *in, char *end, Value **boolean);
|
||||||
static char *parseIntegerLiteral( char *in, char *end, Value **integer, Value::ValueType integerType = Value::ddl_int32 );
|
static char *parseIntegerLiteral(char *in, char *end, Value **integer, Value::ValueType integerType = Value::ValueType::ddl_int32);
|
||||||
static char *parseFloatingLiteral( char *in, char *end, Value **floating, Value::ValueType floatType= Value::ddl_float );
|
static char *parseFloatingLiteral(char *in, char *end, Value **floating, Value::ValueType floatType = Value::ValueType::ddl_float);
|
||||||
static char *parseStringLiteral( char *in, char *end, Value **stringData );
|
static char *parseStringLiteral(char *in, char *end, Value **stringData);
|
||||||
static char *parseHexaLiteral( char *in, char *end, Value **data );
|
static char *parseHexaLiteral(char *in, char *end, Value **data);
|
||||||
static char *parseProperty( char *in, char *end, Property **prop );
|
static char *parseProperty(char *in, char *end, Property **prop);
|
||||||
static char *parseDataList( char *in, char *end, Value::ValueType type, Value **data, size_t &numValues, Reference **refs, size_t &numRefs );
|
static char *parseDataList(char *in, char *end, Value::ValueType type, Value **data, size_t &numValues, Reference **refs, size_t &numRefs);
|
||||||
static char *parseDataArrayList( char *in, char *end, Value::ValueType type, DataArrayList **dataList );
|
static char *parseDataArrayList(char *in, char *end, Value::ValueType type, DataArrayList **dataList);
|
||||||
static const char *getVersion();
|
static const char *getVersion();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
OpenDDLParser( const OpenDDLParser & ) ddl_no_copy;
|
OpenDDLParser(const OpenDDLParser &) ddl_no_copy;
|
||||||
OpenDDLParser &operator = ( const OpenDDLParser & ) ddl_no_copy;
|
OpenDDLParser &operator=(const OpenDDLParser &) ddl_no_copy;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
logCallback m_logCallback;
|
logCallback m_logCallback;
|
||||||
std::vector<char> m_buffer;
|
std::vector<char> m_buffer;
|
||||||
|
|
||||||
typedef std::vector<DDLNode*> DDLNodeStack;
|
typedef std::vector<DDLNode *> DDLNodeStack;
|
||||||
DDLNodeStack m_stack;
|
DDLNodeStack m_stack;
|
||||||
Context *m_context;
|
Context *m_context;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*-----------------------------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------------------------
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2014-2015 Kim Kulling
|
Copyright (c) 2014-2020 Kim Kulling
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
this software and associated documentation files (the "Software"), to deal in
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
@ -26,64 +26,318 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
BEGIN_ODDLPARSER_NS
|
BEGIN_ODDLPARSER_NS
|
||||||
|
|
||||||
template<class T>
|
template <class T>
|
||||||
inline
|
inline bool isUpperCase(T in) {
|
||||||
bool isUpperCase( T in ) {
|
return (in >= 'A' && in <= 'Z');
|
||||||
return ( in >= 'A' && in <= 'Z' );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template <class T>
|
||||||
inline
|
inline bool isLowerCase(T in) {
|
||||||
bool isLowerCase( T in ) {
|
return (in >= 'a' && in <= 'z');
|
||||||
return ( in >= 'a' && in <= 'z' );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template <class T>
|
||||||
inline
|
inline bool isSpace(const T in) {
|
||||||
bool isSpace( const T in ) {
|
return (' ' == in || '\t' == in);
|
||||||
return ( ' ' == in || '\t' == in );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template <class T>
|
||||||
inline
|
inline bool isNewLine(const T in) {
|
||||||
bool isNewLine( const T in ) {
|
return ('\n' == in || ('\r' == in));
|
||||||
return ( '\n' == in || ( '\r' == in ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template <class T>
|
||||||
inline
|
inline bool isSeparator(T in) {
|
||||||
bool isSeparator( T in ) {
|
if (isSpace(in) || ',' == in || '{' == in || '}' == in || '[' == in || '(' == in || ')' == in) {
|
||||||
if( isSpace( in ) || ',' == in || '{' == in || '}' == in || '[' == in || '(' == in || ')' == in ) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
static const unsigned char chartype_table[256] = {
|
||||||
inline
|
0,
|
||||||
bool isNumeric( const T in ) {
|
0,
|
||||||
return ( in >= '0' && in <= '9' );
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0, // 0-15
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0, // 16-31
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0, // 32-47
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0, // 48-63
|
||||||
|
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0, // 64-79
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0, // 80-95
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0, // 96-111
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0, // 112-127
|
||||||
|
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0, // > 127
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
inline bool isNumeric(const T in) {
|
||||||
|
return (chartype_table[static_cast<size_t>(in)] == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template <class T>
|
||||||
inline
|
inline bool isNotEndOfToken(T *in, T *end) {
|
||||||
bool isNotEndOfToken( T *in, T *end ) {
|
return ('}' != *in && ',' != *in && !isSpace(*in) && ')' != *in && in != end);
|
||||||
return ( '}' != *in && ',' != *in && !isSpace( *in ) && ')' != *in && in != end );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template <class T>
|
||||||
inline
|
inline bool isInteger(T *in, T *end) {
|
||||||
bool isInteger( T *in, T *end ) {
|
if (in != end) {
|
||||||
if( in != end ) {
|
if (*in == '-') {
|
||||||
if( *in == '-' ) {
|
|
||||||
++in;
|
++in;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool result( false );
|
bool result(false);
|
||||||
while( isNotEndOfToken( in, end ) ) {
|
while (isNotEndOfToken(in, end)) {
|
||||||
result = isNumeric( *in );
|
result = isNumeric(*in);
|
||||||
if( !result ) {
|
if (!result) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
++in;
|
++in;
|
||||||
|
@ -92,40 +346,39 @@ bool isInteger( T *in, T *end ) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template <class T>
|
||||||
inline
|
inline bool isFloat(T *in, T *end) {
|
||||||
bool isFloat( T *in, T *end ) {
|
if (in != end) {
|
||||||
if( in != end ) {
|
if (*in == '-') {
|
||||||
if( *in == '-' ) {
|
|
||||||
++in;
|
++in;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// check for <1>.0f
|
// check for <1>.0f
|
||||||
bool result( false );
|
bool result(false);
|
||||||
while( isNotEndOfToken( in, end ) ) {
|
while (isNotEndOfToken(in, end)) {
|
||||||
if( *in == '.' ) {
|
if (*in == '.') {
|
||||||
result = true;
|
result = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
result = isNumeric( *in );
|
result = isNumeric(*in);
|
||||||
if( !result ) {
|
if (!result) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
++in;
|
++in;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check for 1<.>0f
|
// check for 1<.>0f
|
||||||
if( *in == '.' ) {
|
if (*in == '.') {
|
||||||
++in;
|
++in;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check for 1.<0>f
|
// check for 1.<0>f
|
||||||
while( isNotEndOfToken( in, end ) ) {
|
while (isNotEndOfToken(in, end)) {
|
||||||
result = isNumeric( *in );
|
result = isNumeric(*in);
|
||||||
if( !result ) {
|
if (!result) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
++in;
|
++in;
|
||||||
|
@ -134,24 +387,21 @@ bool isFloat( T *in, T *end ) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template <class T>
|
||||||
inline
|
inline bool isCharacter(const T in) {
|
||||||
bool isCharacter( const T in ) {
|
return ((in >= 'a' && in <= 'z') || (in >= 'A' && in <= 'Z'));
|
||||||
return ( ( in >= 'a' && in <= 'z' ) || ( in >= 'A' && in <= 'Z' ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template <class T>
|
||||||
inline
|
inline bool isStringLiteral(const T in) {
|
||||||
bool isStringLiteral( const T in ) {
|
return (in == '\"');
|
||||||
return ( in == '\"' );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template <class T>
|
||||||
inline
|
inline bool isHexLiteral(T *in, T *end) {
|
||||||
bool isHexLiteral( T *in, T *end ) {
|
if (*in == '0') {
|
||||||
if( *in == '0' ) {
|
if (in + 1 != end) {
|
||||||
if( in + 1 != end ) {
|
if (*(in + 1) == 'x' || *(in + 1) == 'X') {
|
||||||
if( *( in + 1 ) == 'x' || *( in + 1 ) == 'X' ) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -160,13 +410,12 @@ bool isHexLiteral( T *in, T *end ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template <class T>
|
||||||
inline
|
inline bool isReference(T *in, T *end) {
|
||||||
bool isReference( T *in, T *end ) {
|
if (*in == 'r') {
|
||||||
if( *in == 'r' ) {
|
if (*(in + 1) == 'e') {
|
||||||
if( *(in+1) == 'e' ) {
|
if (*(in + 2) == 'f') {
|
||||||
if( *(in+2) == 'f' ) {
|
if ((in + 2) != end) {
|
||||||
if( ( in + 2 ) != end ) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -176,16 +425,14 @@ bool isReference( T *in, T *end ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template <class T>
|
||||||
inline
|
inline bool isEndofLine(const T in) {
|
||||||
bool isEndofLine( const T in ) {
|
return ('\n' == in);
|
||||||
return ( '\n' == in );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template <class T>
|
||||||
inline
|
inline static T *getNextSeparator(T *in, T *end) {
|
||||||
static T *getNextSeparator( T *in, T *end ) {
|
while (!isSeparator(*in) || in == end) {
|
||||||
while( !isSeparator( *in ) || in == end ) {
|
|
||||||
++in;
|
++in;
|
||||||
}
|
}
|
||||||
return in;
|
return in;
|
||||||
|
@ -193,30 +440,28 @@ static T *getNextSeparator( T *in, T *end ) {
|
||||||
|
|
||||||
static const int ErrorHex2Decimal = 9999999;
|
static const int ErrorHex2Decimal = 9999999;
|
||||||
|
|
||||||
inline
|
inline int hex2Decimal(char in) {
|
||||||
int hex2Decimal( char in ) {
|
if (isNumeric(in)) {
|
||||||
if( isNumeric( in ) ) {
|
return (in - 48);
|
||||||
return ( in - 48 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char hexCodeLower( 'a' ), hexCodeUpper( 'A' );
|
char hexCodeLower('a'), hexCodeUpper('A');
|
||||||
for( int i = 0; i<16; i++ ) {
|
for (int i = 0; i < 16; i++) {
|
||||||
if( in == hexCodeLower + i || in == hexCodeUpper + i ) {
|
if (in == hexCodeLower + i || in == hexCodeUpper + i) {
|
||||||
return ( i+10 );
|
return (i + 10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ErrorHex2Decimal;
|
return ErrorHex2Decimal;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template <class T>
|
||||||
inline
|
inline bool isComment(T *in, T *end) {
|
||||||
bool isComment( T *in, T *end ) {
|
if (*in == '/') {
|
||||||
if ( *in=='/' ) {
|
if (in + 1 != end) {
|
||||||
if ( in+1!=end ) {
|
if (*(in + 1) == '/') {
|
||||||
if ( *( in+1 )=='/' ) {
|
char *drive((in + 2));
|
||||||
char *drive( ( in+2 ) );
|
if ((isUpperCase<T>(*drive) || isLowerCase<T>(*drive)) && *(drive + 1) == '/') {
|
||||||
if ( (isUpperCase<T>( *drive )||isLowerCase<T>( *drive ))&&*( drive+1 )=='/' ) {
|
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
|
@ -228,9 +473,8 @@ bool isComment( T *in, T *end ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template <class T>
|
||||||
inline
|
inline bool isCommentOpenTag(T *in, T *end) {
|
||||||
bool isCommentOpenTag(T *in, T *end ) {
|
|
||||||
if (*in == '/') {
|
if (*in == '/') {
|
||||||
if (in + 1 != end) {
|
if (in + 1 != end) {
|
||||||
if (*(in + 1) == '*') {
|
if (*(in + 1) == '*') {
|
||||||
|
@ -242,9 +486,8 @@ bool isCommentOpenTag(T *in, T *end ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template <class T>
|
||||||
inline
|
inline bool isCommentCloseTag(T *in, T *end) {
|
||||||
bool isCommentCloseTag(T *in, T *end) {
|
|
||||||
if (*in == '*') {
|
if (*in == '*') {
|
||||||
if (in + 1 != end) {
|
if (in + 1 != end) {
|
||||||
if (*(in + 1) == '/') {
|
if (*(in + 1) == '/') {
|
||||||
|
@ -257,4 +500,3 @@ bool isCommentCloseTag(T *in, T *end) {
|
||||||
}
|
}
|
||||||
|
|
||||||
END_ODDLPARSER_NS
|
END_ODDLPARSER_NS
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*-----------------------------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------------------------
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2014-2015 Kim Kulling
|
Copyright (c) 2014-2020 Kim Kulling
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
this software and associated documentation files (the "Software"), to deal in
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
@ -38,7 +38,7 @@ public:
|
||||||
/// @brief The class destructor, virtual.
|
/// @brief The class destructor, virtual.
|
||||||
virtual ~StreamFormatterBase();
|
virtual ~StreamFormatterBase();
|
||||||
|
|
||||||
/// @brief Will format the sring and return the new formatted result.
|
/// @brief Will format the string and return the new formatted result.
|
||||||
/// @param statement [in] The string to reformat.
|
/// @param statement [in] The string to reformat.
|
||||||
/// @return The reformatted result.
|
/// @return The reformatted result.
|
||||||
virtual std::string format(const std::string &statement);
|
virtual std::string format(const std::string &statement);
|
||||||
|
@ -52,7 +52,7 @@ class DLL_ODDLPARSER_EXPORT IOStreamBase {
|
||||||
public:
|
public:
|
||||||
/// @brief The class constructor with the formatter.
|
/// @brief The class constructor with the formatter.
|
||||||
/// @param formatter [in] The formatter to use.
|
/// @param formatter [in] The formatter to use.
|
||||||
explicit IOStreamBase(StreamFormatterBase *formatter = ddl_nullptr);
|
explicit IOStreamBase(StreamFormatterBase *formatter = nullptr);
|
||||||
|
|
||||||
/// @brief The class destructor, virtual.
|
/// @brief The class destructor, virtual.
|
||||||
virtual ~IOStreamBase();
|
virtual ~IOStreamBase();
|
||||||
|
@ -74,7 +74,7 @@ public:
|
||||||
/// @param sizeToRead [in] The size to read in bytes.
|
/// @param sizeToRead [in] The size to read in bytes.
|
||||||
/// @param statement [out] The read statements.
|
/// @param statement [out] The read statements.
|
||||||
/// @return The bytes read from the stream.
|
/// @return The bytes read from the stream.
|
||||||
virtual size_t read( size_t sizeToRead, std::string &statement );
|
virtual size_t read(size_t sizeToRead, std::string &statement);
|
||||||
|
|
||||||
/// @brief Will write a string into the stream.
|
/// @brief Will write a string into the stream.
|
||||||
/// @param statement [in] The string to write.
|
/// @param statement [in] The string to write.
|
||||||
|
|
|
@ -0,0 +1,226 @@
|
||||||
|
/*-----------------------------------------------------------------------------------------------
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2014-2019 Kim Kulling
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
-----------------------------------------------------------------------------------------------*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <openddlparser/OpenDDLCommon.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
BEGIN_ODDLPARSER_NS
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------------------------
|
||||||
|
/// @class TPoolAllocator
|
||||||
|
/// @ingroup CPPCore
|
||||||
|
///
|
||||||
|
/// @brief This class implements a simple pool-based allocation scheme.
|
||||||
|
/// Initially you have to define its size. Each allocation will be done from this initially created
|
||||||
|
/// pool. You have to release all pooled instances after the usage.
|
||||||
|
/// This allocation scheme is fast and does no call any new-calls during the lifetime of the
|
||||||
|
/// allocator.
|
||||||
|
//-------------------------------------------------------------------------------------------------
|
||||||
|
template <class T>
|
||||||
|
class TPoolAllocator {
|
||||||
|
public:
|
||||||
|
TPoolAllocator();
|
||||||
|
TPoolAllocator(size_t numItems);
|
||||||
|
~TPoolAllocator();
|
||||||
|
T *alloc();
|
||||||
|
void release();
|
||||||
|
void reserve(size_t size);
|
||||||
|
void clear();
|
||||||
|
size_t capacity() const;
|
||||||
|
size_t reservedMem() const;
|
||||||
|
size_t freeMem() const;
|
||||||
|
void dumpAllocations(std::string &allocs);
|
||||||
|
void resize(size_t growSize);
|
||||||
|
|
||||||
|
CPPCORE_NONE_COPYING(TPoolAllocator)
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct Pool {
|
||||||
|
size_t m_poolsize;
|
||||||
|
T *m_pool;
|
||||||
|
size_t m_currentIdx;
|
||||||
|
Pool *m_next;
|
||||||
|
|
||||||
|
Pool() :
|
||||||
|
m_poolsize(0u), m_pool(nullptr), m_currentIdx(0u), m_next(nullptr) {
|
||||||
|
// empty
|
||||||
|
}
|
||||||
|
|
||||||
|
Pool(size_t numItems, Pool *prev) :
|
||||||
|
m_poolsize(numItems), m_pool(nullptr), m_currentIdx(0u), m_next(prev) {
|
||||||
|
m_pool = new T[m_poolsize];
|
||||||
|
}
|
||||||
|
|
||||||
|
~Pool() {
|
||||||
|
delete[] m_pool;
|
||||||
|
m_pool = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
CPPCORE_NONE_COPYING(Pool)
|
||||||
|
};
|
||||||
|
|
||||||
|
Pool *getFreePool() {
|
||||||
|
Pool *current(m_freeList);
|
||||||
|
if (nullptr != m_freeList) {
|
||||||
|
m_freeList = m_freeList->m_next;
|
||||||
|
}
|
||||||
|
return current;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pool *m_first;
|
||||||
|
Pool *m_current;
|
||||||
|
Pool *m_freeList;
|
||||||
|
size_t m_capacity;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
inline TPoolAllocator<T>::TPoolAllocator() :
|
||||||
|
m_first(nullptr), m_current(nullptr), m_freeList(nullptr), m_capacity(0L) {
|
||||||
|
// empty
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
inline TPoolAllocator<T>::TPoolAllocator(size_t numItems) :
|
||||||
|
m_first(nullptr), m_current(nullptr), m_freeList(nullptr), m_capacity(0L) {
|
||||||
|
m_first = new Pool(numItems);
|
||||||
|
m_capacity += numItems;
|
||||||
|
m_current = m_first;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
inline TPoolAllocator<T>::~TPoolAllocator() {
|
||||||
|
clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
inline T *TPoolAllocator<T>::alloc() {
|
||||||
|
if (nullptr == m_current) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_current->m_currentIdx == m_current->m_poolsize) {
|
||||||
|
resize(m_current->m_poolsize);
|
||||||
|
}
|
||||||
|
|
||||||
|
T *ptr(&m_current->m_pool[m_current->m_currentIdx]);
|
||||||
|
m_current->m_currentIdx++;
|
||||||
|
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
inline void TPoolAllocator<T>::release() {
|
||||||
|
if (nullptr == m_current) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pool *current(m_first);
|
||||||
|
while (nullptr != current) {
|
||||||
|
current->m_currentIdx = 0;
|
||||||
|
current = current->m_next;
|
||||||
|
}
|
||||||
|
m_freeList = m_first->m_next;
|
||||||
|
m_current = m_first;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
inline void TPoolAllocator<T>::reserve(size_t size) {
|
||||||
|
clear();
|
||||||
|
|
||||||
|
m_first = new Pool(size, nullptr);
|
||||||
|
m_current = m_first;
|
||||||
|
|
||||||
|
m_current->m_pool = new T[size];
|
||||||
|
m_current->m_poolsize = size;
|
||||||
|
|
||||||
|
m_capacity = size;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
inline void TPoolAllocator<T>::clear() {
|
||||||
|
if (nullptr == m_current) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pool *next(m_first);
|
||||||
|
while (nullptr != next) {
|
||||||
|
Pool *current = next;
|
||||||
|
next = current->m_next;
|
||||||
|
delete current;
|
||||||
|
}
|
||||||
|
m_current = nullptr;
|
||||||
|
m_freeList = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
inline size_t TPoolAllocator<T>::capacity() const {
|
||||||
|
return m_capacity;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
inline size_t TPoolAllocator<T>::reservedMem() const {
|
||||||
|
return m_capacity * sizeof(T);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
inline size_t TPoolAllocator<T>::freeMem() const {
|
||||||
|
if (nullptr == m_current) {
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (m_current->m_poolsize - m_current->m_currentIdx);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
inline void TPoolAllocator<T>::dumpAllocations(std::string &allocs) {
|
||||||
|
allocs.clear();
|
||||||
|
allocs += "Number allocations = ";
|
||||||
|
allocs += std::to_string(m_current->m_currentIdx);
|
||||||
|
allocs += "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
inline void TPoolAllocator<T>::resize(size_t growSize) {
|
||||||
|
if (nullptr != m_current) {
|
||||||
|
if (growSize < m_current->m_poolsize) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nullptr == m_first) {
|
||||||
|
m_first = new Pool(growSize, nullptr);
|
||||||
|
m_current = m_first;
|
||||||
|
m_capacity += m_current->m_poolsize;
|
||||||
|
} else {
|
||||||
|
Pool *pool = getFreePool();
|
||||||
|
if (nullptr == pool) {
|
||||||
|
pool = new Pool(growSize, nullptr);
|
||||||
|
m_capacity += growSize;
|
||||||
|
}
|
||||||
|
m_current->m_next = pool;
|
||||||
|
m_current = m_current->m_next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
END_ODDLPARSER_NS
|
|
@ -1,7 +1,7 @@
|
||||||
/*-----------------------------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------------------------
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2014-2015 Kim Kulling
|
Copyright (c) 2014-2020 Kim Kulling
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
this software and associated documentation files (the "Software"), to deal in
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
@ -101,7 +101,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief This enum describes the data type stored in the value.
|
/// @brief This enum describes the data type stored in the value.
|
||||||
enum ValueType {
|
enum class ValueType {
|
||||||
ddl_none = -1, ///< Nothing specified
|
ddl_none = -1, ///< Nothing specified
|
||||||
ddl_bool = 0, ///< A boolean type
|
ddl_bool = 0, ///< A boolean type
|
||||||
ddl_int8, ///< Integer type, 8 bytes
|
ddl_int8, ///< Integer type, 8 bytes
|
||||||
|
|
|
@ -48,7 +48,7 @@ using namespace Assimp;
|
||||||
|
|
||||||
class utOpenGEXImportExport : public AbstractImportExportBase {
|
class utOpenGEXImportExport : public AbstractImportExportBase {
|
||||||
public:
|
public:
|
||||||
virtual bool importerTest() {
|
bool importerTest() override {
|
||||||
Assimp::Importer importer;
|
Assimp::Importer importer;
|
||||||
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/OpenGEX/Example.ogex", 0);
|
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/OpenGEX/Example.ogex", 0);
|
||||||
return nullptr != scene;
|
return nullptr != scene;
|
||||||
|
|
Loading…
Reference in New Issue