Model loading and texturing
This commit is contained in:
217
thirdparty/assimp/contrib/openddlparser/code/DDLNode.cpp
vendored
Normal file
217
thirdparty/assimp/contrib/openddlparser/code/DDLNode.cpp
vendored
Normal file
@@ -0,0 +1,217 @@
|
||||
/*-----------------------------------------------------------------------------------------------
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014-2015 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.
|
||||
-----------------------------------------------------------------------------------------------*/
|
||||
#include <openddlparser/DDLNode.h>
|
||||
#include <openddlparser/OpenDDLParser.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
BEGIN_ODDLPARSER_NS
|
||||
|
||||
DDLNode::DllNodeList DDLNode::s_allocatedNodes;
|
||||
|
||||
template<class T>
|
||||
inline
|
||||
static void releaseDataType( T *ptr ) {
|
||||
if( ddl_nullptr == ptr ) {
|
||||
return;
|
||||
}
|
||||
|
||||
T *current( ddl_nullptr );
|
||||
while( ptr ) {
|
||||
current = ptr;
|
||||
ptr = ptr->m_next;
|
||||
delete current;
|
||||
}
|
||||
}
|
||||
|
||||
static void releaseReferencedNames( Reference *ref ) {
|
||||
if( ddl_nullptr == ref ) {
|
||||
return;
|
||||
}
|
||||
|
||||
delete ref;
|
||||
}
|
||||
|
||||
DDLNode::DDLNode( const std::string &type, const std::string &name, size_t idx, DDLNode *parent )
|
||||
: m_type( type )
|
||||
, m_name( name )
|
||||
, m_parent( parent )
|
||||
, m_children()
|
||||
, m_properties( ddl_nullptr )
|
||||
, m_value( ddl_nullptr )
|
||||
, m_dtArrayList( ddl_nullptr )
|
||||
, m_references( ddl_nullptr )
|
||||
, m_idx( idx ) {
|
||||
if( m_parent ) {
|
||||
m_parent->m_children.push_back( this );
|
||||
}
|
||||
}
|
||||
|
||||
DDLNode::~DDLNode() {
|
||||
delete m_properties;
|
||||
delete m_value;
|
||||
releaseReferencedNames( m_references );
|
||||
|
||||
delete m_dtArrayList;
|
||||
m_dtArrayList = ddl_nullptr;
|
||||
if( s_allocatedNodes[ m_idx ] == this ) {
|
||||
s_allocatedNodes[ m_idx ] = ddl_nullptr;
|
||||
}
|
||||
for ( size_t i = 0; i<m_children.size(); i++ ){
|
||||
delete m_children[ i ];
|
||||
}
|
||||
}
|
||||
|
||||
void DDLNode::attachParent( DDLNode *parent ) {
|
||||
if( m_parent == parent ) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_parent = parent;
|
||||
if( ddl_nullptr != m_parent ) {
|
||||
m_parent->m_children.push_back( this );
|
||||
}
|
||||
}
|
||||
|
||||
void DDLNode::detachParent() {
|
||||
if( ddl_nullptr != m_parent ) {
|
||||
DDLNodeIt it = std::find( m_parent->m_children.begin(), m_parent->m_children.end(), this );
|
||||
if( m_parent->m_children.end() != it ) {
|
||||
m_parent->m_children.erase( it );
|
||||
}
|
||||
m_parent = ddl_nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
DDLNode *DDLNode::getParent() const {
|
||||
return m_parent;
|
||||
}
|
||||
|
||||
const DDLNode::DllNodeList &DDLNode::getChildNodeList() const {
|
||||
return m_children;
|
||||
}
|
||||
|
||||
void DDLNode::setType( const std::string &type ) {
|
||||
m_type = type;
|
||||
}
|
||||
|
||||
const std::string &DDLNode::getType() const {
|
||||
return m_type;
|
||||
}
|
||||
|
||||
void DDLNode::setName( const std::string &name ) {
|
||||
m_name = name;
|
||||
}
|
||||
|
||||
const std::string &DDLNode::getName() const {
|
||||
return m_name;
|
||||
}
|
||||
|
||||
void DDLNode::setProperties( Property *prop ) {
|
||||
if(m_properties!=ddl_nullptr)
|
||||
delete m_properties;
|
||||
m_properties = prop;
|
||||
}
|
||||
|
||||
Property *DDLNode::getProperties() const {
|
||||
return m_properties;
|
||||
}
|
||||
|
||||
bool DDLNode::hasProperty( const std::string &name ) {
|
||||
const Property *prop( findPropertyByName( name ) );
|
||||
return ( ddl_nullptr != prop );
|
||||
}
|
||||
|
||||
bool DDLNode::hasProperties() const {
|
||||
return( ddl_nullptr != m_properties );
|
||||
}
|
||||
|
||||
Property *DDLNode::findPropertyByName( const std::string &name ) {
|
||||
if( name.empty() ) {
|
||||
return ddl_nullptr;
|
||||
}
|
||||
|
||||
if( ddl_nullptr == m_properties ) {
|
||||
return ddl_nullptr;
|
||||
}
|
||||
|
||||
Property *current( m_properties );
|
||||
while( ddl_nullptr != current ) {
|
||||
int res = strncmp( current->m_key->m_buffer, name.c_str(), name.size() );
|
||||
if( 0 == res ) {
|
||||
return current;
|
||||
}
|
||||
current = current->m_next;
|
||||
}
|
||||
|
||||
return ddl_nullptr;
|
||||
}
|
||||
|
||||
void DDLNode::setValue( Value *val ) {
|
||||
m_value = val;
|
||||
}
|
||||
|
||||
Value *DDLNode::getValue() const {
|
||||
return m_value;
|
||||
}
|
||||
|
||||
void DDLNode::setDataArrayList( DataArrayList *dtArrayList ) {
|
||||
m_dtArrayList = dtArrayList;
|
||||
}
|
||||
|
||||
DataArrayList *DDLNode::getDataArrayList() const {
|
||||
return m_dtArrayList;
|
||||
}
|
||||
|
||||
void DDLNode::setReferences( Reference *refs ) {
|
||||
m_references = refs;
|
||||
}
|
||||
|
||||
Reference *DDLNode::getReferences() const {
|
||||
return m_references;
|
||||
}
|
||||
|
||||
void DDLNode::dump(IOStreamBase &/*stream*/) {
|
||||
// Todo!
|
||||
}
|
||||
|
||||
DDLNode *DDLNode::create( const std::string &type, const std::string &name, DDLNode *parent ) {
|
||||
const size_t idx( s_allocatedNodes.size() );
|
||||
DDLNode *node = new DDLNode( type, name, idx, parent );
|
||||
s_allocatedNodes.push_back( node );
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
void DDLNode::releaseNodes() {
|
||||
if( s_allocatedNodes.size() > 0 ) {
|
||||
for( DDLNodeIt it = s_allocatedNodes.begin(); it != s_allocatedNodes.end(); it++ ) {
|
||||
if( *it ) {
|
||||
delete *it;
|
||||
}
|
||||
}
|
||||
s_allocatedNodes.clear();
|
||||
}
|
||||
}
|
||||
|
||||
END_ODDLPARSER_NS
|
||||
212
thirdparty/assimp/contrib/openddlparser/code/OpenDDLCommon.cpp
vendored
Normal file
212
thirdparty/assimp/contrib/openddlparser/code/OpenDDLCommon.cpp
vendored
Normal file
@@ -0,0 +1,212 @@
|
||||
/*-----------------------------------------------------------------------------------------------
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014-2015 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.
|
||||
-----------------------------------------------------------------------------------------------*/
|
||||
#include <openddlparser/OpenDDLCommon.h>
|
||||
#include <openddlparser/DDLNode.h>
|
||||
#include <openddlparser/Value.h>
|
||||
|
||||
BEGIN_ODDLPARSER_NS
|
||||
|
||||
Text::Text( const char *buffer, size_t numChars )
|
||||
: m_capacity( 0 )
|
||||
, m_len( 0 )
|
||||
, m_buffer( ddl_nullptr ) {
|
||||
set( buffer, numChars );
|
||||
}
|
||||
|
||||
Text::~Text() {
|
||||
clear();
|
||||
}
|
||||
|
||||
void Text::clear() {
|
||||
delete[] m_buffer;
|
||||
m_buffer = ddl_nullptr;
|
||||
m_capacity = 0;
|
||||
m_len = 0;
|
||||
}
|
||||
|
||||
void Text::set( const char *buffer, size_t numChars ) {
|
||||
clear();
|
||||
if( numChars > 0 ) {
|
||||
m_len = numChars;
|
||||
m_capacity = m_len + 1;
|
||||
m_buffer = new char[ m_capacity ];
|
||||
strncpy( m_buffer, buffer, numChars );
|
||||
m_buffer[ numChars ] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
bool Text::operator == ( const std::string &name ) const {
|
||||
if( m_len != name.size() ) {
|
||||
return false;
|
||||
}
|
||||
const int res( strncmp( m_buffer, name.c_str(), name.size() ) );
|
||||
|
||||
return ( 0 == res );
|
||||
}
|
||||
|
||||
bool Text::operator == ( const Text &rhs ) const {
|
||||
if( m_len != rhs.m_len ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const int res( strncmp( m_buffer, rhs.m_buffer, m_len ) );
|
||||
|
||||
return ( 0 == res );
|
||||
}
|
||||
|
||||
Name::Name( NameType type, Text *id )
|
||||
: m_type( type )
|
||||
, m_id( id ) {
|
||||
// empty
|
||||
}
|
||||
|
||||
Name::~Name() {
|
||||
delete m_id;
|
||||
m_id = ddl_nullptr;
|
||||
}
|
||||
|
||||
Name::Name( const Name &name ){
|
||||
m_type=name.m_type;
|
||||
m_id=new Text(name.m_id->m_buffer,name.m_id->m_len);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference::Reference()
|
||||
: m_numRefs( 0 )
|
||||
, m_referencedName( ddl_nullptr ) {
|
||||
// empty
|
||||
}
|
||||
|
||||
Reference::Reference( size_t numrefs, Name **names )
|
||||
: m_numRefs( numrefs )
|
||||
, m_referencedName( ddl_nullptr ) {
|
||||
if ( numrefs > 0 ) {
|
||||
m_referencedName = new Name *[ numrefs ];
|
||||
for ( size_t i = 0; i < numrefs; i++ ) {
|
||||
m_referencedName[ i ] = names[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference::Reference(const Reference &ref) {
|
||||
m_numRefs=ref.m_numRefs;
|
||||
if(m_numRefs!=0){
|
||||
m_referencedName = new Name*[m_numRefs];
|
||||
for ( size_t i = 0; i < m_numRefs; i++ ) {
|
||||
m_referencedName[i] = new Name(*ref.m_referencedName[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference::~Reference() {
|
||||
for( size_t i = 0; i < m_numRefs; i++ ) {
|
||||
delete m_referencedName[ i ];
|
||||
}
|
||||
m_numRefs = 0;
|
||||
delete [] m_referencedName;
|
||||
m_referencedName = ddl_nullptr;
|
||||
}
|
||||
|
||||
size_t Reference::sizeInBytes() {
|
||||
if ( 0 == m_numRefs ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t size( 0 );
|
||||
for ( size_t i = 0; i < m_numRefs; i++ ) {
|
||||
Name *name( m_referencedName[ i ] );
|
||||
if ( ddl_nullptr != name ) {
|
||||
size += name->m_id->m_len;
|
||||
}
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
Property::Property( Text *id )
|
||||
: m_key( id )
|
||||
, m_value( ddl_nullptr )
|
||||
, m_ref( ddl_nullptr )
|
||||
, m_next( ddl_nullptr ) {
|
||||
// empty
|
||||
}
|
||||
|
||||
Property::~Property() {
|
||||
delete m_key;
|
||||
if(m_value!=ddl_nullptr)
|
||||
delete m_value;
|
||||
if(m_ref!=ddl_nullptr)
|
||||
delete(m_ref);
|
||||
if(m_next!=ddl_nullptr)
|
||||
delete m_next;
|
||||
}
|
||||
|
||||
DataArrayList::DataArrayList()
|
||||
: m_numItems( 0 )
|
||||
, m_dataList( ddl_nullptr )
|
||||
, m_next( ddl_nullptr )
|
||||
, m_refs(ddl_nullptr)
|
||||
, m_numRefs(0){
|
||||
// empty
|
||||
}
|
||||
|
||||
DataArrayList::~DataArrayList() {
|
||||
delete m_dataList;
|
||||
if(m_next!=ddl_nullptr)
|
||||
delete m_next;
|
||||
if(m_refs!=ddl_nullptr)
|
||||
delete m_refs;
|
||||
}
|
||||
|
||||
size_t DataArrayList::size() {
|
||||
size_t result( 0 );
|
||||
if ( ddl_nullptr == m_next ) {
|
||||
if ( m_dataList != ddl_nullptr ) {
|
||||
result = 1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
DataArrayList *n( m_next );
|
||||
while( ddl_nullptr != n ) {
|
||||
result++;
|
||||
n = n->m_next;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Context::Context()
|
||||
: m_root( ddl_nullptr ) {
|
||||
// empty
|
||||
}
|
||||
|
||||
Context::~Context() {
|
||||
clear();
|
||||
}
|
||||
|
||||
void Context::clear() {
|
||||
delete m_root;
|
||||
m_root = ddl_nullptr;
|
||||
}
|
||||
|
||||
END_ODDLPARSER_NS
|
||||
384
thirdparty/assimp/contrib/openddlparser/code/OpenDDLExport.cpp
vendored
Normal file
384
thirdparty/assimp/contrib/openddlparser/code/OpenDDLExport.cpp
vendored
Normal file
@@ -0,0 +1,384 @@
|
||||
/*-----------------------------------------------------------------------------------------------
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014-2015 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.
|
||||
-----------------------------------------------------------------------------------------------*/
|
||||
#include <openddlparser/OpenDDLExport.h>
|
||||
#include <openddlparser/DDLNode.h>
|
||||
#include <openddlparser/Value.h>
|
||||
#include <openddlparser/OpenDDLParser.h>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
BEGIN_ODDLPARSER_NS
|
||||
|
||||
struct DDLNodeIterator {
|
||||
const DDLNode::DllNodeList &m_childs;
|
||||
size_t m_idx;
|
||||
|
||||
DDLNodeIterator( const DDLNode::DllNodeList &childs )
|
||||
: m_childs( childs )
|
||||
, m_idx( 0 ) {
|
||||
// empty
|
||||
}
|
||||
|
||||
~DDLNodeIterator() {
|
||||
// empty
|
||||
}
|
||||
|
||||
bool getNext( DDLNode **node ) {
|
||||
if( m_childs.size() > (m_idx+1) ) {
|
||||
m_idx++;
|
||||
*node = m_childs[ m_idx ];
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
DDLNodeIterator() ddl_no_copy;
|
||||
DDLNodeIterator &operator = ( const DDLNodeIterator & ) ddl_no_copy;
|
||||
};
|
||||
|
||||
static void writeLineEnd( std::string &statement ) {
|
||||
statement += "\n";
|
||||
}
|
||||
|
||||
OpenDDLExport::OpenDDLExport( IOStreamBase *stream )
|
||||
: m_stream( stream ) {
|
||||
if (ddl_nullptr == m_stream) {
|
||||
m_stream = new IOStreamBase();
|
||||
}
|
||||
}
|
||||
|
||||
OpenDDLExport::~OpenDDLExport() {
|
||||
if (ddl_nullptr != m_stream) {
|
||||
m_stream->close();
|
||||
}
|
||||
delete m_stream;
|
||||
}
|
||||
|
||||
bool OpenDDLExport::exportContext( Context *ctx, const std::string &filename ) {
|
||||
if( ddl_nullptr == ctx ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
DDLNode *root( ctx->m_root );
|
||||
if ( ddl_nullptr == root ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!filename.empty()) {
|
||||
if (!m_stream->open( filename )) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const bool retValue( handleNode( root ) );
|
||||
|
||||
return retValue;
|
||||
}
|
||||
|
||||
bool OpenDDLExport::handleNode( DDLNode *node ) {
|
||||
if( ddl_nullptr == node ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const DDLNode::DllNodeList &childs = node->getChildNodeList();
|
||||
if( childs.empty() ) {
|
||||
return true;
|
||||
}
|
||||
DDLNode *current( ddl_nullptr );
|
||||
DDLNodeIterator it( childs );
|
||||
std::string statement;
|
||||
bool success( true );
|
||||
while( it.getNext( ¤t ) ) {
|
||||
if( ddl_nullptr != current ) {
|
||||
success |= writeNode( current, statement );
|
||||
if( !handleNode( current ) ) {
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
bool OpenDDLExport::writeToStream( const std::string &statement ) {
|
||||
if (ddl_nullptr == m_stream ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( !statement.empty()) {
|
||||
m_stream->write( statement );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OpenDDLExport::writeNode( DDLNode *node, std::string &statement ) {
|
||||
writeNodeHeader( node, statement );
|
||||
if (node->hasProperties()) {
|
||||
writeProperties( node, statement );
|
||||
}
|
||||
writeLineEnd( statement );
|
||||
|
||||
statement = "}";
|
||||
DataArrayList *al( node->getDataArrayList() );
|
||||
if ( ddl_nullptr != al ) {
|
||||
writeValueType( al->m_dataList->m_type, al->m_numItems, statement );
|
||||
writeValueArray( al, statement );
|
||||
}
|
||||
Value *v( node->getValue() );
|
||||
if (ddl_nullptr != v ) {
|
||||
writeValueType( v->m_type, 1, statement );
|
||||
statement = "{";
|
||||
writeLineEnd( statement );
|
||||
writeValue( v, statement );
|
||||
statement = "}";
|
||||
writeLineEnd( statement );
|
||||
}
|
||||
statement = "}";
|
||||
writeLineEnd( statement );
|
||||
|
||||
writeToStream( statement );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OpenDDLExport::writeNodeHeader( DDLNode *node, std::string &statement ) {
|
||||
if (ddl_nullptr == node) {
|
||||
return false;
|
||||
}
|
||||
|
||||
statement += node->getType();
|
||||
const std::string &name( node->getName() );
|
||||
if ( !name.empty() ) {
|
||||
statement += " ";
|
||||
statement += "$";
|
||||
statement += name;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OpenDDLExport::writeProperties( DDLNode *node, std::string &statement ) {
|
||||
if ( ddl_nullptr == node ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Property *prop( node->getProperties() );
|
||||
// if no properties are there, return
|
||||
if ( ddl_nullptr == prop ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( ddl_nullptr != prop ) {
|
||||
// for instance (attrib = "position", bla=2)
|
||||
statement += "(";
|
||||
bool first( true );
|
||||
while ( ddl_nullptr != prop ) {
|
||||
if (!first) {
|
||||
statement += ", ";
|
||||
} else {
|
||||
first = false;
|
||||
}
|
||||
statement += std::string( prop->m_key->m_buffer );
|
||||
statement += " = ";
|
||||
writeValue( prop->m_value, statement );
|
||||
prop = prop->m_next;
|
||||
}
|
||||
|
||||
statement += ")";
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OpenDDLExport::writeValueType( Value::ValueType type, size_t numItems, std::string &statement ) {
|
||||
if ( Value::ddl_types_max == type) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::string typeStr( getTypeToken( type ) );
|
||||
statement += typeStr;
|
||||
// if we have an array to write
|
||||
if ( numItems > 1 ) {
|
||||
statement += "[";
|
||||
char buffer[ 256 ];
|
||||
::memset( buffer, '\0', 256 * sizeof( char ) );
|
||||
sprintf( buffer, "%d", static_cast<int>( numItems ) );
|
||||
statement += buffer;
|
||||
statement += "]";
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OpenDDLExport::writeValue( Value *val, std::string &statement ) {
|
||||
if (ddl_nullptr == val) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch ( val->m_type ) {
|
||||
case Value::ddl_bool:
|
||||
if ( true == val->getBool() ) {
|
||||
statement += "true";
|
||||
} else {
|
||||
statement += "false";
|
||||
}
|
||||
break;
|
||||
case Value::ddl_int8:
|
||||
{
|
||||
std::stringstream stream;
|
||||
const int i = static_cast<int>( val->getInt8() );
|
||||
stream << i;
|
||||
statement += stream.str();
|
||||
}
|
||||
break;
|
||||
case Value::ddl_int16:
|
||||
{
|
||||
std::stringstream stream;
|
||||
char buffer[ 256 ];
|
||||
::memset( buffer, '\0', 256 * sizeof( char ) );
|
||||
sprintf( buffer, "%d", val->getInt16() );
|
||||
statement += buffer;
|
||||
}
|
||||
break;
|
||||
case Value::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::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:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OpenDDLExport::writeValueArray( DataArrayList *al, std::string &statement ) {
|
||||
if (ddl_nullptr == al) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (0 == al->m_numItems) {
|
||||
return true;
|
||||
}
|
||||
|
||||
DataArrayList *nextDataArrayList = al ;
|
||||
while (ddl_nullptr != nextDataArrayList) {
|
||||
if (ddl_nullptr != nextDataArrayList) {
|
||||
statement += "{ ";
|
||||
Value *nextValue( nextDataArrayList->m_dataList );
|
||||
size_t idx( 0 );
|
||||
while (ddl_nullptr != nextValue) {
|
||||
if (idx > 0) {
|
||||
statement += ", ";
|
||||
}
|
||||
writeValue( nextValue, statement );
|
||||
nextValue = nextValue->m_next;
|
||||
idx++;
|
||||
}
|
||||
statement += " }";
|
||||
}
|
||||
nextDataArrayList = nextDataArrayList->m_next;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
END_ODDLPARSER_NS
|
||||
|
||||
1031
thirdparty/assimp/contrib/openddlparser/code/OpenDDLParser.cpp
vendored
Normal file
1031
thirdparty/assimp/contrib/openddlparser/code/OpenDDLParser.cpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
96
thirdparty/assimp/contrib/openddlparser/code/OpenDDLStream.cpp
vendored
Normal file
96
thirdparty/assimp/contrib/openddlparser/code/OpenDDLStream.cpp
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
/*-----------------------------------------------------------------------------------------------
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014-2015 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.
|
||||
-----------------------------------------------------------------------------------------------*/
|
||||
#include <openddlparser/OpenDDLStream.h>
|
||||
|
||||
BEGIN_ODDLPARSER_NS
|
||||
|
||||
StreamFormatterBase::StreamFormatterBase() {
|
||||
// empty
|
||||
}
|
||||
|
||||
StreamFormatterBase::~StreamFormatterBase() {
|
||||
// empty
|
||||
}
|
||||
|
||||
std::string StreamFormatterBase::format(const std::string &statement) {
|
||||
std::string tmp(statement);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
IOStreamBase::IOStreamBase(StreamFormatterBase *formatter)
|
||||
: m_formatter(formatter)
|
||||
, m_file(ddl_nullptr) {
|
||||
if (ddl_nullptr == m_formatter) {
|
||||
m_formatter = new StreamFormatterBase;
|
||||
}
|
||||
}
|
||||
|
||||
IOStreamBase::~IOStreamBase() {
|
||||
delete m_formatter;
|
||||
m_formatter = ddl_nullptr;
|
||||
}
|
||||
|
||||
bool IOStreamBase::open(const std::string &name) {
|
||||
m_file = ::fopen(name.c_str(), "a");
|
||||
if (m_file == ddl_nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IOStreamBase::close() {
|
||||
if (ddl_nullptr == m_file) {
|
||||
return false;
|
||||
}
|
||||
|
||||
::fclose(m_file);
|
||||
m_file = ddl_nullptr;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IOStreamBase::isOpen() const {
|
||||
return ( ddl_nullptr != m_file );
|
||||
}
|
||||
|
||||
size_t IOStreamBase::read( size_t sizeToRead, std::string &statement ) {
|
||||
if (ddl_nullptr == m_file) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
statement.resize(sizeToRead);
|
||||
const size_t readBytes = ::fread( &statement[0], 1, sizeToRead, m_file );
|
||||
|
||||
return readBytes;
|
||||
}
|
||||
|
||||
size_t IOStreamBase::write(const std::string &statement) {
|
||||
if (ddl_nullptr == m_file) {
|
||||
return 0;
|
||||
}
|
||||
std::string formatStatement = m_formatter->format(statement);
|
||||
return ::fwrite(formatStatement.c_str(), sizeof(char), formatStatement.size(), m_file);
|
||||
}
|
||||
|
||||
END_ODDLPARSER_NS
|
||||
439
thirdparty/assimp/contrib/openddlparser/code/Value.cpp
vendored
Normal file
439
thirdparty/assimp/contrib/openddlparser/code/Value.cpp
vendored
Normal file
@@ -0,0 +1,439 @@
|
||||
/*-----------------------------------------------------------------------------------------------
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014-2015 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.
|
||||
-----------------------------------------------------------------------------------------------*/
|
||||
#include <openddlparser/Value.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
|
||||
BEGIN_ODDLPARSER_NS
|
||||
|
||||
static Value::Iterator end( ddl_nullptr );
|
||||
|
||||
Value::Iterator::Iterator()
|
||||
: m_start( ddl_nullptr )
|
||||
, m_current( ddl_nullptr ) {
|
||||
// empty
|
||||
}
|
||||
|
||||
Value::Iterator::Iterator( Value *start )
|
||||
: m_start( start )
|
||||
, m_current( start ) {
|
||||
// empty
|
||||
}
|
||||
|
||||
Value::Iterator::Iterator( const Iterator &rhs )
|
||||
: m_start( rhs.m_start )
|
||||
, m_current( rhs.m_current ) {
|
||||
// empty
|
||||
}
|
||||
|
||||
Value::Iterator::~Iterator() {
|
||||
// empty
|
||||
}
|
||||
|
||||
bool Value::Iterator::hasNext() const {
|
||||
if( ddl_nullptr == m_current ) {
|
||||
return false;
|
||||
}
|
||||
return ( ddl_nullptr != m_current->getNext() );
|
||||
}
|
||||
|
||||
Value *Value::Iterator::getNext() {
|
||||
if( !hasNext() ) {
|
||||
return ddl_nullptr;
|
||||
}
|
||||
|
||||
Value *v( m_current->getNext() );
|
||||
m_current = v;
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
const Value::Iterator Value::Iterator::operator++( int ) {
|
||||
if( ddl_nullptr == m_current ) {
|
||||
return end;
|
||||
}
|
||||
|
||||
m_current = m_current->getNext();
|
||||
Iterator inst( m_current );
|
||||
|
||||
return inst;
|
||||
}
|
||||
|
||||
Value::Iterator &Value::Iterator::operator++( ) {
|
||||
if( ddl_nullptr == m_current ) {
|
||||
return end;
|
||||
}
|
||||
|
||||
m_current = m_current->getNext();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool Value::Iterator::operator == ( const Iterator &rhs ) const {
|
||||
return ( m_current == rhs.m_current );
|
||||
}
|
||||
|
||||
Value *Value::Iterator::operator->( ) const {
|
||||
if(ddl_nullptr == m_current ) {
|
||||
return ddl_nullptr;
|
||||
}
|
||||
return m_current;
|
||||
}
|
||||
|
||||
Value::Value( ValueType type )
|
||||
: m_type( type )
|
||||
, m_size( 0 )
|
||||
, m_data( ddl_nullptr )
|
||||
, m_next( ddl_nullptr ) {
|
||||
// empty
|
||||
}
|
||||
|
||||
Value::~Value() {
|
||||
if(m_data!=ddl_nullptr) {
|
||||
if (m_type == ddl_ref ) {
|
||||
Reference *tmp = (Reference *) m_data;
|
||||
if (tmp != ddl_nullptr)
|
||||
delete tmp;
|
||||
}else
|
||||
delete[] m_data;
|
||||
|
||||
}
|
||||
if(m_next!=ddl_nullptr)
|
||||
delete m_next;
|
||||
}
|
||||
|
||||
void Value::setBool( bool value ) {
|
||||
assert( ddl_bool == m_type );
|
||||
::memcpy( m_data, &value, m_size );
|
||||
}
|
||||
|
||||
bool Value::getBool() {
|
||||
assert( ddl_bool == m_type );
|
||||
return ( *m_data == 1 );
|
||||
}
|
||||
|
||||
void Value::setInt8( int8 value ) {
|
||||
assert( ddl_int8 == m_type );
|
||||
::memcpy( m_data, &value, m_size );
|
||||
}
|
||||
|
||||
int8 Value::getInt8() {
|
||||
assert( ddl_int8 == m_type );
|
||||
return ( int8 ) ( *m_data );
|
||||
}
|
||||
|
||||
void Value::setInt16( int16 value ) {
|
||||
assert( ddl_int16 == m_type );
|
||||
::memcpy( m_data, &value, m_size );
|
||||
}
|
||||
|
||||
int16 Value::getInt16() {
|
||||
assert( ddl_int16 == m_type );
|
||||
int16 i;
|
||||
::memcpy( &i, m_data, m_size );
|
||||
return i;
|
||||
}
|
||||
|
||||
void Value::setInt32( int32 value ) {
|
||||
assert( ddl_int32 == m_type );
|
||||
::memcpy( m_data, &value, m_size );
|
||||
}
|
||||
|
||||
int32 Value::getInt32() {
|
||||
assert( ddl_int32 == m_type );
|
||||
int32 i;
|
||||
::memcpy( &i, m_data, m_size );
|
||||
return i;
|
||||
}
|
||||
|
||||
void Value::setInt64( int64 value ) {
|
||||
assert( ddl_int64 == m_type );
|
||||
::memcpy( m_data, &value, m_size );
|
||||
}
|
||||
|
||||
int64 Value::getInt64() {
|
||||
assert( ddl_int64 == m_type );
|
||||
int64 i;
|
||||
::memcpy( &i, m_data, m_size );
|
||||
return i;
|
||||
}
|
||||
|
||||
void Value::setUnsignedInt8( uint8 value ) {
|
||||
assert( ddl_unsigned_int8 == m_type );
|
||||
::memcpy( m_data, &value, m_size );
|
||||
}
|
||||
|
||||
uint8 Value::getUnsignedInt8() const {
|
||||
assert( ddl_unsigned_int8 == m_type );
|
||||
uint8 i;
|
||||
::memcpy( &i, m_data, m_size );
|
||||
return i;
|
||||
}
|
||||
|
||||
void Value::setUnsignedInt16( uint16 value ) {
|
||||
assert( ddl_unsigned_int16 == m_type );
|
||||
::memcpy( m_data, &value, m_size );
|
||||
}
|
||||
|
||||
uint16 Value::getUnsignedInt16() const {
|
||||
assert( ddl_unsigned_int16 == m_type );
|
||||
uint16 i;
|
||||
::memcpy( &i, m_data, m_size );
|
||||
return i;
|
||||
}
|
||||
|
||||
void Value::setUnsignedInt32( uint32 value ) {
|
||||
assert( ddl_unsigned_int32 == m_type );
|
||||
::memcpy( m_data, &value, m_size );
|
||||
}
|
||||
|
||||
uint32 Value::getUnsignedInt32() const {
|
||||
assert( ddl_unsigned_int32 == m_type );
|
||||
uint32 i;
|
||||
::memcpy( &i, m_data, m_size );
|
||||
return i;
|
||||
}
|
||||
|
||||
void Value::setUnsignedInt64( uint64 value ) {
|
||||
assert( ddl_unsigned_int64 == m_type );
|
||||
::memcpy( m_data, &value, m_size );
|
||||
}
|
||||
|
||||
uint64 Value::getUnsignedInt64() const {
|
||||
assert( ddl_unsigned_int64 == m_type );
|
||||
uint64 i;
|
||||
::memcpy( &i, m_data, m_size );
|
||||
return i;
|
||||
}
|
||||
|
||||
void Value::setFloat( float value ) {
|
||||
assert( ddl_float == m_type );
|
||||
::memcpy( m_data, &value, m_size );
|
||||
}
|
||||
|
||||
float Value::getFloat() const {
|
||||
if( m_type == ddl_float ) {
|
||||
float v;
|
||||
::memcpy( &v, m_data, m_size );
|
||||
return ( float ) v;
|
||||
} else {
|
||||
float tmp;
|
||||
::memcpy( &tmp, m_data, 4 );
|
||||
return ( float ) tmp;
|
||||
}
|
||||
}
|
||||
|
||||
void Value::setDouble( double value ) {
|
||||
assert( ddl_double == m_type );
|
||||
::memcpy( m_data, &value, m_size );
|
||||
}
|
||||
|
||||
double Value::getDouble() const {
|
||||
if ( m_type == ddl_double ) {
|
||||
double v;
|
||||
::memcpy( &v, m_data, m_size );
|
||||
return ( float ) v;
|
||||
}
|
||||
else {
|
||||
double tmp;
|
||||
::memcpy( &tmp, m_data, 4 );
|
||||
return ( double ) tmp;
|
||||
}
|
||||
}
|
||||
|
||||
void Value::setString( const std::string &str ) {
|
||||
assert( ddl_string == m_type );
|
||||
::memcpy( m_data, str.c_str(), str.size() );
|
||||
m_data[ str.size() ] = '\0';
|
||||
}
|
||||
|
||||
const char *Value::getString() const {
|
||||
assert( ddl_string == m_type );
|
||||
return (const char*) m_data;
|
||||
}
|
||||
|
||||
void Value::setRef( Reference *ref ) {
|
||||
assert( ddl_ref == m_type );
|
||||
|
||||
if ( ddl_nullptr != ref ) {
|
||||
const size_t sizeInBytes( ref->sizeInBytes() );
|
||||
if ( sizeInBytes > 0 ) {
|
||||
if ( ddl_nullptr != m_data ) {
|
||||
delete [] m_data;
|
||||
}
|
||||
|
||||
m_data = (unsigned char*) new Reference(*ref);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference *Value::getRef() const {
|
||||
assert( ddl_ref == m_type );
|
||||
|
||||
return (Reference*) m_data;
|
||||
}
|
||||
|
||||
void Value::dump( IOStreamBase &/*stream*/ ) {
|
||||
switch( m_type ) {
|
||||
case ddl_none:
|
||||
std::cout << "None" << std::endl;
|
||||
break;
|
||||
case ddl_bool:
|
||||
std::cout << getBool() << std::endl;
|
||||
break;
|
||||
case ddl_int8:
|
||||
std::cout << getInt8() << std::endl;
|
||||
break;
|
||||
case ddl_int16:
|
||||
std::cout << getInt16() << std::endl;
|
||||
break;
|
||||
case ddl_int32:
|
||||
std::cout << getInt32() << std::endl;
|
||||
break;
|
||||
case ddl_int64:
|
||||
std::cout << getInt64() << std::endl;
|
||||
break;
|
||||
case ddl_unsigned_int8:
|
||||
std::cout << "Not supported" << std::endl;
|
||||
break;
|
||||
case ddl_unsigned_int16:
|
||||
std::cout << "Not supported" << std::endl;
|
||||
break;
|
||||
case ddl_unsigned_int32:
|
||||
std::cout << "Not supported" << std::endl;
|
||||
break;
|
||||
case ddl_unsigned_int64:
|
||||
std::cout << "Not supported" << std::endl;
|
||||
break;
|
||||
case ddl_half:
|
||||
std::cout << "Not supported" << std::endl;
|
||||
break;
|
||||
case ddl_float:
|
||||
std::cout << getFloat() << std::endl;
|
||||
break;
|
||||
case ddl_double:
|
||||
std::cout << getDouble() << std::endl;
|
||||
break;
|
||||
case ddl_string:
|
||||
std::cout << getString() << std::endl;
|
||||
break;
|
||||
case ddl_ref:
|
||||
std::cout << "Not supported" << std::endl;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Value::setNext( Value *next ) {
|
||||
m_next = next;
|
||||
}
|
||||
|
||||
Value *Value::getNext() const {
|
||||
return m_next;
|
||||
}
|
||||
|
||||
size_t Value::size() const{
|
||||
size_t result=1;
|
||||
Value *n=m_next;
|
||||
while( n!=ddl_nullptr) {
|
||||
result++;
|
||||
n=n->m_next;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Value *ValueAllocator::allocPrimData( Value::ValueType type, size_t len ) {
|
||||
if( type == Value::ddl_none || Value::ddl_types_max == type ) {
|
||||
return ddl_nullptr;
|
||||
}
|
||||
|
||||
Value *data = new Value( type );
|
||||
switch( type ) {
|
||||
case Value::ddl_bool:
|
||||
data->m_size = sizeof( bool );
|
||||
break;
|
||||
case Value::ddl_int8:
|
||||
data->m_size = sizeof( int8 );
|
||||
break;
|
||||
case Value::ddl_int16:
|
||||
data->m_size = sizeof( int16 );
|
||||
break;
|
||||
case Value::ddl_int32:
|
||||
data->m_size = sizeof( int32 );
|
||||
break;
|
||||
case Value::ddl_int64:
|
||||
data->m_size = sizeof( int64 );
|
||||
break;
|
||||
case Value::ddl_unsigned_int8:
|
||||
data->m_size = sizeof( uint8 );
|
||||
break;
|
||||
case Value::ddl_unsigned_int16:
|
||||
data->m_size = sizeof( uint16 );
|
||||
break;
|
||||
case Value::ddl_unsigned_int32:
|
||||
data->m_size = sizeof( uint32 );
|
||||
break;
|
||||
case Value::ddl_unsigned_int64:
|
||||
data->m_size = sizeof( uint64 );
|
||||
break;
|
||||
case Value::ddl_half:
|
||||
data->m_size = sizeof( short );
|
||||
break;
|
||||
case Value::ddl_float:
|
||||
data->m_size = sizeof( float );
|
||||
break;
|
||||
case Value::ddl_double:
|
||||
data->m_size = sizeof( double );
|
||||
break;
|
||||
case Value::ddl_string:
|
||||
data->m_size = sizeof( char )*(len+1);
|
||||
break;
|
||||
case Value::ddl_ref:
|
||||
data->m_size = 0;
|
||||
break;
|
||||
case Value::ddl_none:
|
||||
case Value::ddl_types_max:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if( data->m_size ) {
|
||||
data->m_data = new unsigned char[ data->m_size ];
|
||||
::memset(data->m_data,0,data->m_size);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
void ValueAllocator::releasePrimData( Value **data ) {
|
||||
if( !data ) {
|
||||
return;
|
||||
}
|
||||
|
||||
delete *data;
|
||||
*data = ddl_nullptr;
|
||||
}
|
||||
|
||||
END_ODDLPARSER_NS
|
||||
Reference in New Issue
Block a user