From 96b07a22f5392f5d7f821f5743deb3d64bd94e89 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 16 Oct 2009 12:59:45 +0000 Subject: Although this looks like a load of code changes, this represents no functional change to the Taf system. Really all that's happened is I've broken out the core taf data types into seperate files, and gone ahead and created a helpful new header file ("taf.h") that will include the entire taf system, including the reader and writer for you. This means that a lot of programs will start complaining, but fortunately, there's an easy solution, if it complains about taf, make sure to include taf.h at the top, instead of other taf files and you'll be set. The next set of changes will add lots of helpers to the taf system and change the reader to read non-const structures, i.e. I'll actually add editing support to created taf structures. --- src/fbasicstring.h | 15 ++++ src/taf.h | 11 +++ src/tafcomment.cpp | 30 ++++++++ src/tafcomment.h | 35 ++++++++++ src/tafgroup.cpp | 164 +++++++++++++++++++++++++++++++++++++++++++ src/tafgroup.h | 65 ++++++++++++++++++ src/tafnode.cpp | 195 ---------------------------------------------------- src/tafnode.h | 82 ---------------------- src/tafproperty.cpp | 30 ++++++++ src/tafproperty.h | 35 ++++++++++ src/tafreader.cpp | 3 +- src/tafreader.h | 8 ++- src/tafwriter.cpp | 3 +- src/tests/taf.cpp | 3 +- src/unit/taf.unit | 3 +- 15 files changed, 396 insertions(+), 286 deletions(-) create mode 100644 src/taf.h create mode 100644 src/tafcomment.cpp create mode 100644 src/tafcomment.h create mode 100644 src/tafgroup.cpp create mode 100644 src/tafgroup.h create mode 100644 src/tafproperty.cpp create mode 100644 src/tafproperty.h (limited to 'src') diff --git a/src/fbasicstring.h b/src/fbasicstring.h index cda507a..225bc80 100644 --- a/src/fbasicstring.h +++ b/src/fbasicstring.h @@ -1931,6 +1931,21 @@ namespace Bu ar.write( core->pFirst->pData, core->nLength*sizeof(chr) ); } } + /* + void archive( class Archive &ar ) const + { + if( ar.isLoading() ) + { + } + else + { + flatten(); + + ar << core->nLength; + if( core->nLength ) + ar.write( core->pFirst->pData, core->nLength*sizeof(chr) ); + } + }*/ iterator begin() { diff --git a/src/taf.h b/src/taf.h new file mode 100644 index 0000000..109275c --- /dev/null +++ b/src/taf.h @@ -0,0 +1,11 @@ +// +// There's no protection on this file, it just includes other files. +// + +#include "bu/tafnode.h" +#include "bu/tafgroup.h" +#include "bu/tafproperty.h" +#include "bu/tafcomment.h" +#include "bu/tafreader.h" +#include "bu/tafwriter.h" + diff --git a/src/tafcomment.cpp b/src/tafcomment.cpp new file mode 100644 index 0000000..03f382a --- /dev/null +++ b/src/tafcomment.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2007-2008 Xagasoft, All rights reserved. + * + * This file is part of the libbu++ library and is released under the + * terms of the license contained in the file LICENSE. + */ + +#include "bu/tafcomment.h" + +Bu::TafComment::TafComment( const Bu::FString &sText, bool bEOL ) : + TafNode( typeComment ), + sText( sText ), + bEOL( bEOL ) +{ +} + +Bu::TafComment::~TafComment() +{ +} + +const Bu::FString &Bu::TafComment::getText() const +{ + return sText; +} + +bool Bu::TafComment::isEOLStyle() const +{ + return bEOL; +} + diff --git a/src/tafcomment.h b/src/tafcomment.h new file mode 100644 index 0000000..9f0534f --- /dev/null +++ b/src/tafcomment.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2007-2008 Xagasoft, All rights reserved. + * + * This file is part of the libbu++ library and is released under the + * terms of the license contained in the file LICENSE. + */ + +#ifndef BU_TAF_COMMENT_H +#define BU_TAF_COMMENT_H + +#include +#include "bu/tafnode.h" + +namespace Bu +{ + /** + * + *@ingroup Taf + */ + class TafComment : public TafNode + { + public: + TafComment( const Bu::FString &sText, bool bEOL=false ); + virtual ~TafComment(); + + const Bu::FString &getText() const; + bool isEOLStyle() const; + + private: + Bu::FString sText; + bool bEOL; + }; +} + +#endif diff --git a/src/tafgroup.cpp b/src/tafgroup.cpp new file mode 100644 index 0000000..1837bd8 --- /dev/null +++ b/src/tafgroup.cpp @@ -0,0 +1,164 @@ +/* + * Copyright (C) 2007-2008 Xagasoft, All rights reserved. + * + * This file is part of the libbu++ library and is released under the + * terms of the license contained in the file LICENSE. + */ + +#include "bu/tafgroup.h" +#include "bu/tafproperty.h" +#include "bu/tafcomment.h" + +Bu::TafGroup::TafGroup( const Bu::FString &sName ) : + TafNode( typeGroup ), + sName( sName ) +{ +} + +Bu::TafGroup::~TafGroup() +{ + for( NodeList::iterator i = lChildren.begin(); i != lChildren.end(); i++ ) + { + delete (*i); + } +} + +const Bu::FString &Bu::TafGroup::getName() const +{ + return sName; +} + +void Bu::TafGroup::setName( const Bu::FString &sName ) +{ + this->sName = sName; +} + +Bu::TafNode *Bu::TafGroup::addChild( Bu::TafNode *pNode ) +{ + switch( pNode->getType() ) + { + case typeGroup: + addChild( (Bu::TafGroup *)pNode ); + break; + + case typeProperty: + addChild( (Bu::TafProperty *)pNode ); + break; + + case typeComment: + addChild( (Bu::TafComment *)pNode ); + break; + } + + return pNode; +} + +Bu::TafGroup *Bu::TafGroup::addChild( TafGroup *pNode ) +{ + TafGroup *pGroup = (TafGroup *)pNode; + if( !hChildren.has( pGroup->getName() ) ) + hChildren.insert( pGroup->getName(), GroupList() ); + hChildren.get( pGroup->getName() ).append( pGroup ); + lChildren.append( pNode ); + return pNode; +} + +Bu::TafProperty *Bu::TafGroup::addChild( TafProperty *pNode ) +{ + TafProperty *pProperty = (TafProperty *)pNode; + if( !hProp.has( pProperty->getName() ) ) + hProp.insert( pProperty->getName(), PropList() ); + hProp.get( pProperty->getName() ).append( pProperty->getValue() ); + lChildren.append( pNode ); + return pNode; +} + +Bu::TafComment *Bu::TafGroup::addChild( TafComment *pNode ) +{ + lChildren.append( pNode ); + return pNode; +} + +Bu::TafGroup *Bu::TafGroup::addGroup( const Bu::FString &sName ) +{ + return addChild( new TafGroup( sName ) ); +} + +Bu::TafProperty *Bu::TafGroup::addProperty( + const Bu::FString &sName, const Bu::FString &sValue ) +{ + return addChild( new TafProperty( sName, sValue ) ); +} + +bool Bu::TafGroup::hasChild( const Bu::FString &sName ) const +{ + return hChildren.has( sName ); +} + +const Bu::TafGroup::GroupList &Bu::TafGroup::getChildren( const Bu::FString &sName ) const +{ + try { + return hChildren.get( sName ); + } catch( Bu::HashException &e ) + { + throw Bu::TafException("No children of group \"%s\" match \"%s\".", + this->sName.getStr(), sName.getStr() ); + } +} + +const Bu::TafGroup::NodeList &Bu::TafGroup::getChildren() const +{ + return lChildren; +} + +const Bu::TafGroup *Bu::TafGroup::getChild( const Bu::FString &sName ) const +{ + try { + return hChildren.get( sName ).first(); + } catch( Bu::HashException &e ) + { + throw Bu::TafException("No children of group \"%s\" match \"%s\".", + this->sName.getStr(), sName.getStr() ); + } +} + +bool Bu::TafGroup::hasProperty( const Bu::FString &sName ) const +{ + return hProp.has( sName ); +} + +const Bu::TafGroup::PropList &Bu::TafGroup::getProperties( const Bu::FString &sName ) const +{ + try { + return hProp.get( sName ); + } catch( Bu::HashException &e ) + { + throw Bu::TafException("No properties of group \"%s\" match \"%s\".", + this->sName.getStr(), sName.getStr() ); + } +} + +const Bu::FString &Bu::TafGroup::getProperty( const Bu::FString &sName ) const +{ + try { + return hProp.get( sName ).first(); + } catch( Bu::HashException &e ) + { + throw Bu::TafException("No properties of group \"%s\" match \"%s\".", + this->sName.getStr(), sName.getStr() ); + } +} + +const Bu::FString &Bu::TafGroup::getProperty( const Bu::FString &sName, + const Bu::FString &sDef ) const +{ + try + { + return hProp.get( sName ).first(); + } + catch( Bu::HashException &e ) + { + return sDef; + } +} + diff --git a/src/tafgroup.h b/src/tafgroup.h new file mode 100644 index 0000000..6a50d11 --- /dev/null +++ b/src/tafgroup.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2007-2008 Xagasoft, All rights reserved. + * + * This file is part of the libbu++ library and is released under the + * terms of the license contained in the file LICENSE. + */ + +#ifndef BU_TAF_GROUP_H +#define BU_TAF_GROUP_H + +#include +#include "bu/tafnode.h" +#include "bu/fstring.h" +#include "bu/hash.h" +#include "bu/list.h" + +namespace Bu +{ + class TafProperty; + class TafComment; + /** + * + *@ingroup Taf + */ + class TafGroup : public TafNode + { + public: + typedef Bu::List PropList; + typedef Bu::Hash PropHash; + typedef Bu::List GroupList; + typedef Bu::Hash GroupHash; + typedef Bu::List NodeList; + + TafGroup( const Bu::FString &sName ); + virtual ~TafGroup(); + + const Bu::FString &getName() const; + void setName( const Bu::FString &sName ); + + bool hasProperty( const Bu::FString &sName ) const; + const Bu::FString &getProperty( const Bu::FString &sName ) const; + const Bu::FString &getProperty( const Bu::FString &sName, + const Bu::FString &sDef ) const; + const PropList &getProperties( const Bu::FString &sName ) const; + bool hasChild( const Bu::FString &sName ) const; + const TafGroup *getChild( const Bu::FString &sName ) const; + const GroupList &getChildren( const Bu::FString &sName ) const; + TafNode *addChild( TafNode *pNode ); + TafGroup *addChild( TafGroup *pNode ); + TafProperty *addChild( TafProperty *pNode ); + TafComment *addChild( TafComment *pNode ); + TafGroup *addGroup( const Bu::FString &sName ); + TafProperty *addProperty( + const Bu::FString &sName, const Bu::FString &sValue ); + const NodeList &getChildren() const; + + private: + Bu::FString sName; + PropHash hProp; + GroupHash hChildren; + NodeList lChildren; + }; +} + +#endif diff --git a/src/tafnode.cpp b/src/tafnode.cpp index 8ea2e95..e7711fb 100644 --- a/src/tafnode.cpp +++ b/src/tafnode.cpp @@ -23,198 +23,3 @@ Bu::TafNode::NodeType Bu::TafNode::getType() const return eType; } -Bu::TafGroup::TafGroup( const Bu::FString &sName ) : - TafNode( typeGroup ), - sName( sName ) -{ -} - -Bu::TafGroup::~TafGroup() -{ - for( NodeList::iterator i = lChildren.begin(); i != lChildren.end(); i++ ) - { - delete (*i); - } -} - -const Bu::FString &Bu::TafGroup::getName() const -{ - return sName; -} - -void Bu::TafGroup::setName( const Bu::FString &sName ) -{ - this->sName = sName; -} - -Bu::TafNode *Bu::TafGroup::addChild( Bu::TafNode *pNode ) -{ - switch( pNode->getType() ) - { - case typeGroup: - addChild( (Bu::TafGroup *)pNode ); - break; - - case typeProperty: - addChild( (Bu::TafProperty *)pNode ); - break; - - case typeComment: - addChild( (Bu::TafComment *)pNode ); - break; - } - - return pNode; -} - -Bu::TafGroup *Bu::TafGroup::addChild( TafGroup *pNode ) -{ - TafGroup *pGroup = (TafGroup *)pNode; - if( !hChildren.has( pGroup->getName() ) ) - hChildren.insert( pGroup->getName(), GroupList() ); - hChildren.get( pGroup->getName() ).append( pGroup ); - lChildren.append( pNode ); - return pNode; -} - -Bu::TafProperty *Bu::TafGroup::addChild( TafProperty *pNode ) -{ - TafProperty *pProperty = (TafProperty *)pNode; - if( !hProp.has( pProperty->getName() ) ) - hProp.insert( pProperty->getName(), PropList() ); - hProp.get( pProperty->getName() ).append( pProperty->getValue() ); - lChildren.append( pNode ); - return pNode; -} - -Bu::TafComment *Bu::TafGroup::addChild( TafComment *pNode ) -{ - lChildren.append( pNode ); - return pNode; -} - -Bu::TafGroup *Bu::TafGroup::addGroup( const Bu::FString &sName ) -{ - return addChild( new TafGroup( sName ) ); -} - -Bu::TafProperty *Bu::TafGroup::addProperty( - const Bu::FString &sName, const Bu::FString &sValue ) -{ - return addChild( new TafProperty( sName, sValue ) ); -} - -bool Bu::TafGroup::hasChild( const Bu::FString &sName ) const -{ - return hChildren.has( sName ); -} - -const Bu::TafGroup::GroupList &Bu::TafGroup::getChildren( const Bu::FString &sName ) const -{ - try { - return hChildren.get( sName ); - } catch( Bu::HashException &e ) - { - throw Bu::TafException("No children of group \"%s\" match \"%s\".", - this->sName.getStr(), sName.getStr() ); - } -} - -const Bu::TafGroup::NodeList &Bu::TafGroup::getChildren() const -{ - return lChildren; -} - -const Bu::TafGroup *Bu::TafGroup::getChild( const Bu::FString &sName ) const -{ - try { - return hChildren.get( sName ).first(); - } catch( Bu::HashException &e ) - { - throw Bu::TafException("No children of group \"%s\" match \"%s\".", - this->sName.getStr(), sName.getStr() ); - } -} - -bool Bu::TafGroup::hasProperty( const Bu::FString &sName ) const -{ - return hProp.has( sName ); -} - -const Bu::TafGroup::PropList &Bu::TafGroup::getProperties( const Bu::FString &sName ) const -{ - try { - return hProp.get( sName ); - } catch( Bu::HashException &e ) - { - throw Bu::TafException("No properties of group \"%s\" match \"%s\".", - this->sName.getStr(), sName.getStr() ); - } -} - -const Bu::FString &Bu::TafGroup::getProperty( const Bu::FString &sName ) const -{ - try { - return hProp.get( sName ).first(); - } catch( Bu::HashException &e ) - { - throw Bu::TafException("No properties of group \"%s\" match \"%s\".", - this->sName.getStr(), sName.getStr() ); - } -} - -const Bu::FString &Bu::TafGroup::getProperty( const Bu::FString &sName, - const Bu::FString &sDef ) const -{ - try - { - return hProp.get( sName ).first(); - } - catch( Bu::HashException &e ) - { - return sDef; - } -} - -Bu::TafProperty::TafProperty( const Bu::FString &sName, const Bu::FString &sValue ) : - TafNode( typeProperty ), - sName( sName ), - sValue( sValue ) -{ -} - -Bu::TafProperty::~TafProperty() -{ -} - -const Bu::FString &Bu::TafProperty::getName() const -{ - return sName; -} - -const Bu::FString &Bu::TafProperty::getValue() const -{ - return sValue; -} - -Bu::TafComment::TafComment( const Bu::FString &sText, bool bEOL ) : - TafNode( typeComment ), - sText( sText ), - bEOL( bEOL ) -{ -} - -Bu::TafComment::~TafComment() -{ -} - -const Bu::FString &Bu::TafComment::getText() const -{ - return sText; -} - -bool Bu::TafComment::isEOLStyle() const -{ - return bEOL; -} - diff --git a/src/tafnode.h b/src/tafnode.h index f6d2ea9..5aa5082 100644 --- a/src/tafnode.h +++ b/src/tafnode.h @@ -11,7 +11,6 @@ #include #include "bu/fstring.h" #include "bu/hash.h" -#include "bu/list.h" #include "bu/exceptionbase.h" namespace Bu @@ -40,87 +39,6 @@ namespace Bu private: NodeType eType; }; - - class TafProperty; - class TafComment; - /** - * - *@ingroup Taf - */ - class TafGroup : public TafNode - { - public: - typedef Bu::List PropList; - typedef Bu::Hash PropHash; - typedef Bu::List GroupList; - typedef Bu::Hash GroupHash; - typedef Bu::List NodeList; - - TafGroup( const Bu::FString &sName ); - virtual ~TafGroup(); - - const Bu::FString &getName() const; - void setName( const Bu::FString &sName ); - - bool hasProperty( const Bu::FString &sName ) const; - const Bu::FString &getProperty( const Bu::FString &sName ) const; - const Bu::FString &getProperty( const Bu::FString &sName, - const Bu::FString &sDef ) const; - const PropList &getProperties( const Bu::FString &sName ) const; - bool hasChild( const Bu::FString &sName ) const; - const TafGroup *getChild( const Bu::FString &sName ) const; - const GroupList &getChildren( const Bu::FString &sName ) const; - TafNode *addChild( TafNode *pNode ); - TafGroup *addChild( TafGroup *pNode ); - TafProperty *addChild( TafProperty *pNode ); - TafComment *addChild( TafComment *pNode ); - TafGroup *addGroup( const Bu::FString &sName ); - TafProperty *addProperty( - const Bu::FString &sName, const Bu::FString &sValue ); - const NodeList &getChildren() const; - - private: - Bu::FString sName; - PropHash hProp; - GroupHash hChildren; - NodeList lChildren; - }; - - /** - * - *@ingroup Taf - */ - class TafProperty : public TafNode - { - public: - TafProperty( const Bu::FString &sName, const Bu::FString &sValue ); - virtual ~TafProperty(); - - const Bu::FString &getName() const; - const Bu::FString &getValue() const; - - private: - Bu::FString sName; - Bu::FString sValue; - }; - - /** - * - *@ingroup Taf - */ - class TafComment : public TafNode - { - public: - TafComment( const Bu::FString &sText, bool bEOL=false ); - virtual ~TafComment(); - - const Bu::FString &getText() const; - bool isEOLStyle() const; - - private: - Bu::FString sText; - bool bEOL; - }; } #endif diff --git a/src/tafproperty.cpp b/src/tafproperty.cpp new file mode 100644 index 0000000..855c5bb --- /dev/null +++ b/src/tafproperty.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2007-2008 Xagasoft, All rights reserved. + * + * This file is part of the libbu++ library and is released under the + * terms of the license contained in the file LICENSE. + */ + +#include "bu/tafproperty.h" + +Bu::TafProperty::TafProperty( const Bu::FString &sName, const Bu::FString &sValue ) : + TafNode( typeProperty ), + sName( sName ), + sValue( sValue ) +{ +} + +Bu::TafProperty::~TafProperty() +{ +} + +const Bu::FString &Bu::TafProperty::getName() const +{ + return sName; +} + +const Bu::FString &Bu::TafProperty::getValue() const +{ + return sValue; +} + diff --git a/src/tafproperty.h b/src/tafproperty.h new file mode 100644 index 0000000..3589a58 --- /dev/null +++ b/src/tafproperty.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2007-2008 Xagasoft, All rights reserved. + * + * This file is part of the libbu++ library and is released under the + * terms of the license contained in the file LICENSE. + */ + +#ifndef BU_TAF_PROPERTY_H +#define BU_TAF_PROPERTY_H + +#include +#include "bu/tafnode.h" + +namespace Bu +{ + /** + * + *@ingroup Taf + */ + class TafProperty : public TafNode + { + public: + TafProperty( const Bu::FString &sName, const Bu::FString &sValue ); + virtual ~TafProperty(); + + const Bu::FString &getName() const; + const Bu::FString &getValue() const; + + private: + Bu::FString sName; + Bu::FString sValue; + }; +} + +#endif diff --git a/src/tafreader.cpp b/src/tafreader.cpp index ebf54c1..f3265ab 100644 --- a/src/tafreader.cpp +++ b/src/tafreader.cpp @@ -5,8 +5,9 @@ * terms of the license contained in the file LICENSE. */ -#include "bu/tafreader.h" +#include "bu/taf.h" #include "bu/fstring.h" +#include "bu/stream.h" #include diff --git a/src/tafreader.h b/src/tafreader.h index 53ab6d4..286ee39 100644 --- a/src/tafreader.h +++ b/src/tafreader.h @@ -9,12 +9,16 @@ #define BU_TAF_READER_H #include -#include "bu/tafnode.h" -#include "bu/stream.h" #include "bu/fstring.h" namespace Bu { + class TafNode; + class TafGroup; + class TafProperty; + class TafComment; + class Stream; + /** * *@ingroup Taf diff --git a/src/tafwriter.cpp b/src/tafwriter.cpp index 82d39e5..c5fc730 100644 --- a/src/tafwriter.cpp +++ b/src/tafwriter.cpp @@ -5,8 +5,7 @@ * terms of the license contained in the file LICENSE. */ -#include "bu/tafwriter.h" -#include "bu/tafnode.h" +#include "bu/taf.h" #include "bu/stream.h" Bu::TafWriter::TafWriter( Bu::Stream &sOut ) : diff --git a/src/tests/taf.cpp b/src/tests/taf.cpp index 45a6430..deadfb2 100644 --- a/src/tests/taf.cpp +++ b/src/tests/taf.cpp @@ -5,8 +5,7 @@ * terms of the license contained in the file LICENSE. */ -#include "bu/tafreader.h" -#include "bu/tafwriter.h" +#include "bu/taf.h" #include "bu/file.h" int main( int argc, char *argv[] ) diff --git a/src/unit/taf.unit b/src/unit/taf.unit index 5588c85..eeddd53 100644 --- a/src/unit/taf.unit +++ b/src/unit/taf.unit @@ -7,8 +7,7 @@ */ #include "bu/file.h" -#include "bu/tafreader.h" -#include "bu/tafwriter.h" +#include "bu/taf.h" #include "bu/membuf.h" #include -- cgit v1.2.3