- Previous merge accidentally copied OpenDDL C++ files into include directory.
parent
8b7fa48d27
commit
f7a8c80fc2
|
@ -1,209 +0,0 @@
|
|||
/*-----------------------------------------------------------------------------------------------
|
||||
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;
|
||||
}
|
||||
|
||||
if( ref->m_referencedName ) {
|
||||
for( size_t i = 0; i < ref->m_numRefs; i++ ) {
|
||||
delete ref->m_referencedName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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() {
|
||||
releaseDataType<Property>( m_properties );
|
||||
releaseDataType<Value>( m_value );
|
||||
releaseReferencedNames( m_references );
|
||||
|
||||
delete m_dtArrayList;
|
||||
m_dtArrayList = ddl_nullptr;
|
||||
if( s_allocatedNodes[ m_idx ] == this ) {
|
||||
s_allocatedNodes[ m_idx ] = ddl_nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
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( m_parent ) {
|
||||
std::vector<DDLNode*>::iterator it;
|
||||
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 ) {
|
||||
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 );
|
||||
}
|
||||
|
||||
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_text.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;
|
||||
}
|
||||
|
||||
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( DllNodeList::iterator it = s_allocatedNodes.begin(); it != s_allocatedNodes.end(); it++ ) {
|
||||
if( *it ) {
|
||||
delete *it;
|
||||
}
|
||||
}
|
||||
s_allocatedNodes.clear();
|
||||
}
|
||||
}
|
||||
|
||||
END_ODDLPARSER_NS
|
|
@ -1,907 +0,0 @@
|
|||
/*-----------------------------------------------------------------------------------------------
|
||||
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/OpenDDLParser.h>
|
||||
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
#include <math.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
# include <windows.h>
|
||||
#endif // _WIN32
|
||||
|
||||
#define DEBUG_HEADER_NAME
|
||||
|
||||
BEGIN_ODDLPARSER_NS
|
||||
|
||||
static const char *Version = "0.1.0";
|
||||
|
||||
namespace Grammar {
|
||||
static const char * const OpenBracketToken = "{";
|
||||
static const char * const CloseBracketToken = "}";
|
||||
static const char * const OpenPropertyToken = "(";
|
||||
static const char * const ClosePropertyToken = ")";
|
||||
static const char * const BoolTrue = "true";
|
||||
static const char * const BoolFalse = "false";
|
||||
static const char * const RefToken = "ref";
|
||||
static const char * const CommaSeparator = ",";
|
||||
|
||||
static const char* PrimitiveTypeToken[ Value::ddl_types_max ] = {
|
||||
"bool",
|
||||
"int8",
|
||||
"int16",
|
||||
"int32",
|
||||
"int64",
|
||||
"unsigned_int8",
|
||||
"unsigned_int16",
|
||||
"unsigned_int32",
|
||||
"unsigned_int64",
|
||||
"half",
|
||||
"float",
|
||||
"double",
|
||||
"string",
|
||||
"ref"
|
||||
};
|
||||
} // Namespace Grammar
|
||||
|
||||
|
||||
static void logInvalidTokenError( char *in, const std::string &exp, OpenDDLParser::logCallback callback ) {
|
||||
std::stringstream stream;
|
||||
stream << "Invalid token " << *in << ", " << exp << " expected." << std::endl;
|
||||
callback( ddl_error_msg, stream.str() );
|
||||
}
|
||||
|
||||
static bool isIntegerType( Value::ValueType integerType ) {
|
||||
if( integerType != Value::ddl_int8 && integerType != Value::ddl_int16 &&
|
||||
integerType != Value::ddl_int32 && integerType != Value::ddl_int64 ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static DDLNode *createDDLNode( Identifier *id, OpenDDLParser *parser ) {
|
||||
if( ddl_nullptr == id || ddl_nullptr == parser ) {
|
||||
return ddl_nullptr;
|
||||
}
|
||||
|
||||
const std::string type( id->m_text.m_buffer );
|
||||
DDLNode *parent( parser->top() );
|
||||
DDLNode *node = DDLNode::create( type, "", parent );
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
static void logMessage( LogSeverity severity, const std::string &msg ) {
|
||||
std::string log;
|
||||
if( ddl_debug_msg == severity ) {
|
||||
log += "Debug:";
|
||||
} else if( ddl_info_msg == severity ) {
|
||||
log += "Info :";
|
||||
} else if( ddl_warn_msg == severity ) {
|
||||
log += "Warn :";
|
||||
} else if( ddl_error_msg == severity ) {
|
||||
log += "Error:";
|
||||
} else {
|
||||
log += "None :";
|
||||
}
|
||||
|
||||
log += msg;
|
||||
std::cout << log;
|
||||
}
|
||||
|
||||
OpenDDLParser::OpenDDLParser()
|
||||
: m_logCallback( logMessage )
|
||||
, m_buffer()
|
||||
, m_stack()
|
||||
, m_context( ddl_nullptr ) {
|
||||
// empty
|
||||
}
|
||||
|
||||
OpenDDLParser::OpenDDLParser( char *buffer, size_t len )
|
||||
: m_logCallback( &logMessage )
|
||||
, m_buffer()
|
||||
, m_context( ddl_nullptr ) {
|
||||
if( 0 != len ) {
|
||||
setBuffer( buffer, len );
|
||||
}
|
||||
}
|
||||
|
||||
OpenDDLParser::~OpenDDLParser() {
|
||||
clear();
|
||||
}
|
||||
|
||||
void OpenDDLParser::setLogCallback( logCallback callback ) {
|
||||
if( ddl_nullptr != callback ) {
|
||||
// install user-specific log callback
|
||||
m_logCallback = callback;
|
||||
} else {
|
||||
// install default log callback
|
||||
m_logCallback = &logMessage;
|
||||
}
|
||||
}
|
||||
|
||||
OpenDDLParser::logCallback OpenDDLParser::getLogCallback() const {
|
||||
return m_logCallback;
|
||||
}
|
||||
|
||||
void OpenDDLParser::setBuffer( char *buffer, size_t len ) {
|
||||
clear();
|
||||
if( 0 == len ) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_buffer.resize( len );
|
||||
::memcpy(&m_buffer[ 0 ], buffer, len );
|
||||
}
|
||||
|
||||
void OpenDDLParser::setBuffer( const std::vector<char> &buffer ) {
|
||||
clear();
|
||||
m_buffer.resize( buffer.size() );
|
||||
std::copy( buffer.begin(), buffer.end(), m_buffer.begin() );
|
||||
}
|
||||
|
||||
const char *OpenDDLParser::getBuffer() const {
|
||||
if( m_buffer.empty() ) {
|
||||
return ddl_nullptr;
|
||||
}
|
||||
|
||||
return &m_buffer[ 0 ];
|
||||
}
|
||||
|
||||
size_t OpenDDLParser::getBufferSize() const {
|
||||
return m_buffer.size();
|
||||
}
|
||||
|
||||
void OpenDDLParser::clear() {
|
||||
m_buffer.resize( 0 );
|
||||
if( m_context ) {
|
||||
m_context->m_root = ddl_nullptr;
|
||||
}
|
||||
|
||||
DDLNode::releaseNodes();
|
||||
}
|
||||
|
||||
bool OpenDDLParser::parse() {
|
||||
if( m_buffer.empty() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
normalizeBuffer( m_buffer );
|
||||
|
||||
m_context = new Context;
|
||||
m_context->m_root = DDLNode::create( "root", "", ddl_nullptr );
|
||||
pushNode( m_context->m_root );
|
||||
|
||||
// do the main parsing
|
||||
char *current( &m_buffer[ 0 ] );
|
||||
char *end( &m_buffer[ m_buffer.size() - 1 ] + 1 );
|
||||
size_t pos( current - &m_buffer[ 0 ] );
|
||||
while( pos < m_buffer.size() ) {
|
||||
current = parseNextNode( current, end );
|
||||
pos = current - &m_buffer[ 0 ];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
char *OpenDDLParser::parseNextNode( char *in, char *end ) {
|
||||
in = parseHeader( in, end );
|
||||
in = parseStructure( in, end );
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
static void dumpId( Identifier *id ) {
|
||||
if( ddl_nullptr != id ) {
|
||||
std::cout << id->m_text.m_buffer << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
char *OpenDDLParser::parseHeader( char *in, char *end ) {
|
||||
if( ddl_nullptr == in || in == end ) {
|
||||
return in;
|
||||
}
|
||||
|
||||
Identifier *id( ddl_nullptr );
|
||||
in = OpenDDLParser::parseIdentifier( in, end, &id );
|
||||
|
||||
#ifdef DEBUG_HEADER_NAME
|
||||
dumpId( id );
|
||||
#endif // DEBUG_HEADER_NAME
|
||||
|
||||
in = lookForNextToken( in, end );
|
||||
Property *first( ddl_nullptr );
|
||||
if( ddl_nullptr != id ) {
|
||||
if( *in == '(' ) {
|
||||
in++;
|
||||
Property *prop( ddl_nullptr ), *prev( ddl_nullptr );
|
||||
while( *in != ')' && in != end ) {
|
||||
in = OpenDDLParser::parseProperty( in, end, &prop );
|
||||
in = lookForNextToken( in, end );
|
||||
|
||||
if( *in != ',' && *in != ')' ) {
|
||||
logInvalidTokenError( in, ")", m_logCallback );
|
||||
return in;
|
||||
}
|
||||
|
||||
if( ddl_nullptr != prop && *in != ',' ) {
|
||||
if( ddl_nullptr == first ) {
|
||||
first = prop;
|
||||
}
|
||||
if( ddl_nullptr != prev ) {
|
||||
prev->m_next = prop;
|
||||
}
|
||||
prev = prop;
|
||||
}
|
||||
}
|
||||
in++;
|
||||
}
|
||||
|
||||
// store the node
|
||||
DDLNode *node( createDDLNode( id, this ) );
|
||||
if( ddl_nullptr != node ) {
|
||||
pushNode( node );
|
||||
} else {
|
||||
std::cerr << "nullptr returned by creating DDLNode." << std::endl;
|
||||
}
|
||||
|
||||
// set the properties
|
||||
if( ddl_nullptr != first ) {
|
||||
node->setProperties( first );
|
||||
}
|
||||
|
||||
Name *name( ddl_nullptr );
|
||||
in = OpenDDLParser::parseName( in, end, &name );
|
||||
if( ddl_nullptr != name ) {
|
||||
const std::string nodeName( name->m_id->m_text.m_buffer );
|
||||
node->setName( nodeName );
|
||||
}
|
||||
}
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
char *OpenDDLParser::parseStructure( char *in, char *end ) {
|
||||
if( ddl_nullptr == in || in == end ) {
|
||||
return in;
|
||||
}
|
||||
|
||||
bool error( false );
|
||||
in = lookForNextToken( in, end );
|
||||
if( *in == '{' ) {
|
||||
// loop over all children ( data and nodes )
|
||||
do {
|
||||
in = parseStructureBody( in, end, error );
|
||||
} while ( *in != '}' );
|
||||
in++;
|
||||
} else {
|
||||
in++;
|
||||
logInvalidTokenError( in, std::string( Grammar::OpenBracketToken ), m_logCallback );
|
||||
error = true;
|
||||
return in;
|
||||
}
|
||||
in = lookForNextToken( in, end );
|
||||
|
||||
// pop node from stack after successful parsing
|
||||
if( !error ) {
|
||||
popNode();
|
||||
}
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
static void setNodeValues( DDLNode *currentNode, Value *values ) {
|
||||
if( ddl_nullptr != values ){
|
||||
if( ddl_nullptr != currentNode ) {
|
||||
currentNode->setValue( values );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void setNodeReferences( DDLNode *currentNode, Reference *refs ) {
|
||||
if( ddl_nullptr != refs ) {
|
||||
if( ddl_nullptr != currentNode ) {
|
||||
currentNode->setReferences( refs );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void setNodeDataArrayList( DDLNode *currentNode, DataArrayList *dtArrayList ) {
|
||||
if( ddl_nullptr != dtArrayList ) {
|
||||
if( ddl_nullptr != currentNode ) {
|
||||
currentNode->setDataArrayList( dtArrayList );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
char *OpenDDLParser::parseStructureBody( char *in, char *end, bool &error ) {
|
||||
if( !isNumeric( *in ) && !isCharacter( *in ) ) {
|
||||
in++;
|
||||
}
|
||||
|
||||
in = lookForNextToken( in, end );
|
||||
Value::ValueType type( Value::ddl_none );
|
||||
size_t arrayLen( 0 );
|
||||
in = OpenDDLParser::parsePrimitiveDataType( in, end, type, arrayLen );
|
||||
if( Value::ddl_none != type ) {
|
||||
// parse a primitive data type
|
||||
in = lookForNextToken( in, end );
|
||||
if( *in == '{' ) {
|
||||
Reference *refs( ddl_nullptr );
|
||||
DataArrayList *dtArrayList( ddl_nullptr );
|
||||
Value *values( ddl_nullptr );
|
||||
if( 1 == arrayLen ) {
|
||||
size_t numRefs( 0 ), numValues( 0 );
|
||||
in = parseDataList( in, end, &values, numValues, &refs, numRefs );
|
||||
setNodeValues( top(), values );
|
||||
setNodeReferences( top(), refs );
|
||||
} else if( arrayLen > 1 ) {
|
||||
in = parseDataArrayList( in, end, &dtArrayList );
|
||||
setNodeDataArrayList( top(), dtArrayList );
|
||||
} else {
|
||||
std::cerr << "0 for array is invalid." << std::endl;
|
||||
error = true;
|
||||
}
|
||||
}
|
||||
|
||||
in = lookForNextToken( in, end );
|
||||
if( *in != '}' ) {
|
||||
logInvalidTokenError( in, std::string( Grammar::CloseBracketToken ), m_logCallback );
|
||||
} else {
|
||||
//in++;
|
||||
}
|
||||
} else {
|
||||
// parse a complex data type
|
||||
in = parseNextNode( in, end );
|
||||
}
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
void OpenDDLParser::pushNode( DDLNode *node ) {
|
||||
if( ddl_nullptr == node ) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_stack.push_back( node );
|
||||
}
|
||||
|
||||
DDLNode *OpenDDLParser::popNode() {
|
||||
if( m_stack.empty() ) {
|
||||
return ddl_nullptr;
|
||||
}
|
||||
|
||||
DDLNode *topNode( top() );
|
||||
m_stack.pop_back();
|
||||
|
||||
return topNode;
|
||||
}
|
||||
|
||||
DDLNode *OpenDDLParser::top() {
|
||||
if( m_stack.empty() ) {
|
||||
return ddl_nullptr;
|
||||
}
|
||||
|
||||
DDLNode *top( m_stack.back() );
|
||||
return top;
|
||||
}
|
||||
|
||||
DDLNode *OpenDDLParser::getRoot() const {
|
||||
if( ddl_nullptr == m_context ) {
|
||||
return ddl_nullptr;
|
||||
}
|
||||
|
||||
return m_context->m_root;
|
||||
}
|
||||
|
||||
Context *OpenDDLParser::getContext() const {
|
||||
return m_context;
|
||||
}
|
||||
|
||||
void OpenDDLParser::normalizeBuffer( std::vector<char> &buffer) {
|
||||
if( buffer.empty() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<char> newBuffer;
|
||||
const size_t len( buffer.size() );
|
||||
char *end( &buffer[ len-1 ] + 1 );
|
||||
for( size_t readIdx = 0; readIdx<len; ++readIdx ) {
|
||||
char *c( &buffer[readIdx] );
|
||||
// check for a comment
|
||||
if( !isComment<char>( c, end ) && !isNewLine( *c ) ) {
|
||||
newBuffer.push_back( buffer[ readIdx ] );
|
||||
} else {
|
||||
if( isComment<char>( c, end ) ) {
|
||||
readIdx++;
|
||||
// skip the comment and the rest of the line
|
||||
while( !isEndofLine( buffer[ readIdx ] ) ) {
|
||||
readIdx++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
buffer = newBuffer;
|
||||
}
|
||||
|
||||
char *OpenDDLParser::parseName( char *in, char *end, Name **name ) {
|
||||
*name = ddl_nullptr;
|
||||
if( ddl_nullptr == in || in == end ) {
|
||||
return in;
|
||||
}
|
||||
|
||||
// ignore blanks
|
||||
in = lookForNextToken( in, end );
|
||||
if( *in != '$' && *in != '%' ) {
|
||||
return in;
|
||||
}
|
||||
|
||||
NameType ntype( GlobalName );
|
||||
if( *in == '%' ) {
|
||||
ntype = LocalName;
|
||||
}
|
||||
|
||||
Name *currentName( ddl_nullptr );
|
||||
Identifier *id( ddl_nullptr );
|
||||
in = parseIdentifier( in, end, &id );
|
||||
if( id ) {
|
||||
currentName = new Name( ntype, id );
|
||||
if( currentName ) {
|
||||
*name = currentName;
|
||||
}
|
||||
}
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
char *OpenDDLParser::parseIdentifier( char *in, char *end, Identifier **id ) {
|
||||
*id = ddl_nullptr;
|
||||
if( ddl_nullptr == in || in == end ) {
|
||||
return in;
|
||||
}
|
||||
|
||||
// ignore blanks
|
||||
in = lookForNextToken( in, end );
|
||||
|
||||
// staring with a number is forbidden
|
||||
if( isNumeric<const char>( *in ) ) {
|
||||
return in;
|
||||
}
|
||||
|
||||
// get size of id
|
||||
size_t idLen( 0 );
|
||||
char *start( in );
|
||||
while( !isSeparator( *in ) && !isNewLine( *in ) && ( in != end ) && *in != '(' && *in != ')' ) {
|
||||
in++;
|
||||
idLen++;
|
||||
}
|
||||
|
||||
const size_t len( idLen );
|
||||
Identifier *newId = new Identifier( start, len );
|
||||
*id = newId;
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
char *OpenDDLParser::parsePrimitiveDataType( char *in, char *end, Value::ValueType &type, size_t &len ) {
|
||||
type = Value::ddl_none;
|
||||
len = 0;
|
||||
if( ddl_nullptr == in || in == end ) {
|
||||
return in;
|
||||
}
|
||||
|
||||
size_t prim_len( 0 );
|
||||
for( unsigned int i = 0; i < Value::ddl_types_max; i++ ) {
|
||||
prim_len = strlen( Grammar::PrimitiveTypeToken[ i ] );
|
||||
if( 0 == strncmp( in, Grammar::PrimitiveTypeToken[ i ], prim_len ) ) {
|
||||
type = ( Value::ValueType ) i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( Value::ddl_none == type ) {
|
||||
in = lookForNextToken( in, end );
|
||||
return in;
|
||||
} else {
|
||||
in += prim_len;
|
||||
}
|
||||
|
||||
bool ok( true );
|
||||
if( *in == '[' ) {
|
||||
ok = false;
|
||||
in++;
|
||||
char *start( in );
|
||||
while ( in != end ) {
|
||||
in++;
|
||||
if( *in == ']' ) {
|
||||
len = atoi( start );
|
||||
ok = true;
|
||||
in++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
len = 1;
|
||||
}
|
||||
if( !ok ) {
|
||||
type = Value::ddl_none;
|
||||
}
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
char *OpenDDLParser::parseReference( char *in, char *end, std::vector<Name*> &names ) {
|
||||
if( ddl_nullptr == in || in == end ) {
|
||||
return in;
|
||||
}
|
||||
|
||||
Name *nextName( ddl_nullptr );
|
||||
in = parseName( in, end, &nextName );
|
||||
if( nextName ) {
|
||||
names.push_back( nextName );
|
||||
}
|
||||
while( ',' == *in ) {
|
||||
in = getNextSeparator( in, end );
|
||||
if( ',' == *in ) {
|
||||
in = parseName( in, end, &nextName );
|
||||
if( nextName ) {
|
||||
names.push_back( nextName );
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
char *OpenDDLParser::parseBooleanLiteral( char *in, char *end, Value **boolean ) {
|
||||
*boolean = ddl_nullptr;
|
||||
if( ddl_nullptr == in || in == end ) {
|
||||
return in;
|
||||
}
|
||||
|
||||
in = lookForNextToken( in, end );
|
||||
char *start( in );
|
||||
size_t len( 0 );
|
||||
while( !isSeparator( *in ) && in != end ) {
|
||||
in++;
|
||||
len++;
|
||||
}
|
||||
len++;
|
||||
int res = ::strncmp( Grammar::BoolTrue, start, strlen( Grammar::BoolTrue ) );
|
||||
if( 0 != res ) {
|
||||
res = ::strncmp( Grammar::BoolFalse, start, strlen( Grammar::BoolFalse ) );
|
||||
if( 0 != res ) {
|
||||
*boolean = ddl_nullptr;
|
||||
return in;
|
||||
}
|
||||
*boolean = ValueAllocator::allocPrimData( Value::ddl_bool );
|
||||
(*boolean)->setBool( false );
|
||||
} else {
|
||||
*boolean = ValueAllocator::allocPrimData( Value::ddl_bool );
|
||||
(*boolean)->setBool( true );
|
||||
}
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
char *OpenDDLParser::parseIntegerLiteral( char *in, char *end, Value **integer, Value::ValueType integerType ) {
|
||||
*integer = ddl_nullptr;
|
||||
if( ddl_nullptr == in || in == end ) {
|
||||
return in;
|
||||
}
|
||||
|
||||
if( !isIntegerType( integerType ) ) {
|
||||
return in;
|
||||
}
|
||||
|
||||
in = lookForNextToken( in, end );
|
||||
char *start( in );
|
||||
while( !isSeparator( *in ) && in != end ) {
|
||||
in++;
|
||||
}
|
||||
|
||||
if( isNumeric( *start ) ) {
|
||||
const int value( atoi( start ) );
|
||||
*integer = ValueAllocator::allocPrimData( integerType );
|
||||
switch( integerType ) {
|
||||
case Value::ddl_int8:
|
||||
( *integer )->setInt8( (int8) value );
|
||||
break;
|
||||
case Value::ddl_int16:
|
||||
( *integer )->setInt16( ( int16 ) value );
|
||||
break;
|
||||
case Value::ddl_int32:
|
||||
( *integer )->setInt32( ( int32 ) value );
|
||||
break;
|
||||
case Value::ddl_int64:
|
||||
( *integer )->setInt64( ( int64 ) value );
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
char *OpenDDLParser::parseFloatingLiteral( char *in, char *end, Value **floating ) {
|
||||
*floating = ddl_nullptr;
|
||||
if( ddl_nullptr == in || in == end ) {
|
||||
return in;
|
||||
}
|
||||
|
||||
in = lookForNextToken( in, end );
|
||||
char *start( in );
|
||||
while( !isSeparator( *in ) && in != end ) {
|
||||
in++;
|
||||
}
|
||||
|
||||
// parse the float value
|
||||
bool ok( false );
|
||||
if( isNumeric( *start ) ) {
|
||||
ok = true;
|
||||
} else {
|
||||
if( *start == '-' ) {
|
||||
if( isNumeric( *(start+1) ) ) {
|
||||
ok = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( ok ) {
|
||||
const float value( ( float ) atof( start ) );
|
||||
*floating = ValueAllocator::allocPrimData( Value::ddl_float );
|
||||
( *floating )->setFloat( value );
|
||||
}
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
char *OpenDDLParser::parseStringLiteral( char *in, char *end, Value **stringData ) {
|
||||
*stringData = ddl_nullptr;
|
||||
if( ddl_nullptr == in || in == end ) {
|
||||
return in;
|
||||
}
|
||||
|
||||
in = lookForNextToken( in, end );
|
||||
size_t len( 0 );
|
||||
char *start( in );
|
||||
if( *start == '\"' ) {
|
||||
start++;
|
||||
in++;
|
||||
while( *in != '\"' && in != end ) {
|
||||
in++;
|
||||
len++;
|
||||
}
|
||||
|
||||
*stringData = ValueAllocator::allocPrimData( Value::ddl_string, len );
|
||||
::strncpy( ( char* ) ( *stringData )->m_data, start, len );
|
||||
( *stringData )->m_data[len] = '\0';
|
||||
in++;
|
||||
}
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
static void createPropertyWithData( Identifier *id, Value *primData, Property **prop ) {
|
||||
if( ddl_nullptr != primData ) {
|
||||
( *prop ) = new Property( id );
|
||||
( *prop )->m_value = primData;
|
||||
}
|
||||
}
|
||||
|
||||
char *OpenDDLParser::parseHexaLiteral( char *in, char *end, Value **data ) {
|
||||
*data = ddl_nullptr;
|
||||
if( ddl_nullptr == in || in == end ) {
|
||||
return in;
|
||||
}
|
||||
|
||||
in = lookForNextToken( in, end );
|
||||
if( *in != '0' ) {
|
||||
return in;
|
||||
}
|
||||
|
||||
in++;
|
||||
if( *in != 'x' && *in != 'X' ) {
|
||||
return in;
|
||||
}
|
||||
|
||||
in++;
|
||||
bool ok( true );
|
||||
char *start( in );
|
||||
int pos( 0 );
|
||||
while( !isSeparator( *in ) && in != end ) {
|
||||
if( ( *in < '0' && *in > '9' ) || ( *in < 'a' && *in > 'f' ) || ( *in < 'A' && *in > 'F' ) ) {
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
pos++;
|
||||
in++;
|
||||
}
|
||||
|
||||
if( !ok ) {
|
||||
return in;
|
||||
}
|
||||
|
||||
int value( 0 );
|
||||
while( pos > 0 ) {
|
||||
int v = hex2Decimal( *start );
|
||||
pos--;
|
||||
value = ( value << 4 ) | v;
|
||||
start++;
|
||||
}
|
||||
|
||||
*data = ValueAllocator::allocPrimData( Value::ddl_unsigned_int64 );
|
||||
if( ddl_nullptr != *data ) {
|
||||
( *data )->setUnsignedInt64( value );
|
||||
}
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
char *OpenDDLParser::parseProperty( char *in, char *end, Property **prop ) {
|
||||
*prop = ddl_nullptr;
|
||||
if( ddl_nullptr == in || in == end ) {
|
||||
return in;
|
||||
}
|
||||
|
||||
in = lookForNextToken( in, end );
|
||||
Identifier *id( ddl_nullptr );
|
||||
in = parseIdentifier( in, end, &id );
|
||||
if( ddl_nullptr != id ) {
|
||||
in = lookForNextToken( in, end );
|
||||
if( *in == '=' ) {
|
||||
in++;
|
||||
in = getNextToken( in, end );
|
||||
Value *primData( ddl_nullptr );
|
||||
if( isInteger( in, end ) ) {
|
||||
in = parseIntegerLiteral( in, end, &primData );
|
||||
createPropertyWithData( id, primData, prop );
|
||||
} else if( isFloat( in, end ) ) {
|
||||
in = parseFloatingLiteral( in, end, &primData );
|
||||
createPropertyWithData( id, primData, prop );
|
||||
} else if( isStringLiteral( *in ) ) { // string data
|
||||
in = parseStringLiteral( in, end, &primData );
|
||||
createPropertyWithData( id, primData, prop );
|
||||
} else { // reference data
|
||||
std::vector<Name*> names;
|
||||
in = parseReference( in, end, names );
|
||||
if( !names.empty() ) {
|
||||
Reference *ref = new Reference( names.size(), &names[ 0 ] );
|
||||
( *prop ) = new Property( id );
|
||||
( *prop )->m_ref = ref;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
char *OpenDDLParser::parseDataList( char *in, char *end, Value **data, size_t &numValues, Reference **refs, size_t &numRefs ) {
|
||||
*data = ddl_nullptr;
|
||||
numValues = numRefs = 0;
|
||||
if( ddl_nullptr == in || in == end ) {
|
||||
return in;
|
||||
}
|
||||
|
||||
in = lookForNextToken( in, end );
|
||||
if( *in == '{' ) {
|
||||
in++;
|
||||
Value *current( ddl_nullptr ), *prev( ddl_nullptr );
|
||||
while( '}' != *in ) {
|
||||
current = ddl_nullptr;
|
||||
in = lookForNextToken( in, end );
|
||||
if( isInteger( in, end ) ) {
|
||||
in = parseIntegerLiteral( in, end, ¤t );
|
||||
} else if( isFloat( in, end ) ) {
|
||||
in = parseFloatingLiteral( in, end, ¤t );
|
||||
} else if( isStringLiteral( *in ) ) {
|
||||
in = parseStringLiteral( in, end, ¤t );
|
||||
} else if( isHexLiteral( in, end ) ) {
|
||||
in = parseHexaLiteral( in, end, ¤t );
|
||||
} else { // reference data
|
||||
std::vector<Name*> names;
|
||||
in = parseReference( in, end, names );
|
||||
if( !names.empty() ) {
|
||||
Reference *ref = new Reference( names.size(), &names[ 0 ] );
|
||||
*refs = ref;
|
||||
numRefs = names.size();
|
||||
}
|
||||
}
|
||||
|
||||
if( ddl_nullptr != current ) {
|
||||
if( ddl_nullptr == *data ) {
|
||||
*data = current;
|
||||
prev = current;
|
||||
} else {
|
||||
prev->setNext( current );
|
||||
prev = current;
|
||||
}
|
||||
numValues++;
|
||||
}
|
||||
|
||||
in = getNextSeparator( in, end );
|
||||
if( ',' != *in && '}' != *in && !isSpace( *in ) ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
in++;
|
||||
}
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
static DataArrayList *createDataArrayList( Value *currentValue, size_t numValues ) {
|
||||
DataArrayList *dataList = new DataArrayList;
|
||||
dataList->m_dataList = currentValue;
|
||||
dataList->m_numItems = numValues;
|
||||
|
||||
return dataList;
|
||||
|
||||
}
|
||||
char *OpenDDLParser::parseDataArrayList( char *in, char *end, DataArrayList **dataList ) {
|
||||
*dataList = ddl_nullptr;
|
||||
if( ddl_nullptr == in || in == end ) {
|
||||
return in;
|
||||
}
|
||||
|
||||
in = lookForNextToken( in, end );
|
||||
if( *in == Grammar::OpenBracketToken[ 0 ] ) {
|
||||
in++;
|
||||
Value *currentValue( ddl_nullptr );
|
||||
Reference *refs( ddl_nullptr );
|
||||
DataArrayList *prev( ddl_nullptr ), *currentDataList( ddl_nullptr );
|
||||
do {
|
||||
size_t numRefs( 0 ), numValues( 0 );
|
||||
currentValue = ddl_nullptr;
|
||||
in = parseDataList( in, end, ¤tValue, numValues, &refs, numRefs );
|
||||
if( ddl_nullptr != currentValue ) {
|
||||
if( ddl_nullptr == prev ) {
|
||||
*dataList = createDataArrayList( currentValue, numValues );
|
||||
prev = *dataList;
|
||||
} else {
|
||||
currentDataList = createDataArrayList( currentValue, numValues );
|
||||
if( ddl_nullptr != prev ) {
|
||||
prev->m_next = currentDataList;
|
||||
prev = currentDataList;
|
||||
}
|
||||
}
|
||||
}
|
||||
} while( Grammar::CommaSeparator[ 0 ] == *in && in != end );
|
||||
in = lookForNextToken( in, end );
|
||||
in++;
|
||||
}
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
const char *OpenDDLParser::getVersion() {
|
||||
return Version;
|
||||
}
|
||||
|
||||
END_ODDLPARSER_NS
|
|
@ -1,336 +0,0 @@
|
|||
/*-----------------------------------------------------------------------------------------------
|
||||
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
|
||||
|
||||
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() {
|
||||
// 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;
|
||||
}
|
||||
|
||||
Value::Value( ValueType type )
|
||||
: m_type( type )
|
||||
, m_size( 0 )
|
||||
, m_data( ddl_nullptr )
|
||||
, m_next( ddl_nullptr ) {
|
||||
// empty
|
||||
}
|
||||
|
||||
Value::~Value() {
|
||||
// empty
|
||||
}
|
||||
|
||||
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 ) ? true : false;
|
||||
}
|
||||
|
||||
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 );
|
||||
return ( int16 ) ( *m_data );
|
||||
}
|
||||
|
||||
void Value::setInt32( int32 value ) {
|
||||
assert( ddl_int32 == m_type );
|
||||
::memcpy( m_data, &value, m_size );
|
||||
}
|
||||
|
||||
int32 Value::getInt32() {
|
||||
assert( ddl_int32 == m_type );
|
||||
return ( int32 ) ( *m_data );
|
||||
}
|
||||
|
||||
void Value::setInt64( int64 value ) {
|
||||
assert( ddl_int32 == m_type );
|
||||
::memcpy( m_data, &value, m_size );
|
||||
}
|
||||
|
||||
int64 Value::getInt64() {
|
||||
return ( int64 ) ( *m_data );
|
||||
}
|
||||
|
||||
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 );
|
||||
return ( uint8 ) ( *m_data );
|
||||
}
|
||||
|
||||
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 );
|
||||
return ( uint8 ) ( *m_data );
|
||||
}
|
||||
|
||||
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 );
|
||||
return ( uint8 ) ( *m_data );
|
||||
}
|
||||
|
||||
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 );
|
||||
return ( uint64 ) ( *m_data );
|
||||
}
|
||||
|
||||
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 {
|
||||
double v;
|
||||
::memcpy( &v, m_data, m_size );
|
||||
return v;
|
||||
}
|
||||
|
||||
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 {
|
||||
return (const char*) m_data;
|
||||
}
|
||||
|
||||
void Value::dump() {
|
||||
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 << "Not supported" << 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;
|
||||
}
|
||||
|
||||
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 );
|
||||
data->m_type = type;
|
||||
switch( type ) {
|
||||
case Value::ddl_bool:
|
||||
data->m_size = sizeof( bool );
|
||||
break;
|
||||
case Value::ddl_int8:
|
||||
data->m_size = sizeof( char );
|
||||
break;
|
||||
case Value::ddl_int16:
|
||||
data->m_size = sizeof( short );
|
||||
break;
|
||||
case Value::ddl_int32:
|
||||
data->m_size = sizeof( int );
|
||||
break;
|
||||
case Value::ddl_int64:
|
||||
data->m_size = sizeof( int64 );
|
||||
break;
|
||||
case Value::ddl_unsigned_int8:
|
||||
data->m_size = sizeof( unsigned char );
|
||||
break;
|
||||
case Value::ddl_unsigned_int32:
|
||||
data->m_size = sizeof( unsigned int );
|
||||
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 );
|
||||
break;
|
||||
case Value::ddl_ref:
|
||||
data->m_size = sizeof( char );
|
||||
break;
|
||||
case Value::ddl_none:
|
||||
case Value::ddl_types_max:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if( data->m_size ) {
|
||||
size_t len1( len );
|
||||
if( Value::ddl_string == type ) {
|
||||
len1++;
|
||||
}
|
||||
data->m_size *= len1;
|
||||
data->m_data = new unsigned char[ data->m_size ];
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
void ValueAllocator::releasePrimData( Value **data ) {
|
||||
if( !data ) {
|
||||
return;
|
||||
}
|
||||
|
||||
delete *data;
|
||||
*data = ddl_nullptr;
|
||||
}
|
||||
|
||||
END_ODDLPARSER_NS
|
|
@ -161,11 +161,11 @@
|
|||
7F7924C21AB43E20005A8E5D /* sweep_context.cc in Sources */ = {isa = PBXBuildFile; fileRef = 5E10483FBE6D4F4594B460E0 /* sweep_context.cc */; };
|
||||
7F7924C31AB43E20005A8E5D /* ioapi.c in Sources */ = {isa = PBXBuildFile; fileRef = AF75E6049338489BB256D295 /* ioapi.c */; };
|
||||
7F7924C41AB43E20005A8E5D /* unzip.c in Sources */ = {isa = PBXBuildFile; fileRef = 973D4231A4AA4925B019FEEE /* unzip.c */; };
|
||||
7F7A93A81B65D0110094C4DA /* DDLNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7F7A93A51B65D0110094C4DA /* DDLNode.cpp */; };
|
||||
7F7A93A91B65D0110094C4DA /* OpenDDLParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7F7A93A61B65D0110094C4DA /* OpenDDLParser.cpp */; };
|
||||
7F7A93AA1B65D0110094C4DA /* Value.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7F7A93A71B65D0110094C4DA /* Value.cpp */; };
|
||||
7FBE9FEA1B65AC1200D2115E /* OpenGEXExporter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7FBE9FE51B65AC1200D2115E /* OpenGEXExporter.cpp */; };
|
||||
7FBE9FEB1B65AC1200D2115E /* OpenGEXImporter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7FBE9FE71B65AC1200D2115E /* OpenGEXImporter.cpp */; };
|
||||
7FBEA00E1B65AF9200D2115E /* DDLNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7FBEA0061B65AF9200D2115E /* DDLNode.cpp */; };
|
||||
7FBEA00F1B65AF9200D2115E /* OpenDDLParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7FBEA0091B65AF9200D2115E /* OpenDDLParser.cpp */; };
|
||||
7FBEA0101B65AF9200D2115E /* Value.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7FBEA00C1B65AF9200D2115E /* Value.cpp */; };
|
||||
7FBEA0121B65B11800D2115E /* Version.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7FBEA0111B65B11800D2115E /* Version.cpp */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
|
@ -368,18 +368,18 @@
|
|||
7F29EF981AB26C4900E9D380 /* libz.1.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.1.dylib; path = /usr/lib/libz.1.dylib; sourceTree = "<absolute>"; };
|
||||
7F392D921AB2C7BB00D952EB /* libc++.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = "libc++.dylib"; path = "/usr/lib/libc++.dylib"; sourceTree = "<absolute>"; };
|
||||
7F7922801AB43AC3005A8E5D /* libassimp.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libassimp.a; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
7F7A93A51B65D0110094C4DA /* DDLNode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DDLNode.cpp; path = contrib/openddlparser/code/DDLNode.cpp; sourceTree = "<group>"; };
|
||||
7F7A93A61B65D0110094C4DA /* OpenDDLParser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = OpenDDLParser.cpp; path = contrib/openddlparser/code/OpenDDLParser.cpp; sourceTree = "<group>"; };
|
||||
7F7A93A71B65D0110094C4DA /* Value.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Value.cpp; path = contrib/openddlparser/code/Value.cpp; sourceTree = "<group>"; };
|
||||
7FBE9FE51B65AC1200D2115E /* OpenGEXExporter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = OpenGEXExporter.cpp; path = code/OpenGEXExporter.cpp; sourceTree = "<group>"; };
|
||||
7FBE9FE61B65AC1200D2115E /* OpenGEXExporter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OpenGEXExporter.h; path = code/OpenGEXExporter.h; sourceTree = "<group>"; };
|
||||
7FBE9FE71B65AC1200D2115E /* OpenGEXImporter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = OpenGEXImporter.cpp; path = code/OpenGEXImporter.cpp; sourceTree = "<group>"; };
|
||||
7FBE9FE81B65AC1200D2115E /* OpenGEXImporter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OpenGEXImporter.h; path = code/OpenGEXImporter.h; sourceTree = "<group>"; };
|
||||
7FBE9FE91B65AC1200D2115E /* OpenGEXStructs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OpenGEXStructs.h; path = code/OpenGEXStructs.h; sourceTree = "<group>"; };
|
||||
7FBEA0061B65AF9200D2115E /* DDLNode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DDLNode.cpp; path = contrib/openddlparser/include/openddlparser/DDLNode.cpp; sourceTree = "<group>"; };
|
||||
7FBEA0071B65AF9200D2115E /* DDLNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DDLNode.h; path = contrib/openddlparser/include/openddlparser/DDLNode.h; sourceTree = "<group>"; };
|
||||
7FBEA0081B65AF9200D2115E /* OpenDDLCommon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OpenDDLCommon.h; path = contrib/openddlparser/include/openddlparser/OpenDDLCommon.h; sourceTree = "<group>"; };
|
||||
7FBEA0091B65AF9200D2115E /* OpenDDLParser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = OpenDDLParser.cpp; path = contrib/openddlparser/include/openddlparser/OpenDDLParser.cpp; sourceTree = "<group>"; };
|
||||
7FBEA00A1B65AF9200D2115E /* OpenDDLParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OpenDDLParser.h; path = contrib/openddlparser/include/openddlparser/OpenDDLParser.h; sourceTree = "<group>"; };
|
||||
7FBEA00B1B65AF9200D2115E /* OpenDDLParserUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OpenDDLParserUtils.h; path = contrib/openddlparser/include/openddlparser/OpenDDLParserUtils.h; sourceTree = "<group>"; };
|
||||
7FBEA00C1B65AF9200D2115E /* Value.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Value.cpp; path = contrib/openddlparser/include/openddlparser/Value.cpp; sourceTree = "<group>"; };
|
||||
7FBEA00D1B65AF9200D2115E /* Value.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Value.h; path = contrib/openddlparser/include/openddlparser/Value.h; sourceTree = "<group>"; };
|
||||
7FBEA0111B65B11800D2115E /* Version.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Version.cpp; path = code/Version.cpp; sourceTree = "<group>"; };
|
||||
7FF72CB6E99E40E19AE0E64C /* MaterialSystem.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.cpp; fileEncoding = 4; name = MaterialSystem.cpp; path = code/MaterialSystem.cpp; sourceTree = SOURCE_ROOT; };
|
||||
|
@ -1079,14 +1079,14 @@
|
|||
7FBEA0051B65AF8900D2115E /* openddlparser */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
7FBEA0061B65AF9200D2115E /* DDLNode.cpp */,
|
||||
7FBEA0071B65AF9200D2115E /* DDLNode.h */,
|
||||
7FBEA0081B65AF9200D2115E /* OpenDDLCommon.h */,
|
||||
7FBEA0091B65AF9200D2115E /* OpenDDLParser.cpp */,
|
||||
7FBEA00A1B65AF9200D2115E /* OpenDDLParser.h */,
|
||||
7FBEA00B1B65AF9200D2115E /* OpenDDLParserUtils.h */,
|
||||
7FBEA00C1B65AF9200D2115E /* Value.cpp */,
|
||||
7FBEA0071B65AF9200D2115E /* DDLNode.h */,
|
||||
7F7A93A51B65D0110094C4DA /* DDLNode.cpp */,
|
||||
7FBEA00A1B65AF9200D2115E /* OpenDDLParser.h */,
|
||||
7F7A93A61B65D0110094C4DA /* OpenDDLParser.cpp */,
|
||||
7FBEA00D1B65AF9200D2115E /* Value.h */,
|
||||
7F7A93A71B65D0110094C4DA /* Value.cpp */,
|
||||
);
|
||||
name = openddlparser;
|
||||
sourceTree = "<group>";
|
||||
|
@ -1592,11 +1592,11 @@
|
|||
7F79244A1AB43E20005A8E5D /* DeboneProcess.cpp in Sources */,
|
||||
7F79244B1AB43E20005A8E5D /* DefaultIOStream.cpp in Sources */,
|
||||
7F79244C1AB43E20005A8E5D /* DefaultIOSystem.cpp in Sources */,
|
||||
7F7A93A81B65D0110094C4DA /* DDLNode.cpp in Sources */,
|
||||
7F79244D1AB43E20005A8E5D /* DefaultLogger.cpp in Sources */,
|
||||
7F79244E1AB43E20005A8E5D /* Exporter.cpp in Sources */,
|
||||
7F79244F1AB43E20005A8E5D /* FBXAnimation.cpp in Sources */,
|
||||
7F7924501AB43E20005A8E5D /* FBXBinaryTokenizer.cpp in Sources */,
|
||||
7FBEA0101B65AF9200D2115E /* Value.cpp in Sources */,
|
||||
7F7924511AB43E20005A8E5D /* FBXConverter.cpp in Sources */,
|
||||
7F7924521AB43E20005A8E5D /* FBXDeformer.cpp in Sources */,
|
||||
7F7924531AB43E20005A8E5D /* FBXDocument.cpp in Sources */,
|
||||
|
@ -1610,6 +1610,7 @@
|
|||
7F79245B1AB43E20005A8E5D /* FBXProperties.cpp in Sources */,
|
||||
7F79245C1AB43E20005A8E5D /* FBXTokenizer.cpp in Sources */,
|
||||
7F79245D1AB43E20005A8E5D /* FBXUtil.cpp in Sources */,
|
||||
7F7A93A91B65D0110094C4DA /* OpenDDLParser.cpp in Sources */,
|
||||
7F79245E1AB43E20005A8E5D /* FindDegenerates.cpp in Sources */,
|
||||
7F79245F1AB43E20005A8E5D /* FindInstancesProcess.cpp in Sources */,
|
||||
7F7924601AB43E20005A8E5D /* FindInvalidDataProcess.cpp in Sources */,
|
||||
|
@ -1632,7 +1633,6 @@
|
|||
7F7924701AB43E20005A8E5D /* IRRShared.cpp in Sources */,
|
||||
7F7924711AB43E20005A8E5D /* Importer.cpp in Sources */,
|
||||
7F7924721AB43E20005A8E5D /* ImporterRegistry.cpp in Sources */,
|
||||
7FBEA00E1B65AF9200D2115E /* DDLNode.cpp in Sources */,
|
||||
7F7924731AB43E20005A8E5D /* ImproveCacheLocality.cpp in Sources */,
|
||||
7F7924741AB43E20005A8E5D /* JoinVerticesProcess.cpp in Sources */,
|
||||
7F7924751AB43E20005A8E5D /* LWOAnimation.cpp in Sources */,
|
||||
|
@ -1641,7 +1641,6 @@
|
|||
7F7924781AB43E20005A8E5D /* LWOMaterial.cpp in Sources */,
|
||||
7F7924791AB43E20005A8E5D /* LWSLoader.cpp in Sources */,
|
||||
7F79247A1AB43E20005A8E5D /* LimitBoneWeightsProcess.cpp in Sources */,
|
||||
7FBEA00F1B65AF9200D2115E /* OpenDDLParser.cpp in Sources */,
|
||||
7F79247B1AB43E20005A8E5D /* MD2Loader.cpp in Sources */,
|
||||
7F79247C1AB43E20005A8E5D /* MD3Loader.cpp in Sources */,
|
||||
7F79247D1AB43E20005A8E5D /* MD5Loader.cpp in Sources */,
|
||||
|
@ -1673,6 +1672,7 @@
|
|||
7F7924961AB43E20005A8E5D /* PostStepRegistry.cpp in Sources */,
|
||||
7F7924971AB43E20005A8E5D /* PretransformVertices.cpp in Sources */,
|
||||
7F7924981AB43E20005A8E5D /* ProcessHelper.cpp in Sources */,
|
||||
7F7A93AA1B65D0110094C4DA /* Value.cpp in Sources */,
|
||||
7F7924991AB43E20005A8E5D /* Q3BSPFileImporter.cpp in Sources */,
|
||||
7F79249A1AB43E20005A8E5D /* Q3BSPFileParser.cpp in Sources */,
|
||||
7F79249B1AB43E20005A8E5D /* Q3BSPZipArchive.cpp in Sources */,
|
||||
|
|
Loading…
Reference in New Issue