replace opengexparser by using openddl-parser.

Signed-off-by: Kim Kulling <kim.kulling@googlemail.com>
pull/502/head
Kim Kulling 2015-02-07 12:47:53 +01:00
parent e9dcad4181
commit 20b3ce6a40
13 changed files with 190 additions and 670 deletions

View File

@ -155,6 +155,9 @@ endif(NOT ZLIB_FOUND)
INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR})
add_subdirectory( contrib/openddlparser )
INCLUDE_DIRECTORIES( contrib/openddlparser/include )
SET( OPENDDL_PARSER_LIBRARIES openddl_parser )
# Search for unzip
if (PKG_CONFIG_FOUND)
PKG_CHECK_MODULES(UNZIP minizip)

View File

@ -353,8 +353,6 @@ SOURCE_GROUP( Ogre FILES ${Ogre_SRCS})
SET( OpenGEX_SRCS
OpenGEXImporter.cpp
OpenGEXImporter.h
OpenGEXParser.cpp
OpenGEXParser.h
OpenGEXStructs.h
)
SOURCE_GROUP( OpenGEX FILES ${OpenGEX_SRCS})
@ -729,7 +727,7 @@ SET( assimp_src
ADD_LIBRARY( assimp ${assimp_src} )
TARGET_LINK_LIBRARIES(assimp ${ZLIB_LIBRARIES})
TARGET_LINK_LIBRARIES(assimp ${ZLIB_LIBRARIES} ${OPENDDL_PARSER_LIBRARIES} )
if(ANDROID AND ASSIMP_ANDROID_JNIIOSYSTEM)
set(ASSIMP_ANDROID_JNIIOSYSTEM_PATH port/AndroidJNI)

View File

@ -41,9 +41,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "AssimpPCH.h"
#include "OpenGEXImporter.h"
#include "OpenGEXParser.h"
#include "DefaultIOSystem.h"
#include <openddlparser/OpenDDLParser.h>
#include <vector>
static const aiImporterDesc desc = {
@ -62,6 +63,8 @@ static const aiImporterDesc desc = {
namespace Assimp {
namespace OpenGEX {
USE_ODDLPARSER_NS
//------------------------------------------------------------------------------------------------
OpenGEXImporter::OpenGEXImporter() {
@ -95,8 +98,14 @@ void OpenGEXImporter::InternReadFile( const std::string &filename, aiScene *pSce
std::vector<char> buffer;
TextFileToBuffer( file, buffer );
OpenGEXParser myParser( buffer );
myParser.parse();
OpenDDLParser myParser;
myParser.setBuffer( &buffer[ 0 ], buffer.size() );
bool success( myParser.parse() );
if( success ) {
Context *ctx = myParser.getContext();
importMetric( ctx );
}
}
//------------------------------------------------------------------------------------------------
@ -109,6 +118,28 @@ void OpenGEXImporter::SetupProperties( const Importer *pImp ) {
}
//------------------------------------------------------------------------------------------------
void OpenGEXImporter::importMetric( Context *ctx ) {
if( NULL == ctx || NULL == ctx->getProperties() ) {
return;
}
Property *prop = ctx->getProperties();
while( NULL != prop ) {
prop = prop->m_next;
}
}
//------------------------------------------------------------------------------------------------
void OpenGEXImporter::ParseGeoObject() {
}
//------------------------------------------------------------------------------------------------
void OpenGEXImporter::ParseMaterial() {
}
//------------------------------------------------------------------------------------------------
} // Namespace OpenGEX

View File

@ -44,6 +44,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "BaseImporter.h"
namespace ODDLParser {
struct Context;
}
namespace Assimp {
namespace OpenGEX {
@ -72,7 +77,7 @@ public:
virtual void SetupProperties( const Importer *pImp );
protected:
void ParseMetric();
void importMetric( ODDLParser::Context *ctx );
void ParseGeoObject();
void ParseMaterial();
};

View File

@ -1,409 +0,0 @@
/*
Open Asset Import Library (assimp)
----------------------------------------------------------------------
Copyright (c) 2006-2014, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
----------------------------------------------------------------------
*/
#include "AssimpPCH.h"
#ifndef ASSIMP_BUILD_NO_OPEMGEX_IMPORTER
#include "OpenGEXParser.h"
#include "OpenGEXStructs.h"
#include "ParsingUtils.h"
#include "fast_atof.h"
#include <vector>
namespace Assimp {
namespace OpenGEX {
//------------------------------------------------------------------------------------------------
static const std::string Metric = "Metric";
static const std::string GeometryNode = "GeometryNode";
static const std::string GeometryObject = "GeometryObject";
static const std::string Material = "Material";
static const size_t NumObjects = 4;
static const std::string RootNodes[ NumObjects ] = {
Metric,
GeometryNode,
GeometryObject,
Material
};
static const size_t NumSeparator = 4;
static const std::string Separator[ NumSeparator ] = {
"(", ")", "{", "}"
};
static const size_t NumToken = 8;
static const std::string Token[ NumToken ] = {
RootNodes[ 0 ],
RootNodes[ 1 ],
RootNodes[ 2 ],
RootNodes[ 3 ],
Separator[ 0 ],
Separator[ 1 ],
Separator[ 2 ],
Separator[ 3 ]
};
static bool isSeparator( char in ) {
return ( in == '(' || in == ')' || in == '{' || in == '}' );
}
static bool containsNode( const char *bufferPtr, size_t size, const std::string *nodes,
size_t numNodes, std::string &tokenFound ) {
tokenFound = "";
if( 0 == numNodes ) {
return false;
}
bool found( false );
for( size_t i = 0; i < numNodes; ++i ) {
if( TokenMatch( bufferPtr, nodes[ i ].c_str(), nodes[ i ].size() ) ) {
tokenFound = nodes[ i ];
found = true;
break;
}
}
return found;
}
static OpenGEXParser::TokenType getTokenTypeByName( const char *in ) {
ai_assert( NULL != in );
OpenGEXParser::TokenType type( OpenGEXParser::None );
for( size_t i = 0; i < NumToken; ++i ) {
if( TokenMatch( in, Token[ i ].c_str(), Token[ i ].size() ) ) {
type = static_cast<OpenGEXParser::TokenType>( i+1 );
break;
}
}
return type;
}
static void removeQuotes( std::string &attribName ) {
std::string tmp;
for( unsigned int i = 0; i < attribName.size(); ++i ) {
if( attribName[ i ] != '\"' ) {
tmp += attribName[ i ];
}
}
attribName = tmp;
}
//------------------------------------------------------------------------------------------------
OpenGEXParser::OpenGEXParser( const std::vector<char> &buffer )
: m_buffer( buffer )
, m_index( 0 )
, m_buffersize( buffer.size() )
, m_nodeTypeStack() {
// empty
}
//------------------------------------------------------------------------------------------------
OpenGEXParser::~OpenGEXParser() {
}
//------------------------------------------------------------------------------------------------
void OpenGEXParser::parse() {
while( parseNextNode() ) {
}
}
//------------------------------------------------------------------------------------------------
std::string OpenGEXParser::getNextToken() {
std::string token;
while( m_index < m_buffersize && IsSpace( m_buffer[ m_index ] ) ) {
m_index++;
}
while( m_index < m_buffersize && !IsSpace( m_buffer[ m_index ] ) && !isSeparator( m_buffer[ m_index ] ) ) {
token += m_buffer[ m_index ];
m_index++;
}
if( token == "//" ) {
skipComments();
token = getNextToken();
}
if( token.empty() ) {
if( isSeparator( m_buffer[ m_index ] ) ) {
token += m_buffer[ m_index ];
m_index++;
}
}
return token;
}
//------------------------------------------------------------------------------------------------
bool OpenGEXParser::skipComments() {
bool skipped( false );
if( strncmp( &m_buffer[ m_index ], "//", 2 ) == 0) {
while( !IsLineEnd( m_buffer[ m_index ] ) ) {
++m_index;
}
skipped = true;
}
return skipped;
}
//------------------------------------------------------------------------------------------------
void OpenGEXParser::readUntilEndOfLine() {
while( !IsLineEnd( m_buffer[ m_index ] ) ) {
++m_index;
}
++m_index;
if( IsLineEnd( m_buffer[ m_index ] ) ) {
++m_index;
}
}
//------------------------------------------------------------------------------------------------
bool OpenGEXParser::parseNextNode() {
std::string token( getNextToken() );
std::string rootNodeName, nodeType;
if( containsNode( token.c_str(), token.size(), RootNodes, NumObjects, rootNodeName ) ) {
m_nodeTypeStack.push_back( getTokenTypeByName( rootNodeName.c_str() ) );
if( !getNodeHeader( nodeType ) ) {
return false;
}
if( !getNodeData( nodeType ) ) {
return false;
}
readUntilEndOfLine();
m_nodeTypeStack.pop_back();
}
return true;
}
//------------------------------------------------------------------------------------------------
bool OpenGEXParser::getNodeHeader( std::string &name ) {
bool success( false );
TokenType tokenType( m_nodeTypeStack.back() );
if( tokenType == MetricNode ) {
if( getMetricAttributeKey( name ) ) {
success = true;
}
} else if( tokenType == GeometryNode ) {
} else if( tokenType == GeometryObject ) {
} else if( tokenType == Material ) {
} else {
DefaultLogger::get()->warn( "Unknown token type in file." );
}
return success;
}
//------------------------------------------------------------------------------------------------
bool OpenGEXParser::getBracketOpen() {
const std::string token( getNextToken() );
if( "{" == token ) {
return true;
}
return false;
}
//------------------------------------------------------------------------------------------------
bool OpenGEXParser::getBracketClose() {
const std::string token( getNextToken() );
if( "}" == token ) {
return true;
}
return false;
}
//------------------------------------------------------------------------------------------------
bool OpenGEXParser::getStringData( std::string &data ) {
if( !getBracketOpen() ) {
return false;
}
if( !getBracketClose() ) {
return false;
}
return false;
}
//------------------------------------------------------------------------------------------------
bool OpenGEXParser::getFloatData( size_t num, float *data ) {
ai_assert( NULL != data );
std::string tk;
tk = getNextToken();
if( !getBracketOpen() ) {
return false;
}
bool ok( true );
size_t dataIdx( 0 );
for( unsigned int i = 0; i < num; ++i ) {
data[ dataIdx ] = fast_atof( &m_buffer[ m_index ] );
++dataIdx;
tk = getNextToken();
if( tk == "," ) {
if( i >= ( num - 1 ) ) {
ok = false;
break;
}
}
}
if( !getBracketClose() ) {
return false;
}
return ok;
}
//------------------------------------------------------------------------------------------------
bool OpenGEXParser::getNodeData( const std::string &nodeType ) {
bool success( false );
if( !getBracketOpen() ) {
return false;
}
const TokenType type( m_nodeTypeStack.back() );
if( type == MetricNode ) {
success = onMetricNode( nodeType );
} else if( type == GeometryNode ) {
success = onGeometryNode();
} else if( type == GeometryObject ) {
success = onGeometryObject();
} else if( type == Material ) {
success = onMaterial();
} else {
DefaultLogger::get()->warn( "Unknown token type in file." );
}
if( !getBracketClose() ) {
return false;
}
return success;
}
//------------------------------------------------------------------------------------------------
bool OpenGEXParser::getMetricAttributeKey( std::string &attribName ) {
bool ok( false );
attribName = "";
std::string token( getNextToken() );
if( token[ 0 ] == '(' ) {
// get attribute
token = getNextToken();
if( "key" == token ) {
std::string equal = getNextToken();
attribName = getNextToken();
token = getNextToken();
if( token[ 0 ] == ')' ) {
ok = true;
removeQuotes( attribName );
}
}
}
return ok;
}
//------------------------------------------------------------------------------------------------
bool OpenGEXParser::onMetricNode( const std::string &attribName ) {
float value( 0.0f );
bool success( true );
if( "distance" == attribName ) {
if( getFloatData( 1, &value ) ) {
m_model.m_metrics.m_distance = value;
}
} else if( "angle" == attribName ) {
if( getFloatData( 1, &value ) ) {
m_model.m_metrics.m_angle = value;
}
} else if( "time" == attribName ) {
if( getFloatData( 1, &value ) ) {
m_model.m_metrics.m_time = value;
}
} else if( "up" == attribName ) {
std::string up;
if( getStringData( up ) ) {
m_model.m_metrics.m_up = up;
}
} else {
success = false;
}
return success;
}
//------------------------------------------------------------------------------------------------
bool OpenGEXParser::onGeometryNode() {
return true;
}
//------------------------------------------------------------------------------------------------
bool OpenGEXParser::onGeometryObject() {
return true;
}
//------------------------------------------------------------------------------------------------
bool OpenGEXParser::onMaterial() {
return true;
}
//------------------------------------------------------------------------------------------------
} // Namespace OpenGEX
} // Namespace Assimp
#endif ASSIMP_BUILD_NO_OPEMGEX_IMPORTER

View File

@ -1,121 +0,0 @@
/*
Open Asset Import Library (assimp)
----------------------------------------------------------------------
Copyright (c) 2006-2014, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
----------------------------------------------------------------------
*/
#ifndef ASSIMP_OPENGEX_OPENGEXPARSER_H_INC
#define ASSIMP_OPENGEX_OPENGEXPARSER_H_INC
#ifndef ASSIMP_BUILD_NO_OPEMGEX_IMPORTER
#include <vector>
#include <map>
namespace Assimp {
namespace OpenGEX {
struct OpenGEXModel {
struct Metrics {
float m_distance;
float m_angle;
float m_time;
std::string m_up;
Metrics()
: m_distance( 0.0f )
, m_angle( 0.0f )
, m_time( 0.0f )
, m_up() {
// empty
}
} m_metrics;
};
class OpenGEXParser {
public:
enum TokenType {
None = 0,
MetricNode,
GeometryNode,
GeometryObject,
Material,
BracketIn,
BracketOut,
CurlyBracketIn,
CurlyBracketOut,
};
public:
OpenGEXParser( const std::vector<char> &buffer );
~OpenGEXParser();
void parse();
protected:
std::string getNextToken();
bool skipComments();
void readUntilEndOfLine();
bool parseNextNode();
bool getNodeHeader( std::string &name );
bool getBracketOpen();
bool getBracketClose();
bool getStringData( std::string &data );
bool getFloatData( size_t num, float *data );
bool getNodeData( const std::string &nodeType );
bool getMetricAttributeKey( std::string &attribName );
bool onMetricNode( const std::string &attribName );
bool onGeometryNode();
bool onGeometryObject();
bool onMaterial();
private:
OpenGEXParser( const OpenGEXParser & );
OpenGEXParser &operator = ( const OpenGEXParser & );
private:
const std::vector<char> &m_buffer;
std::vector<TokenType> m_nodeTypeStack;
OpenGEXModel m_model;
size_t m_index;
size_t m_buffersize;
};
} // Namespace openGEX
} // Namespace Assimp
#endif // ASSIMP_BUILD_NO_OPEMGEX_IMPORTER
#endif // ASSIMP_OPENGEX_OPENGEXPARSER_H_INC

View File

@ -116,6 +116,14 @@ const std::string &DDLNode::getName() const {
return m_name;
}
void DDLNode::setProperties( Property *prop ) {
m_properties = prop;
}
Property *DDLNode::getProperties() const {
return m_properties;
}
void DDLNode::setValue( Value *val ) {
m_value = val;
}

View File

@ -104,22 +104,18 @@ static void logMessage( LogSeverity severity, const std::string &msg ) {
OpenDDLParser::OpenDDLParser()
: m_logCallback( logMessage )
, m_ownsBuffer( false )
, m_buffer( ddl_nullptr )
, m_len( 0 )
, m_buffer()
, m_stack()
, m_context( ddl_nullptr ) {
// empty
}
OpenDDLParser::OpenDDLParser( char *buffer, size_t len, bool ownsIt )
OpenDDLParser::OpenDDLParser( char *buffer, size_t len )
: m_logCallback( &logMessage )
, m_ownsBuffer( false )
, m_buffer( ddl_nullptr )
, m_len( 0 )
, m_buffer()
, m_context( ddl_nullptr ) {
if( 0 != m_len ) {
setBuffer( buffer, len, ownsIt );
if( 0 != len ) {
setBuffer( buffer, len );
}
}
@ -141,41 +137,36 @@ OpenDDLParser::logCallback OpenDDLParser::getLogCallback() const {
return m_logCallback;
}
void OpenDDLParser::setBuffer( char *buffer, size_t len, bool ownsIt ) {
if( m_buffer && m_ownsBuffer ) {
delete[] m_buffer;
m_buffer = ddl_nullptr;
m_len = 0;
void OpenDDLParser::setBuffer( char *buffer, size_t len ) {
clear();
if( 0 == len ) {
return;
}
m_ownsBuffer = ownsIt;
if( m_ownsBuffer ) {
// when we are owning the buffer we will do a deep copy
m_buffer = new char[ len ];
m_len = len;
::memcpy( m_buffer, buffer, len );
} else {
// when we are not owning the buffer, we just do a shallow copy
m_buffer = buffer;
m_len = len;
}
m_buffer.resize( len );
::memcpy(&m_buffer[ 0 ], buffer, len );
}
char *OpenDDLParser::getBuffer() const {
return m_buffer;
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_len;
return m_buffer.size();
}
void OpenDDLParser::clear() {
if( m_ownsBuffer ) {
delete [] m_buffer;
}
m_buffer = ddl_nullptr;
m_len = 0;
m_buffer.resize( 0 );
if( m_context ) {
m_context->m_root = ddl_nullptr;
}
@ -184,11 +175,11 @@ void OpenDDLParser::clear() {
}
bool OpenDDLParser::parse() {
if( 0 == m_len ) {
if( m_buffer.empty() ) {
return false;
}
normalizeBuffer( m_buffer, m_len );
normalizeBuffer( m_buffer );
m_context = new Context;
m_context->m_root = DDLNode::create( "root", "", ddl_nullptr );
@ -196,9 +187,11 @@ bool OpenDDLParser::parse() {
// do the main parsing
char *current( &m_buffer[ 0 ] );
char *end( &m_buffer[ m_len - 1 ] + 1 );
while( current != end ) {
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;
}
@ -219,7 +212,7 @@ char *OpenDDLParser::parseHeader( char *in, char *end ) {
in = OpenDDLParser::parseIdentifier( in, end, &id );
#ifdef DEBUG_HEADER_NAME
if( id ) {
if( ddl_nullptr != id ) {
std::cout << id->m_buffer << std::endl;
}
#endif // DEBUG_HEADER_NAME
@ -253,7 +246,11 @@ char *OpenDDLParser::parseHeader( char *in, char *end ) {
// set the properties
if( ddl_nullptr != first ) {
m_context->setProperties( first );
std::cout << id->m_buffer << std::endl;
DDLNode *current( top() );
if( current ) {
current->setProperties( first );
}
}
// store the node
@ -317,6 +314,9 @@ char *OpenDDLParser::parseStructure( char *in, char *end ) {
if( *in != '}' ) {
logInvalidTokenError( in, "}", m_logCallback );
}
else {
in++;
}
} else {
in = parseHeader( in, end );
in = parseStructure( in, end );
@ -327,6 +327,7 @@ char *OpenDDLParser::parseStructure( char *in, char *end ) {
return in;
}
in = getNextToken( in, end );
in++;
@ -373,33 +374,29 @@ Context *OpenDDLParser::getContext() const {
return m_context;
}
void OpenDDLParser::normalizeBuffer( char *buffer, size_t len ) {
if( nullptr == buffer || 0 == len ) {
void OpenDDLParser::normalizeBuffer( std::vector<char> &buffer) {
if( buffer.empty() ) {
return;
}
size_t writeIdx( 0 );
char *end( &buffer[ len ] + 1 );
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 ) ) {
buffer[ writeIdx ] = buffer[ readIdx ];
writeIdx++;
newBuffer.push_back( buffer[ readIdx ] );
} else {
readIdx++;
// skip the comment and the rest of the line
while( !isEndofLine( buffer[ readIdx ] ) ) {
readIdx++;
}
buffer[writeIdx] = '\n';
writeIdx++;
newBuffer.push_back( '\n' );
}
}
if( writeIdx < len ) {
buffer[ writeIdx ] = '\0';
}
buffer = newBuffer;
}
char *OpenDDLParser::parseName( char *in, char *end, Name **name ) {

View File

@ -55,6 +55,8 @@ public:
const std::string &getType() const;
void setName( const std::string &name );
const std::string &getName() const;
void setProperties( Property *prop );
Property *getProperties() const;
void setValue( Value *val );
Value *getValue() const;
void setDataArrayList( DataArrayList *dtArrayList );

View File

@ -25,6 +25,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#define OPENDDLPARSER_OPENDDLPARSERCOMMON_H_INC
#include <cstddef>
#include <vector>
#include <string.h>
#ifdef _WIN32
@ -133,29 +135,24 @@ struct DataArrayList {
};
struct Context {
Property *m_properties;
DDLNode *m_root;
Context()
: m_properties( ddl_nullptr )
, m_root( ddl_nullptr ) {
: m_root( ddl_nullptr ) {
// empty
}
void setProperties( Property *first );
Property *getProperties() const;
};
struct BufferIt {
std::vector<char> m_buffer;
size_t m_idx;
inline
void Context::setProperties( Property *first ) {
m_properties = first;
}
inline
Property *Context::getProperties() const {
return m_properties;
}
BufferIt( const std::vector<char> &buffer )
: m_buffer( buffer )
, m_idx( 0 ) {
// empty
}
};
END_ODDLPARSER_NS

View File

@ -50,11 +50,12 @@ T *getNextToken( T *in, T *end ) {
return in;
}
/// @brief Defines the log severity.
enum LogSeverity {
ddl_debug_msg = 0,
ddl_info_msg,
ddl_warn_msg,
ddl_error_msg,
ddl_debug_msg = 0, ///< Debug message, for debugging
ddl_info_msg, ///< Info messages, normal mode
ddl_warn_msg, ///< Parser warnings
ddl_error_msg ///< Parser errors
};
class DLL_ODDLPARSER_EXPORT OpenDDLParser {
@ -63,12 +64,13 @@ public:
public:
OpenDDLParser();
OpenDDLParser( char *buffer, size_t len, bool ownsIt = false );
OpenDDLParser( char *buffer, size_t len );
~OpenDDLParser();
void setLogCallback( logCallback callback );
logCallback getLogCallback() const;
void setBuffer( char *buffer, size_t len, bool ownsIt = false );
char *getBuffer() const;
void setBuffer( char *buffer, size_t len );
void setBuffer( const std::vector<char> &buffer );
const char *getBuffer() const;
size_t getBufferSize() const;
void clear();
bool parse();
@ -82,7 +84,7 @@ public:
Context *getContext() const;
public: // static parser helpers
static void normalizeBuffer( char *buffer, size_t len );
static void normalizeBuffer( std::vector<char> &buffer );
static char *parseName( char *in, char *end, Name **name );
static char *parseIdentifier( char *in, char *end, Identifier **id );
static char *parsePrimitiveDataType( char *in, char *end, Value::ValueType &type, size_t &len );
@ -103,9 +105,8 @@ private:
private:
logCallback m_logCallback;
bool m_ownsBuffer;
char *m_buffer;
size_t m_len;
std::vector<char> m_buffer;
typedef std::vector<DDLNode*> DDLNodeStack;
DDLNodeStack m_stack;
Context *m_context;

View File

@ -28,19 +28,27 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
BEGIN_ODDLPARSER_NS
///------------------------------------------------------------------------------------------------
/// @brief This class implements a value.
///
/// Values are used to store data types like boolean, integer, floats, double and many mode. To get
/// an overview please check the enum VylueType ( @see Value::ValueType ).
/// Values can be single items or lists of items. They are implemented as linked lists.
///------------------------------------------------------------------------------------------------
class DLL_ODDLPARSER_EXPORT Value {
public:
/// @brief This enum describes the data type stored in the value.
enum ValueType {
ddl_none = -1,
ddl_bool = 0,
ddl_int8,
ddl_int16,
ddl_int32,
ddl_int64,
ddl_unsigned_int8,
ddl_unsigned_int16,
ddl_unsigned_int32,
ddl_unsigned_int64,
ddl_none = -1, ///< Nothing specified
ddl_bool = 0, ///< A boolean type
ddl_int8, ///< Integer type, 8 bytes
ddl_int16, ///< Integer type, 16 bytes
ddl_int32, ///< Integer type, 32 bytes
ddl_int64, ///< Integer type, 64 bytes
ddl_unsigned_int8, ///< Unsigned integer type, 8 bytes
ddl_unsigned_int16, ///< Unsigned integer type, 16 bytes
ddl_unsigned_int32, ///< Unsigned integer type, 32 bytes
ddl_unsigned_int64, ///< Unsigned integer type, 64 bytes
ddl_half,
ddl_float,
ddl_double,