aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-06-07 03:26:43 +0000
committerMike Buland <eichlan@xagasoft.com>2007-06-07 03:26:43 +0000
commit8b598e8436a7110abbd0a7566138bcaa952bb527 (patch)
tree9939beb03fb606e3f9dc3ff8ac04ed3725008ac6 /src
parent1f785c99b4e9e76d6803bd66cc4256e9b03fa788 (diff)
downloadlibbu++-8b598e8436a7110abbd0a7566138bcaa952bb527.tar.gz
libbu++-8b598e8436a7110abbd0a7566138bcaa952bb527.tar.bz2
libbu++-8b598e8436a7110abbd0a7566138bcaa952bb527.tar.xz
libbu++-8b598e8436a7110abbd0a7566138bcaa952bb527.zip
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%.
Diffstat (limited to 'src')
-rw-r--r--src/tafnode.cpp39
-rw-r--r--src/tafnode.h5
-rw-r--r--src/tafreader.cpp32
-rw-r--r--src/tafreader.h7
-rw-r--r--src/tests/taf.cpp11
5 files changed, 74 insertions, 20 deletions
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()
6 6
7Bu::TafNode::~TafNode() 7Bu::TafNode::~TafNode()
8{ 8{
9 printf("Entering Bu::TafNode::~TafNode() \"%s\"\n", sName.getStr() );
10 for( NodeHash::iterator i = hChildren.begin(); i != hChildren.end(); i++ )
11 {
12 NodeList &l = i.getValue();
13 for( NodeList::iterator k = l.begin(); k != l.end(); k++ )
14 {
15 printf("deleting: [%08X] %s\n", *k, "" );//(*k)->getName().getStr() );
16 delete (*k);
17 }
18 }
9} 19}
10 20
11void Bu::TafNode::setProperty( Bu::FString sName, Bu::FString sValue ) 21void Bu::TafNode::setProperty( Bu::FString sName, Bu::FString sValue )
12{ 22{
13 if( hProp.has( sName ) ) 23 if( !hProp.has( sName ) )
14 { 24 {
15 hProp.insert( sName, PropList() ); 25 hProp.insert( sName, PropList() );
16 } 26 }
@@ -18,8 +28,35 @@ void Bu::TafNode::setProperty( Bu::FString sName, Bu::FString sValue )
18 hProp.get( sName ).append( sValue ); 28 hProp.get( sName ).append( sValue );
19} 29}
20 30
31void Bu::TafNode::addChild( TafNode *pNode )
32{
33 if( !hChildren.has( pNode->getName() ) )
34 {
35 hChildren.insert( pNode->getName(), NodeList() );
36 }
37
38 printf("Appending \"%s\"\n", pNode->getName().getStr() );
39 hChildren.get( pNode->getName() ).append( pNode );
40 printf("[%08X]\n", hChildren.get( pNode->getName() ).last() );
41}
42
21const Bu::TafNode::PropList &Bu::TafNode::getProperty( const Bu::FString &sName ) 43const Bu::TafNode::PropList &Bu::TafNode::getProperty( const Bu::FString &sName )
22{ 44{
23 return hProp.get( sName ); 45 return hProp.get( sName );
24} 46}
25 47
48const Bu::TafNode::NodeList &Bu::TafNode::getNode( const Bu::FString &sName )
49{
50 return hChildren.get( sName );
51}
52
53void Bu::TafNode::setName( const Bu::FString &sName )
54{
55 this->sName = sName;
56}
57
58const Bu::FString &Bu::TafNode::getName()
59{
60 return sName;
61}
62
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
23 TafNode(); 23 TafNode();
24 virtual ~TafNode(); 24 virtual ~TafNode();
25 25
26 void setName( const Bu::FString &sName );
27 const Bu::FString &getName();
28
26 void setProperty( Bu::FString sName, Bu::FString sValue ); 29 void setProperty( Bu::FString sName, Bu::FString sValue );
27 const PropList &getProperty( const Bu::FString &sName ); 30 const PropList &getProperty( const Bu::FString &sName );
31 const NodeList &getNode( const Bu::FString &sName );
32 void addChild( TafNode *pNode );
28 33
29 private: 34 private:
30 Bu::FString sName; 35 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 @@
5using namespace Bu; 5using namespace Bu;
6 6
7Bu::TafReader::TafReader( Bu::Stream &sIn ) : 7Bu::TafReader::TafReader( Bu::Stream &sIn ) :
8 c( 0 ),
8 sIn( sIn ) 9 sIn( sIn )
9{ 10{
10 next();
11 node();
12} 11}
13 12
14Bu::TafReader::~TafReader() 13Bu::TafReader::~TafReader()
@@ -16,55 +15,58 @@ Bu::TafReader::~TafReader()
16 15
17} 16}
18 17
19Bu::TafNode *Bu::TafReader::readNode() 18Bu::TafNode *Bu::TafReader::getNode()
20{
21}
22
23void Bu::TafReader::node()
24{ 19{
20 if( c == 0 ) next();
21 TafNode *pNode = new TafNode();
25 ws(); 22 ws();
26 if( c != '{' ) 23 if( c != '{' )
27 throw TafException("Expected '{'"); 24 throw TafException("Expected '{'");
28 next(); 25 next();
29 ws(); 26 ws();
30 FString sName = readStr(); 27 FString sName = readStr();
28 pNode->setName( sName );
31 next(); 29 next();
32 printf("Node[%s]:\n", sName.getStr() ); 30 //printf("Node[%s]:\n", sName.getStr() );
33 31
34 nodeContent(); 32 nodeContent( pNode );
35 33
36 if( c != '}' ) 34 if( c != '}' )
37 throw TafException("Expected '}'"); 35 throw TafException("Expected '}'");
38 36
39 next(); 37 next();
38
39 return pNode;
40} 40}
41 41
42void Bu::TafReader::nodeContent() 42void Bu::TafReader::nodeContent( Bu::TafNode *pNode )
43{ 43{
44 for(;;) 44 for(;;)
45 { 45 {
46 ws(); 46 ws();
47 if( c == '{' ) 47 if( c == '{' )
48 node(); 48 pNode->addChild( getNode() );
49 else if( c == '}' ) 49 else if( c == '}' )
50 return; 50 return;
51 else 51 else
52 nodeProperty(); 52 nodeProperty( pNode );
53 } 53 }
54} 54}
55 55
56void Bu::TafReader::nodeProperty() 56void Bu::TafReader::nodeProperty( Bu::TafNode *pNode )
57{ 57{
58 FString sName = readStr(); 58 FString sName = readStr();
59 ws(); 59 ws();
60 if( c != '=' ) 60 if( c != '=' )
61 { 61 {
62 printf(" %s (true)\n", sName.getStr() ); 62 //printf(" %s (true)\n", sName.getStr() );
63 pNode->setProperty( sName, "" );
63 return; 64 return;
64 } 65 }
65 next(); 66 next();
66 FString sValue = readStr(); 67 FString sValue = readStr();
67 printf(" %s = %s\n", sName.getStr(), sValue.getStr() ); 68 pNode->setProperty( sName, sValue );
69 //printf(" %s = %s\n", sName.getStr(), sValue.getStr() );
68} 70}
69 71
70Bu::FString Bu::TafReader::readStr() 72Bu::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
17 TafReader( Bu::Stream &sIn ); 17 TafReader( Bu::Stream &sIn );
18 virtual ~TafReader(); 18 virtual ~TafReader();
19 19
20 Bu::TafNode *readNode(); 20 Bu::TafNode *getNode();
21 21
22 private: 22 private:
23 void node(); 23 void nodeContent( Bu::TafNode *pNode );
24 void nodeContent(); 24 void nodeProperty( Bu::TafNode *pNode );
25 void nodeProperty();
26 void ws(); 25 void ws();
27 bool isws(); 26 bool isws();
28 void next(); 27 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()
5{ 5{
6 Bu::File f("test.taf", "rb"); 6 Bu::File f("test.taf", "rb");
7 Bu::TafReader tr( f ); 7 Bu::TafReader tr( f );
8
9 Bu::TafNode *pNode = tr.getNode();
10
11 const Bu::TafNode::NodeList &l = pNode->getNode("stats");
12 for( Bu::TafNode::NodeList::const_iterator i = l.begin();
13 i != l.end(); i++ )
14 {
15 printf("%s\n", (*i)->getName().getStr() );
16 }
17
18 delete pNode;
8} 19}
9 20