From c86c0cf088492e02431dffb1f860ff2f6faa492d Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 27 Jun 2007 18:11:13 +0000 Subject: The taf system is new and improved. The writer works, we added C++ style comment blocks, and it retains the order of all nodes. --- src/tafwriter.cpp | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) (limited to 'src/tafwriter.cpp') diff --git a/src/tafwriter.cpp b/src/tafwriter.cpp index ac42d3d..6b505ef 100644 --- a/src/tafwriter.cpp +++ b/src/tafwriter.cpp @@ -9,16 +9,54 @@ Bu::TafWriter::~TafWriter() { } -void Bu::TafWriter::writeNode( Bu::TafNode *pRoot ) +void Bu::TafWriter::writeGroup( const Bu::TafGroup *pRoot ) { sOut.write("{", 1 ); - writeString( pRoot->getName().getStr() ); + writeString( pRoot->getName() ); sOut.write(": ", 2 ); + const Bu::TafGroup::NodeList &nl = pRoot->getChildren(); + for( Bu::TafGroup::NodeList::const_iterator i = nl.begin(); i != nl.end(); i++ ) + { + switch( (*i)->getType() ) + { + case Bu::TafNode::typeGroup: + writeGroup( (Bu::TafGroup *)(*i) ); + break; + + case Bu::TafNode::typeProperty: + writeProperty( (Bu::TafProperty *)(*i) ); + break; + + case Bu::TafNode::typeComment: + writeComment( (Bu::TafComment *)(*i) ); + break; + } + } sOut.write("}", 1 ); } +void Bu::TafWriter::writeProperty( const Bu::TafProperty *pProp ) +{ + writeString( pProp->getName() ); + if( pProp->getValue().getStr() != NULL ) + { + sOut.write("=", 1 ); + writeString( pProp->getValue() ); + } + sOut.write(" ", 1 ); +} + +void Bu::TafWriter::writeComment( const Bu::TafComment *pComment ) +{ + sOut.write("/*", 2 ); + sOut.write( pComment->getText().getStr(), pComment->getText().getSize() ); + sOut.write("*/ ", 3 ); +} + void Bu::TafWriter::writeString( const Bu::FString &str ) { + if( str.getStr() == NULL ) + return; sOut.write("\"", 1 ); for( const char *s = str.getStr(); *s; s++ ) { -- cgit v1.2.3