From 8b598e8436a7110abbd0a7566138bcaa952bb527 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 7 Jun 2007 03:26:43 +0000 Subject: Except for an excessive amount of debug info, I finally got the delete code working. Now you can load Taf structures and clean up, you just can't access all of the data inside 100%. --- src/tafnode.cpp | 39 ++++++++++++++++++++++++++++++++++++++- src/tafnode.h | 5 +++++ src/tafreader.cpp | 32 +++++++++++++++++--------------- src/tafreader.h | 7 +++---- src/tests/taf.cpp | 11 +++++++++++ 5 files changed, 74 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/tafnode.cpp b/src/tafnode.cpp index 01880d9..ed8adc0 100644 --- a/src/tafnode.cpp +++ b/src/tafnode.cpp @@ -6,11 +6,21 @@ Bu::TafNode::TafNode() Bu::TafNode::~TafNode() { + printf("Entering Bu::TafNode::~TafNode() \"%s\"\n", sName.getStr() ); + for( NodeHash::iterator i = hChildren.begin(); i != hChildren.end(); i++ ) + { + NodeList &l = i.getValue(); + for( NodeList::iterator k = l.begin(); k != l.end(); k++ ) + { + printf("deleting: [%08X] %s\n", *k, "" );//(*k)->getName().getStr() ); + delete (*k); + } + } } void Bu::TafNode::setProperty( Bu::FString sName, Bu::FString sValue ) { - if( hProp.has( sName ) ) + if( !hProp.has( sName ) ) { hProp.insert( sName, PropList() ); } @@ -18,8 +28,35 @@ void Bu::TafNode::setProperty( Bu::FString sName, Bu::FString sValue ) hProp.get( sName ).append( sValue ); } +void Bu::TafNode::addChild( TafNode *pNode ) +{ + if( !hChildren.has( pNode->getName() ) ) + { + hChildren.insert( pNode->getName(), NodeList() ); + } + + printf("Appending \"%s\"\n", pNode->getName().getStr() ); + hChildren.get( pNode->getName() ).append( pNode ); + printf("[%08X]\n", hChildren.get( pNode->getName() ).last() ); +} + const Bu::TafNode::PropList &Bu::TafNode::getProperty( const Bu::FString &sName ) { return hProp.get( sName ); } +const Bu::TafNode::NodeList &Bu::TafNode::getNode( const Bu::FString &sName ) +{ + return hChildren.get( sName ); +} + +void Bu::TafNode::setName( const Bu::FString &sName ) +{ + this->sName = sName; +} + +const Bu::FString &Bu::TafNode::getName() +{ + return sName; +} + diff --git a/src/tafnode.h b/src/tafnode.h index e962e88..a570d2d 100644 --- a/src/tafnode.h +++ b/src/tafnode.h @@ -23,8 +23,13 @@ namespace Bu TafNode(); virtual ~TafNode(); + void setName( const Bu::FString &sName ); + const Bu::FString &getName(); + void setProperty( Bu::FString sName, Bu::FString sValue ); const PropList &getProperty( const Bu::FString &sName ); + const NodeList &getNode( const Bu::FString &sName ); + void addChild( TafNode *pNode ); private: Bu::FString sName; diff --git a/src/tafreader.cpp b/src/tafreader.cpp index 5fe303b..1187176 100644 --- a/src/tafreader.cpp +++ b/src/tafreader.cpp @@ -5,10 +5,9 @@ using namespace Bu; Bu::TafReader::TafReader( Bu::Stream &sIn ) : + c( 0 ), sIn( sIn ) { - next(); - node(); } Bu::TafReader::~TafReader() @@ -16,55 +15,58 @@ Bu::TafReader::~TafReader() } -Bu::TafNode *Bu::TafReader::readNode() -{ -} - -void Bu::TafReader::node() +Bu::TafNode *Bu::TafReader::getNode() { + if( c == 0 ) next(); + TafNode *pNode = new TafNode(); ws(); if( c != '{' ) throw TafException("Expected '{'"); next(); ws(); FString sName = readStr(); + pNode->setName( sName ); next(); - printf("Node[%s]:\n", sName.getStr() ); + //printf("Node[%s]:\n", sName.getStr() ); - nodeContent(); + nodeContent( pNode ); if( c != '}' ) throw TafException("Expected '}'"); next(); + + return pNode; } -void Bu::TafReader::nodeContent() +void Bu::TafReader::nodeContent( Bu::TafNode *pNode ) { for(;;) { ws(); if( c == '{' ) - node(); + pNode->addChild( getNode() ); else if( c == '}' ) return; else - nodeProperty(); + nodeProperty( pNode ); } } -void Bu::TafReader::nodeProperty() +void Bu::TafReader::nodeProperty( Bu::TafNode *pNode ) { FString sName = readStr(); ws(); if( c != '=' ) { - printf(" %s (true)\n", sName.getStr() ); + //printf(" %s (true)\n", sName.getStr() ); + pNode->setProperty( sName, "" ); return; } next(); FString sValue = readStr(); - printf(" %s = %s\n", sName.getStr(), sValue.getStr() ); + pNode->setProperty( sName, sValue ); + //printf(" %s = %s\n", sName.getStr(), sValue.getStr() ); } Bu::FString Bu::TafReader::readStr() diff --git a/src/tafreader.h b/src/tafreader.h index 4da800c..47ae187 100644 --- a/src/tafreader.h +++ b/src/tafreader.h @@ -17,12 +17,11 @@ namespace Bu TafReader( Bu::Stream &sIn ); virtual ~TafReader(); - Bu::TafNode *readNode(); + Bu::TafNode *getNode(); private: - void node(); - void nodeContent(); - void nodeProperty(); + void nodeContent( Bu::TafNode *pNode ); + void nodeProperty( Bu::TafNode *pNode ); void ws(); bool isws(); void next(); diff --git a/src/tests/taf.cpp b/src/tests/taf.cpp index 12c653e..f7af2b2 100644 --- a/src/tests/taf.cpp +++ b/src/tests/taf.cpp @@ -5,5 +5,16 @@ int main() { Bu::File f("test.taf", "rb"); Bu::TafReader tr( f ); + + Bu::TafNode *pNode = tr.getNode(); + + const Bu::TafNode::NodeList &l = pNode->getNode("stats"); + for( Bu::TafNode::NodeList::const_iterator i = l.begin(); + i != l.end(); i++ ) + { + printf("%s\n", (*i)->getName().getStr() ); + } + + delete pNode; } -- cgit v1.2.3