openddlparser: closes https://github.com/assimp/assimp/issues/1271.
parent
d3140a68ab
commit
51b915c97b
|
@ -68,8 +68,8 @@ DDLNode::DDLNode( const std::string &type, const std::string &name, size_t idx,
|
||||||
}
|
}
|
||||||
|
|
||||||
DDLNode::~DDLNode() {
|
DDLNode::~DDLNode() {
|
||||||
releaseDataType<Property>( m_properties );
|
delete m_properties;
|
||||||
releaseDataType<Value>( m_value );
|
delete m_value;
|
||||||
releaseReferencedNames( m_references );
|
releaseReferencedNames( m_references );
|
||||||
|
|
||||||
delete m_dtArrayList;
|
delete m_dtArrayList;
|
||||||
|
@ -77,6 +77,9 @@ DDLNode::~DDLNode() {
|
||||||
if( s_allocatedNodes[ m_idx ] == this ) {
|
if( s_allocatedNodes[ m_idx ] == this ) {
|
||||||
s_allocatedNodes[ m_idx ] = ddl_nullptr;
|
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 ) {
|
void DDLNode::attachParent( DDLNode *parent ) {
|
||||||
|
@ -91,9 +94,8 @@ void DDLNode::attachParent( DDLNode *parent ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DDLNode::detachParent() {
|
void DDLNode::detachParent() {
|
||||||
if( m_parent ) {
|
if( ddl_nullptr != m_parent ) {
|
||||||
std::vector<DDLNode*>::iterator it;
|
DDLNodeIt it = std::find( m_parent->m_children.begin(), m_parent->m_children.end(), this );
|
||||||
it = std::find( m_parent->m_children.begin(), m_parent->m_children.end(), this );
|
|
||||||
if( m_parent->m_children.end() != it ) {
|
if( m_parent->m_children.end() != it ) {
|
||||||
m_parent->m_children.erase( it );
|
m_parent->m_children.erase( it );
|
||||||
}
|
}
|
||||||
|
@ -126,6 +128,8 @@ const std::string &DDLNode::getName() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DDLNode::setProperties( Property *prop ) {
|
void DDLNode::setProperties( Property *prop ) {
|
||||||
|
if(m_properties!=ddl_nullptr)
|
||||||
|
delete m_properties;
|
||||||
m_properties = prop;
|
m_properties = prop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,7 +201,7 @@ DDLNode *DDLNode::create( const std::string &type, const std::string &name, DDLN
|
||||||
|
|
||||||
void DDLNode::releaseNodes() {
|
void DDLNode::releaseNodes() {
|
||||||
if( s_allocatedNodes.size() > 0 ) {
|
if( s_allocatedNodes.size() > 0 ) {
|
||||||
for( DllNodeList::iterator it = s_allocatedNodes.begin(); it != s_allocatedNodes.end(); it++ ) {
|
for( DDLNodeIt it = s_allocatedNodes.begin(); it != s_allocatedNodes.end(); it++ ) {
|
||||||
if( *it ) {
|
if( *it ) {
|
||||||
delete *it;
|
delete *it;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
-----------------------------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------------------------*/
|
||||||
#include <openddlparser/OpenDDLCommon.h>
|
#include <openddlparser/OpenDDLCommon.h>
|
||||||
#include <openddlparser/DDLNode.h>
|
#include <openddlparser/DDLNode.h>
|
||||||
|
#include <openddlparser/Value.h>
|
||||||
|
|
||||||
BEGIN_ODDLPARSER_NS
|
BEGIN_ODDLPARSER_NS
|
||||||
|
|
||||||
|
@ -84,7 +85,14 @@ Name::~Name() {
|
||||||
m_id = ddl_nullptr;
|
m_id = ddl_nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference::Reference()
|
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_numRefs( 0 )
|
||||||
, m_referencedName( ddl_nullptr ) {
|
, m_referencedName( ddl_nullptr ) {
|
||||||
// empty
|
// empty
|
||||||
|
@ -96,8 +104,16 @@ Reference::Reference( size_t numrefs, Name **names )
|
||||||
if ( numrefs > 0 ) {
|
if ( numrefs > 0 ) {
|
||||||
m_referencedName = new Name *[ numrefs ];
|
m_referencedName = new Name *[ numrefs ];
|
||||||
for ( size_t i = 0; i < numrefs; i++ ) {
|
for ( size_t i = 0; i < numrefs; i++ ) {
|
||||||
Name *name = new Name( names[ i ]->m_type, names[ i ]->m_id );
|
m_referencedName[ i ] = names[i];
|
||||||
m_referencedName[ i ] = name;
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -107,6 +123,7 @@ Reference::~Reference() {
|
||||||
delete m_referencedName[ i ];
|
delete m_referencedName[ i ];
|
||||||
}
|
}
|
||||||
m_numRefs = 0;
|
m_numRefs = 0;
|
||||||
|
delete [] m_referencedName;
|
||||||
m_referencedName = ddl_nullptr;
|
m_referencedName = ddl_nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,21 +152,30 @@ Property::Property( Text *id )
|
||||||
}
|
}
|
||||||
|
|
||||||
Property::~Property() {
|
Property::~Property() {
|
||||||
m_key = ddl_nullptr;
|
delete m_key;
|
||||||
m_value = ddl_nullptr;
|
if(m_value!=ddl_nullptr)
|
||||||
m_ref = ddl_nullptr;;
|
delete m_value;
|
||||||
m_next = ddl_nullptr;;
|
if(m_ref!=ddl_nullptr)
|
||||||
|
delete(m_ref);
|
||||||
|
if(m_next!=ddl_nullptr)
|
||||||
|
delete m_next;
|
||||||
}
|
}
|
||||||
|
|
||||||
DataArrayList::DataArrayList()
|
DataArrayList::DataArrayList()
|
||||||
: m_numItems( 0 )
|
: m_numItems( 0 )
|
||||||
, m_dataList( ddl_nullptr )
|
, m_dataList( ddl_nullptr )
|
||||||
, m_next( ddl_nullptr ) {
|
, m_next( ddl_nullptr )
|
||||||
|
, m_refs(ddl_nullptr)
|
||||||
|
, m_numRefs(0){
|
||||||
// empty
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
DataArrayList::~DataArrayList() {
|
DataArrayList::~DataArrayList() {
|
||||||
// empty
|
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 DataArrayList::size() {
|
||||||
|
|
|
@ -280,7 +280,7 @@ bool OpenDDLExport::writeValueType( Value::ValueType type, size_t numItems, std:
|
||||||
statement += "[";
|
statement += "[";
|
||||||
char buffer[ 256 ];
|
char buffer[ 256 ];
|
||||||
::memset( buffer, '\0', 256 * sizeof( char ) );
|
::memset( buffer, '\0', 256 * sizeof( char ) );
|
||||||
sprintf( buffer, "%d", int(numItems) );
|
sprintf( buffer, "%d", static_cast<int>( numItems ) );
|
||||||
statement += buffer;
|
statement += buffer;
|
||||||
statement += "]";
|
statement += "]";
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
BEGIN_ODDLPARSER_NS
|
BEGIN_ODDLPARSER_NS
|
||||||
|
|
||||||
static const char *Version = "0.3.0";
|
static const char *Version = "0.4.0";
|
||||||
|
|
||||||
namespace Grammar {
|
namespace Grammar {
|
||||||
static const char *OpenBracketToken = "{";
|
static const char *OpenBracketToken = "{";
|
||||||
|
@ -49,7 +49,7 @@ namespace Grammar {
|
||||||
static const char *BoolFalse = "false";
|
static const char *BoolFalse = "false";
|
||||||
static const char *CommaSeparator = ",";
|
static const char *CommaSeparator = ",";
|
||||||
|
|
||||||
static const char* PrimitiveTypeToken[ Value::ddl_types_max ] = {
|
static const char *PrimitiveTypeToken[ Value::ddl_types_max ] = {
|
||||||
"bool",
|
"bool",
|
||||||
"int8",
|
"int8",
|
||||||
"int16",
|
"int16",
|
||||||
|
@ -74,8 +74,8 @@ const char *getTypeToken( Value::ValueType type ) {
|
||||||
static void logInvalidTokenError( char *in, const std::string &exp, OpenDDLParser::logCallback callback ) {
|
static void logInvalidTokenError( char *in, const std::string &exp, OpenDDLParser::logCallback callback ) {
|
||||||
std::stringstream stream;
|
std::stringstream stream;
|
||||||
stream << "Invalid token \"" << *in << "\"" << " expected \"" << exp << "\"" << std::endl;
|
stream << "Invalid token \"" << *in << "\"" << " expected \"" << exp << "\"" << std::endl;
|
||||||
std::string full(in);
|
std::string full( in );
|
||||||
std::string part(full.substr(0,50));
|
std::string part( full.substr( 0, 50 ) );
|
||||||
stream << part;
|
stream << part;
|
||||||
callback( ddl_error_msg, stream.str() );
|
callback( ddl_error_msg, stream.str() );
|
||||||
}
|
}
|
||||||
|
@ -85,6 +85,7 @@ static bool isIntegerType( Value::ValueType integerType ) {
|
||||||
integerType != Value::ddl_int32 && integerType != Value::ddl_int64 ) {
|
integerType != Value::ddl_int32 && integerType != Value::ddl_int64 ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,7 +106,7 @@ static DDLNode *createDDLNode( Text *id, OpenDDLParser *parser ) {
|
||||||
const std::string type( id->m_buffer );
|
const std::string type( id->m_buffer );
|
||||||
DDLNode *parent( parser->top() );
|
DDLNode *parent( parser->top() );
|
||||||
DDLNode *node = DDLNode::create( type, "", parent );
|
DDLNode *node = DDLNode::create( type, "", parent );
|
||||||
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,10 +194,11 @@ size_t OpenDDLParser::getBufferSize() const {
|
||||||
void OpenDDLParser::clear() {
|
void OpenDDLParser::clear() {
|
||||||
m_buffer.resize( 0 );
|
m_buffer.resize( 0 );
|
||||||
if( ddl_nullptr != m_context ) {
|
if( ddl_nullptr != m_context ) {
|
||||||
m_context->m_root = ddl_nullptr;
|
delete m_context;
|
||||||
|
m_context=ddl_nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
DDLNode::releaseNodes();
|
// DDLNode::releaseNodes();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OpenDDLParser::parse() {
|
bool OpenDDLParser::parse() {
|
||||||
|
@ -212,11 +214,11 @@ bool OpenDDLParser::parse() {
|
||||||
|
|
||||||
// do the main parsing
|
// do the main parsing
|
||||||
char *current( &m_buffer[ 0 ] );
|
char *current( &m_buffer[ 0 ] );
|
||||||
char *end( &m_buffer[ m_buffer.size() - 1 ] + 1 );
|
char *end( &m_buffer[m_buffer.size() - 1 ] + 1 );
|
||||||
size_t pos( current - &m_buffer[ 0 ] );
|
size_t pos( current - &m_buffer[ 0 ] );
|
||||||
while( pos < m_buffer.size() ) {
|
while( pos < m_buffer.size() ) {
|
||||||
current = parseNextNode( current, end );
|
current = parseNextNode( current, end );
|
||||||
if(current==ddl_nullptr) {
|
if ( current == ddl_nullptr ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
pos = current - &m_buffer[ 0 ];
|
pos = current - &m_buffer[ 0 ];
|
||||||
|
@ -245,7 +247,7 @@ static void dumpId( Identifier *id ) {
|
||||||
if( ddl_nullptr != id ) {
|
if( ddl_nullptr != id ) {
|
||||||
if ( ddl_nullptr != id->m_text.m_buffer ) {
|
if ( ddl_nullptr != id->m_text.m_buffer ) {
|
||||||
std::cout << id->m_text.m_buffer << std::endl;
|
std::cout << id->m_text.m_buffer << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -271,14 +273,17 @@ char *OpenDDLParser::parseHeader( char *in, char *end ) {
|
||||||
} else {
|
} else {
|
||||||
std::cerr << "nullptr returned by creating DDLNode." << std::endl;
|
std::cerr << "nullptr returned by creating DDLNode." << std::endl;
|
||||||
}
|
}
|
||||||
|
delete id;
|
||||||
|
|
||||||
Name *name(ddl_nullptr);
|
Name *name(ddl_nullptr);
|
||||||
in = OpenDDLParser::parseName(in, end, &name);
|
in = OpenDDLParser::parseName(in, end, &name);
|
||||||
if( ddl_nullptr != name && ddl_nullptr != node ) {
|
if( ddl_nullptr != name && ddl_nullptr != node ) {
|
||||||
const std::string nodeName( name->m_id->m_buffer );
|
const std::string nodeName( name->m_id->m_buffer );
|
||||||
node->setName( nodeName );
|
node->setName( nodeName );
|
||||||
|
delete name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Property *first(ddl_nullptr);
|
Property *first(ddl_nullptr);
|
||||||
in = lookForNextToken(in, end);
|
in = lookForNextToken(in, end);
|
||||||
if (*in == Grammar::OpenPropertyToken[0]) {
|
if (*in == Grammar::OpenPropertyToken[0]) {
|
||||||
|
@ -303,7 +308,7 @@ char *OpenDDLParser::parseHeader( char *in, char *end ) {
|
||||||
prev = prop;
|
prev = prop;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
in++;
|
++in;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the properties
|
// set the properties
|
||||||
|
@ -330,9 +335,9 @@ char *OpenDDLParser::parseStructure( char *in, char *end ) {
|
||||||
return ddl_nullptr;
|
return ddl_nullptr;
|
||||||
}
|
}
|
||||||
} while ( *in != '}' );
|
} while ( *in != '}' );
|
||||||
in++;
|
++in;
|
||||||
} else {
|
} else {
|
||||||
in++;
|
++in;
|
||||||
logInvalidTokenError( in, std::string( Grammar::OpenBracketToken ), m_logCallback );
|
logInvalidTokenError( in, std::string( Grammar::OpenBracketToken ), m_logCallback );
|
||||||
error = true;
|
error = true;
|
||||||
return ddl_nullptr;
|
return ddl_nullptr;
|
||||||
|
@ -373,7 +378,7 @@ static void setNodeDataArrayList( DDLNode *currentNode, DataArrayList *dtArrayLi
|
||||||
|
|
||||||
char *OpenDDLParser::parseStructureBody( char *in, char *end, bool &error ) {
|
char *OpenDDLParser::parseStructureBody( char *in, char *end, bool &error ) {
|
||||||
if( !isNumeric( *in ) && !isCharacter( *in ) ) {
|
if( !isNumeric( *in ) && !isCharacter( *in ) ) {
|
||||||
in++;
|
++in;
|
||||||
}
|
}
|
||||||
|
|
||||||
in = lookForNextToken( in, end );
|
in = lookForNextToken( in, end );
|
||||||
|
@ -431,7 +436,6 @@ DDLNode *OpenDDLParser::popNode() {
|
||||||
|
|
||||||
DDLNode *topNode( top() );
|
DDLNode *topNode( top() );
|
||||||
m_stack.pop_back();
|
m_stack.pop_back();
|
||||||
|
|
||||||
return topNode;
|
return topNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -467,7 +471,14 @@ void OpenDDLParser::normalizeBuffer( std::vector<char> &buffer) {
|
||||||
for( size_t readIdx = 0; readIdx<len; ++readIdx ) {
|
for( size_t readIdx = 0; readIdx<len; ++readIdx ) {
|
||||||
char *c( &buffer[readIdx] );
|
char *c( &buffer[readIdx] );
|
||||||
// check for a comment
|
// check for a comment
|
||||||
if( !isComment<char>( c, end ) && !isNewLine( *c ) ) {
|
if (isCommentOpenTag(c, end)) {
|
||||||
|
++readIdx;
|
||||||
|
while (!isCommentCloseTag(&buffer[readIdx], end)) {
|
||||||
|
++readIdx;
|
||||||
|
}
|
||||||
|
++readIdx;
|
||||||
|
++readIdx;
|
||||||
|
} else if( !isComment<char>( c, end ) && !isNewLine( *c ) ) {
|
||||||
newBuffer.push_back( buffer[ readIdx ] );
|
newBuffer.push_back( buffer[ readIdx ] );
|
||||||
} else {
|
} else {
|
||||||
if( isComment<char>( c, end ) ) {
|
if( isComment<char>( c, end ) ) {
|
||||||
|
@ -535,8 +546,7 @@ char *OpenDDLParser::parseIdentifier( char *in, char *end, Text **id ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const size_t len( idLen );
|
const size_t len( idLen );
|
||||||
Text *newId = new Text( start, len );
|
*id = new Text( start, len );
|
||||||
*id = newId;
|
|
||||||
|
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
@ -567,14 +577,14 @@ char *OpenDDLParser::parsePrimitiveDataType( char *in, char *end, Value::ValueTy
|
||||||
bool ok( true );
|
bool ok( true );
|
||||||
if( *in == Grammar::OpenArrayToken[ 0 ] ) {
|
if( *in == Grammar::OpenArrayToken[ 0 ] ) {
|
||||||
ok = false;
|
ok = false;
|
||||||
in++;
|
++in;
|
||||||
char *start( in );
|
char *start( in );
|
||||||
while ( in != end ) {
|
while ( in != end ) {
|
||||||
in++;
|
++in;
|
||||||
if( *in == Grammar::CloseArrayToken[ 0 ] ) {
|
if( *in == Grammar::CloseArrayToken[ 0 ] ) {
|
||||||
len = ::atoi( start );
|
len = ::atoi( start );
|
||||||
ok = true;
|
ok = true;
|
||||||
in++;
|
++in;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -623,10 +633,10 @@ char *OpenDDLParser::parseBooleanLiteral( char *in, char *end, Value **boolean )
|
||||||
char *start( in );
|
char *start( in );
|
||||||
size_t len( 0 );
|
size_t len( 0 );
|
||||||
while( !isSeparator( *in ) && in != end ) {
|
while( !isSeparator( *in ) && in != end ) {
|
||||||
in++;
|
++in;
|
||||||
len++;
|
++len;
|
||||||
}
|
}
|
||||||
len++;
|
++len;
|
||||||
int res = ::strncmp( Grammar::BoolTrue, start, strlen( Grammar::BoolTrue ) );
|
int res = ::strncmp( Grammar::BoolTrue, start, strlen( Grammar::BoolTrue ) );
|
||||||
if( 0 != res ) {
|
if( 0 != res ) {
|
||||||
res = ::strncmp( Grammar::BoolFalse, start, strlen( Grammar::BoolFalse ) );
|
res = ::strncmp( Grammar::BoolFalse, start, strlen( Grammar::BoolFalse ) );
|
||||||
|
@ -657,7 +667,7 @@ char *OpenDDLParser::parseIntegerLiteral( char *in, char *end, Value **integer,
|
||||||
in = lookForNextToken( in, end );
|
in = lookForNextToken( in, end );
|
||||||
char *start( in );
|
char *start( in );
|
||||||
while( !isSeparator( *in ) && in != end ) {
|
while( !isSeparator( *in ) && in != end ) {
|
||||||
in++;
|
++in;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( isNumeric( *start ) ) {
|
if( isNumeric( *start ) ) {
|
||||||
|
@ -671,29 +681,29 @@ char *OpenDDLParser::parseIntegerLiteral( char *in, char *end, Value **integer,
|
||||||
*integer = ValueAllocator::allocPrimData( integerType );
|
*integer = ValueAllocator::allocPrimData( integerType );
|
||||||
switch( integerType ) {
|
switch( integerType ) {
|
||||||
case Value::ddl_int8:
|
case Value::ddl_int8:
|
||||||
( *integer )->setInt8( (int8) value );
|
( *integer )->setInt8( (int8) value );
|
||||||
break;
|
break;
|
||||||
case Value::ddl_int16:
|
case Value::ddl_int16:
|
||||||
( *integer )->setInt16( ( int16 ) value );
|
( *integer )->setInt16( ( int16 ) value );
|
||||||
break;
|
break;
|
||||||
case Value::ddl_int32:
|
case Value::ddl_int32:
|
||||||
( *integer )->setInt32( ( int32 ) value );
|
( *integer )->setInt32( ( int32 ) value );
|
||||||
break;
|
break;
|
||||||
case Value::ddl_int64:
|
case Value::ddl_int64:
|
||||||
( *integer )->setInt64( ( int64 ) value );
|
( *integer )->setInt64( ( int64 ) value );
|
||||||
break;
|
break;
|
||||||
case Value::ddl_unsigned_int8:
|
case Value::ddl_unsigned_int8:
|
||||||
( *integer )->setUnsignedInt8( (uint8) uvalue );
|
( *integer )->setUnsignedInt8( (uint8) uvalue );
|
||||||
break;
|
break;
|
||||||
case Value::ddl_unsigned_int16:
|
case Value::ddl_unsigned_int16:
|
||||||
( *integer )->setUnsignedInt16( ( uint16 ) uvalue );
|
( *integer )->setUnsignedInt16( ( uint16 ) uvalue );
|
||||||
break;
|
break;
|
||||||
case Value::ddl_unsigned_int32:
|
case Value::ddl_unsigned_int32:
|
||||||
( *integer )->setUnsignedInt32( ( uint32 ) uvalue );
|
( *integer )->setUnsignedInt32( ( uint32 ) uvalue );
|
||||||
break;
|
break;
|
||||||
case Value::ddl_unsigned_int64:
|
case Value::ddl_unsigned_int64:
|
||||||
( *integer )->setUnsignedInt64( ( uint64 ) uvalue );
|
( *integer )->setUnsignedInt64( ( uint64 ) uvalue );
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -711,7 +721,7 @@ char *OpenDDLParser::parseFloatingLiteral( char *in, char *end, Value **floating
|
||||||
in = lookForNextToken( in, end );
|
in = lookForNextToken( in, end );
|
||||||
char *start( in );
|
char *start( in );
|
||||||
while( !isSeparator( *in ) && in != end ) {
|
while( !isSeparator( *in ) && in != end ) {
|
||||||
in++;
|
++in;
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse the float value
|
// parse the float value
|
||||||
|
@ -732,8 +742,7 @@ char *OpenDDLParser::parseFloatingLiteral( char *in, char *end, Value **floating
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ok ) {
|
if( ok ) {
|
||||||
if(floatType == Value::ddl_double)
|
if ( floatType == Value::ddl_double ) {
|
||||||
{
|
|
||||||
const double value( atof( start ) );
|
const double value( atof( start ) );
|
||||||
*floating = ValueAllocator::allocPrimData( Value::ddl_double );
|
*floating = ValueAllocator::allocPrimData( Value::ddl_double );
|
||||||
( *floating )->setDouble( value );
|
( *floating )->setDouble( value );
|
||||||
|
@ -757,17 +766,17 @@ char *OpenDDLParser::parseStringLiteral( char *in, char *end, Value **stringData
|
||||||
size_t len( 0 );
|
size_t len( 0 );
|
||||||
char *start( in );
|
char *start( in );
|
||||||
if( *start == '\"' ) {
|
if( *start == '\"' ) {
|
||||||
start++;
|
++start;
|
||||||
in++;
|
++in;
|
||||||
while( *in != '\"' && in != end ) {
|
while( *in != '\"' && in != end ) {
|
||||||
in++;
|
++in;
|
||||||
len++;
|
++len;
|
||||||
}
|
}
|
||||||
|
|
||||||
*stringData = ValueAllocator::allocPrimData( Value::ddl_string, len );
|
*stringData = ValueAllocator::allocPrimData( Value::ddl_string, len );
|
||||||
::strncpy( ( char* ) ( *stringData )->m_data, start, len );
|
::strncpy( ( char* ) ( *stringData )->m_data, start, len );
|
||||||
( *stringData )->m_data[len] = '\0';
|
( *stringData )->m_data[len] = '\0';
|
||||||
in++;
|
++in;
|
||||||
}
|
}
|
||||||
|
|
||||||
return in;
|
return in;
|
||||||
|
@ -791,12 +800,12 @@ char *OpenDDLParser::parseHexaLiteral( char *in, char *end, Value **data ) {
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
in++;
|
++in;
|
||||||
if( *in != 'x' && *in != 'X' ) {
|
if( *in != 'x' && *in != 'X' ) {
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
in++;
|
++in;
|
||||||
bool ok( true );
|
bool ok( true );
|
||||||
char *start( in );
|
char *start( in );
|
||||||
int pos( 0 );
|
int pos( 0 );
|
||||||
|
@ -805,8 +814,8 @@ char *OpenDDLParser::parseHexaLiteral( char *in, char *end, Value **data ) {
|
||||||
ok = false;
|
ok = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
pos++;
|
++pos;
|
||||||
in++;
|
++in;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !ok ) {
|
if( !ok ) {
|
||||||
|
@ -816,9 +825,9 @@ char *OpenDDLParser::parseHexaLiteral( char *in, char *end, Value **data ) {
|
||||||
int value( 0 );
|
int value( 0 );
|
||||||
while( pos > 0 ) {
|
while( pos > 0 ) {
|
||||||
int v = hex2Decimal( *start );
|
int v = hex2Decimal( *start );
|
||||||
pos--;
|
--pos;
|
||||||
value = ( value << 4 ) | v;
|
value = ( value << 4 ) | v;
|
||||||
start++;
|
++start;
|
||||||
}
|
}
|
||||||
|
|
||||||
*data = ValueAllocator::allocPrimData( Value::ddl_unsigned_int64 );
|
*data = ValueAllocator::allocPrimData( Value::ddl_unsigned_int64 );
|
||||||
|
@ -841,7 +850,7 @@ char *OpenDDLParser::parseProperty( char *in, char *end, Property **prop ) {
|
||||||
if( ddl_nullptr != id ) {
|
if( ddl_nullptr != id ) {
|
||||||
in = lookForNextToken( in, end );
|
in = lookForNextToken( in, end );
|
||||||
if( *in == '=' ) {
|
if( *in == '=' ) {
|
||||||
in++;
|
++in;
|
||||||
in = getNextToken( in, end );
|
in = getNextToken( in, end );
|
||||||
Value *primData( ddl_nullptr );
|
Value *primData( ddl_nullptr );
|
||||||
if( isInteger( in, end ) ) {
|
if( isInteger( in, end ) ) {
|
||||||
|
@ -862,6 +871,8 @@ char *OpenDDLParser::parseProperty( char *in, char *end, Property **prop ) {
|
||||||
( *prop )->m_ref = ref;
|
( *prop )->m_ref = ref;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
delete id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -878,7 +889,7 @@ char *OpenDDLParser::parseDataList( char *in, char *end, Value::ValueType type,
|
||||||
|
|
||||||
in = lookForNextToken( in, end );
|
in = lookForNextToken( in, end );
|
||||||
if( *in == '{' ) {
|
if( *in == '{' ) {
|
||||||
in++;
|
++in;
|
||||||
Value *current( ddl_nullptr ), *prev( ddl_nullptr );
|
Value *current( ddl_nullptr ), *prev( ddl_nullptr );
|
||||||
while( '}' != *in ) {
|
while( '}' != *in ) {
|
||||||
current = ddl_nullptr;
|
current = ddl_nullptr;
|
||||||
|
@ -934,7 +945,7 @@ char *OpenDDLParser::parseDataList( char *in, char *end, Value::ValueType type,
|
||||||
prev->setNext( current );
|
prev->setNext( current );
|
||||||
prev = current;
|
prev = current;
|
||||||
}
|
}
|
||||||
numValues++;
|
++numValues;
|
||||||
}
|
}
|
||||||
|
|
||||||
in = getNextSeparator( in, end );
|
in = getNextSeparator( in, end );
|
||||||
|
@ -942,7 +953,7 @@ char *OpenDDLParser::parseDataList( char *in, char *end, Value::ValueType type,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
in++;
|
++in;
|
||||||
}
|
}
|
||||||
|
|
||||||
return in;
|
return in;
|
||||||
|
@ -972,7 +983,7 @@ char *OpenDDLParser::parseDataArrayList( char *in, char *end,Value::ValueType ty
|
||||||
|
|
||||||
in = lookForNextToken( in, end );
|
in = lookForNextToken( in, end );
|
||||||
if( *in == Grammar::OpenBracketToken[ 0 ] ) {
|
if( *in == Grammar::OpenBracketToken[ 0 ] ) {
|
||||||
in++;
|
++in;
|
||||||
Value *currentValue( ddl_nullptr );
|
Value *currentValue( ddl_nullptr );
|
||||||
Reference *refs( ddl_nullptr );
|
Reference *refs( ddl_nullptr );
|
||||||
DataArrayList *prev( ddl_nullptr ), *currentDataList( ddl_nullptr );
|
DataArrayList *prev( ddl_nullptr ), *currentDataList( ddl_nullptr );
|
||||||
|
@ -995,7 +1006,7 @@ char *OpenDDLParser::parseDataArrayList( char *in, char *end,Value::ValueType ty
|
||||||
}
|
}
|
||||||
} while( Grammar::CommaSeparator[ 0 ] == *in && in != end );
|
} while( Grammar::CommaSeparator[ 0 ] == *in && in != end );
|
||||||
in = lookForNextToken( in, end );
|
in = lookForNextToken( in, end );
|
||||||
in++;
|
++in;
|
||||||
}
|
}
|
||||||
|
|
||||||
return in;
|
return in;
|
||||||
|
|
|
@ -110,7 +110,17 @@ Value::Value( ValueType type )
|
||||||
}
|
}
|
||||||
|
|
||||||
Value::~Value() {
|
Value::~Value() {
|
||||||
// empty
|
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 ) {
|
void Value::setBool( bool value ) {
|
||||||
|
@ -273,13 +283,7 @@ void Value::setRef( Reference *ref ) {
|
||||||
delete [] m_data;
|
delete [] m_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_data = new unsigned char[ sizeof( Reference ) ];
|
m_data = (unsigned char*) new Reference(*ref);
|
||||||
Reference *myRef = ( Reference * ) m_data;
|
|
||||||
myRef->m_numRefs = ref->m_numRefs;
|
|
||||||
myRef->m_referencedName = new Name *[ myRef->m_numRefs ];
|
|
||||||
for ( size_t i = 0; i < myRef->m_numRefs; i++ ) {
|
|
||||||
myRef->m_referencedName[ i ] = new Name( ref->m_referencedName[ i ]->m_type, ref->m_referencedName[ i ]->m_id );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -366,7 +370,6 @@ Value *ValueAllocator::allocPrimData( Value::ValueType type, size_t len ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *data = new Value( type );
|
Value *data = new Value( type );
|
||||||
data->m_type = type;
|
|
||||||
switch( type ) {
|
switch( type ) {
|
||||||
case Value::ddl_bool:
|
case Value::ddl_bool:
|
||||||
data->m_size = sizeof( bool );
|
data->m_size = sizeof( bool );
|
||||||
|
@ -405,10 +408,10 @@ Value *ValueAllocator::allocPrimData( Value::ValueType type, size_t len ) {
|
||||||
data->m_size = sizeof( double );
|
data->m_size = sizeof( double );
|
||||||
break;
|
break;
|
||||||
case Value::ddl_string:
|
case Value::ddl_string:
|
||||||
data->m_size = sizeof( char );
|
data->m_size = sizeof( char )*(len+1);
|
||||||
break;
|
break;
|
||||||
case Value::ddl_ref:
|
case Value::ddl_ref:
|
||||||
data->m_size = sizeof( char );
|
data->m_size = 0;
|
||||||
break;
|
break;
|
||||||
case Value::ddl_none:
|
case Value::ddl_none:
|
||||||
case Value::ddl_types_max:
|
case Value::ddl_types_max:
|
||||||
|
@ -417,12 +420,8 @@ Value *ValueAllocator::allocPrimData( Value::ValueType type, size_t len ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if( data->m_size ) {
|
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 ];
|
data->m_data = new unsigned char[ data->m_size ];
|
||||||
|
::memset(data->m_data,0,data->m_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
|
|
|
@ -53,6 +53,9 @@ public:
|
||||||
/// @brief The child-node-list type.
|
/// @brief The child-node-list type.
|
||||||
typedef std::vector<DDLNode*> DllNodeList;
|
typedef std::vector<DDLNode*> DllNodeList;
|
||||||
|
|
||||||
|
/// @brief The child-node-list iterator.
|
||||||
|
typedef std::vector<DDLNode*>::iterator DDLNodeIt;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// @brief The class destructor.
|
/// @brief The class destructor.
|
||||||
~DDLNode();
|
~DDLNode();
|
||||||
|
|
|
@ -148,12 +148,12 @@ struct DLL_ODDLPARSER_EXPORT Name {
|
||||||
/// @param type [in] The name type.
|
/// @param type [in] The name type.
|
||||||
/// @param id [in] The id.
|
/// @param id [in] The id.
|
||||||
Name( NameType type, Text *id );
|
Name( NameType type, Text *id );
|
||||||
|
Name( const Name &name );
|
||||||
/// @brief The destructor.
|
/// @brief The destructor.
|
||||||
~Name();
|
~Name();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Name( const Name & ) ddl_no_copy;
|
|
||||||
Name &operator = ( const Name& ) ddl_no_copy;
|
Name &operator = ( const Name& ) ddl_no_copy;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -164,7 +164,7 @@ struct DLL_ODDLPARSER_EXPORT Reference {
|
||||||
|
|
||||||
/// @brief The default constructor.
|
/// @brief The default constructor.
|
||||||
Reference();
|
Reference();
|
||||||
|
Reference( const Reference &ref );
|
||||||
/// @brief The constructor with an array of ref names.
|
/// @brief The constructor with an array of ref names.
|
||||||
/// @param numrefs [in] The number of ref names.
|
/// @param numrefs [in] The number of ref names.
|
||||||
/// @param names [in] The ref names.
|
/// @param names [in] The ref names.
|
||||||
|
@ -178,7 +178,6 @@ struct DLL_ODDLPARSER_EXPORT Reference {
|
||||||
size_t sizeInBytes();
|
size_t sizeInBytes();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Reference( const Reference & ) ddl_no_copy;
|
|
||||||
Reference &operator = ( const Reference & ) ddl_no_copy;
|
Reference &operator = ( const Reference & ) ddl_no_copy;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ struct Property;
|
||||||
template<class T>
|
template<class T>
|
||||||
inline
|
inline
|
||||||
T *lookForNextToken( T *in, T *end ) {
|
T *lookForNextToken( T *in, T *end ) {
|
||||||
while( ( isSpace( *in ) || isNewLine( *in ) || ',' == *in ) && ( in != end ) ) {
|
while( ( in != end ) && ( isSpace( *in ) || isNewLine( *in ) || ',' == *in ) ) {
|
||||||
in++;
|
in++;
|
||||||
}
|
}
|
||||||
return in;
|
return in;
|
||||||
|
|
|
@ -84,7 +84,7 @@ static const unsigned char chartype_table[ 256 ] = {
|
||||||
template<class T>
|
template<class T>
|
||||||
inline
|
inline
|
||||||
bool isNumeric( const T in ) {
|
bool isNumeric( const T in ) {
|
||||||
return ( chartype_table[ static_cast<int>( in ) ] == 1 );
|
return ( chartype_table[ static_cast<size_t>( in ) ] == 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
|
@ -98,7 +98,7 @@ inline
|
||||||
bool isInteger( T *in, T *end ) {
|
bool isInteger( T *in, T *end ) {
|
||||||
if( in != end ) {
|
if( in != end ) {
|
||||||
if( *in == '-' ) {
|
if( *in == '-' ) {
|
||||||
in++;
|
++in;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ bool isInteger( T *in, T *end ) {
|
||||||
if( !result ) {
|
if( !result ) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
in++;
|
++in;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -119,7 +119,7 @@ inline
|
||||||
bool isFloat( T *in, T *end ) {
|
bool isFloat( T *in, T *end ) {
|
||||||
if( in != end ) {
|
if( in != end ) {
|
||||||
if( *in == '-' ) {
|
if( *in == '-' ) {
|
||||||
in++;
|
++in;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,12 +134,12 @@ bool isFloat( T *in, T *end ) {
|
||||||
if( !result ) {
|
if( !result ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
in++;
|
++in;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check for 1<.>0f
|
// check for 1<.>0f
|
||||||
if( *in == '.' ) {
|
if( *in == '.' ) {
|
||||||
in++;
|
++in;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -150,7 +150,7 @@ bool isFloat( T *in, T *end ) {
|
||||||
if( !result ) {
|
if( !result ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
in++;
|
++in;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -208,7 +208,7 @@ template<class T>
|
||||||
inline
|
inline
|
||||||
static T *getNextSeparator( T *in, T *end ) {
|
static T *getNextSeparator( T *in, T *end ) {
|
||||||
while( !isSeparator( *in ) || in == end ) {
|
while( !isSeparator( *in ) || in == end ) {
|
||||||
in++;
|
++in;
|
||||||
}
|
}
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
@ -250,5 +250,33 @@ bool isComment( T *in, T *end ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline
|
||||||
|
bool isCommentOpenTag(T *in, T *end ) {
|
||||||
|
if (*in == '/') {
|
||||||
|
if (in + 1 != end) {
|
||||||
|
if (*(in + 1) == '*') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline
|
||||||
|
bool isCommentCloseTag(T *in, T *end) {
|
||||||
|
if (*in == '*') {
|
||||||
|
if (in + 1 != end) {
|
||||||
|
if (*(in + 1) == '/') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
END_ODDLPARSER_NS
|
END_ODDLPARSER_NS
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue