From c2e3879b965d297604804f03271ac71c8c5c81f3 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 7 Jun 2007 04:55:29 +0000 Subject: The new taf interfaces seem to work just fine, except for saving and that loaded TafNode structures are immutable, it all looks really good. Saving should be a snap, and the immutable part I'm not sure is bad...we'll see what happens. Also, I'm contemplating looking into a way to add "named data structure" support to the Archive at a lower level, then allow it to use a nameing system to apply names to each data structure and then output to any backend that supports naming, like taf, xml, etc. --- src/hash.h | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++- src/tafnode.cpp | 24 +++++++++++++++++------- src/tafnode.h | 8 +++++--- src/tests/taf.cpp | 9 +++------ 4 files changed, 77 insertions(+), 17 deletions(-) diff --git a/src/hash.h b/src/hash.h index a81c355..f6c207f 100644 --- a/src/hash.h +++ b/src/hash.h @@ -358,6 +358,25 @@ namespace Bu ); } } + + virtual const value &get( key k ) const + { + uint32_t hash = __calcHashCode( k ); + bool bFill; + uint32_t nPos = probe( hash, k, bFill ); + + if( bFill ) + { + return aValues[nPos]; + } + else + { + throw HashException( + excodeNotFilled, + "No data assosiated with that key." + ); + } + } virtual bool has( key k ) { @@ -599,6 +618,38 @@ namespace Bu bFill = false; return nCur; } + + uint32_t probe( uint32_t hash, key k, bool &bFill, bool rehash=true ) const + { + uint32_t nCur = hash%nCapacity; + + // First we scan to see if the key is already there, abort if we + // run out of probing room, or we find a non-filled entry + for( int8_t j = 0; + isFilled( nCur ) && j < 32; + nCur = (nCur + (1<getName().getStr() ); + //printf("deleting: [%08X] %s\n", *k, "" );//(*k)->getName().getStr() ); delete (*k); } } @@ -35,27 +35,37 @@ void Bu::TafNode::addChild( TafNode *pNode ) hChildren.insert( pNode->getName(), NodeList() ); } - printf("Appending \"%s\"\n", pNode->getName().getStr() ); + //printf("Appending \"%s\"\n", pNode->getName().getStr() ); hChildren.get( pNode->getName() ).append( pNode ); - printf("[%08X]\n", hChildren.get( pNode->getName() ).last() ); + //printf("[%08X]\n", hChildren.get( pNode->getName() ).last() ); } -const Bu::TafNode::PropList &Bu::TafNode::getProperty( const Bu::FString &sName ) +const Bu::TafNode::PropList &Bu::TafNode::getProperties( const Bu::FString &sName ) const { return hProp.get( sName ); } -const Bu::TafNode::NodeList &Bu::TafNode::getNode( const Bu::FString &sName ) +const Bu::TafNode::NodeList &Bu::TafNode::getNodes( const Bu::FString &sName ) const { return hChildren.get( sName ); } +const Bu::FString &Bu::TafNode::getProperty( const Bu::FString &sName ) const +{ + return getProperties( sName ).first(); +} + +const Bu::TafNode *Bu::TafNode::getNode( const Bu::FString &sName ) const +{ + return getNodes( sName ).first(); +} + void Bu::TafNode::setName( const Bu::FString &sName ) { this->sName = sName; } -const Bu::FString &Bu::TafNode::getName() +const Bu::FString &Bu::TafNode::getName() const { return sName; } diff --git a/src/tafnode.h b/src/tafnode.h index a570d2d..10232d2 100644 --- a/src/tafnode.h +++ b/src/tafnode.h @@ -24,11 +24,13 @@ namespace Bu virtual ~TafNode(); void setName( const Bu::FString &sName ); - const Bu::FString &getName(); + const Bu::FString &getName() const; void setProperty( Bu::FString sName, Bu::FString sValue ); - const PropList &getProperty( const Bu::FString &sName ); - const NodeList &getNode( const Bu::FString &sName ); + const Bu::FString &getProperty( const Bu::FString &sName ) const; + const TafNode *getNode( const Bu::FString &sName ) const; + const PropList &getProperties( const Bu::FString &sName ) const; + const NodeList &getNodes( const Bu::FString &sName ) const; void addChild( TafNode *pNode ); private: diff --git a/src/tests/taf.cpp b/src/tests/taf.cpp index f7af2b2..e7bad52 100644 --- a/src/tests/taf.cpp +++ b/src/tests/taf.cpp @@ -8,12 +8,9 @@ int main() 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() ); - } + const Bu::TafNode *pStats = pNode->getNode("stats"); + printf("%s\n", pStats->getName().getStr() ); + printf(" str = %s\n", pStats->getProperty("str").getStr() ); delete pNode; } -- cgit v1.2.3