aboutsummaryrefslogtreecommitdiff
path: root/src/tafnode.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-06-27 18:11:13 +0000
committerMike Buland <eichlan@xagasoft.com>2007-06-27 18:11:13 +0000
commitc86c0cf088492e02431dffb1f860ff2f6faa492d (patch)
tree1191879314028bb8f58daf45d48dacc6ba9ea583 /src/tafnode.cpp
parent5ec9a131e12d021c42b46b601f5e79502485bebb (diff)
downloadlibbu++-c86c0cf088492e02431dffb1f860ff2f6faa492d.tar.gz
libbu++-c86c0cf088492e02431dffb1f860ff2f6faa492d.tar.bz2
libbu++-c86c0cf088492e02431dffb1f860ff2f6faa492d.tar.xz
libbu++-c86c0cf088492e02431dffb1f860ff2f6faa492d.zip
The taf system is new and improved. The writer works, we added C++ style
comment blocks, and it retains the order of all nodes.
Diffstat (limited to 'src/tafnode.cpp')
-rw-r--r--src/tafnode.cpp138
1 files changed, 107 insertions, 31 deletions
diff --git a/src/tafnode.cpp b/src/tafnode.cpp
index b9a4a24..b7cf211 100644
--- a/src/tafnode.cpp
+++ b/src/tafnode.cpp
@@ -1,72 +1,148 @@
1#include "tafnode.h" 1#include "tafnode.h"
2 2
3Bu::TafNode::TafNode() 3Bu::TafNode::TafNode( NodeType eType ) :
4 eType( eType )
4{ 5{
5} 6}
6 7
7Bu::TafNode::~TafNode() 8Bu::TafNode::~TafNode()
8{ 9{
10}
11
12const Bu::TafNode::NodeType Bu::TafNode::getType() const
13{
14 return eType;
15}
16
17/*
18const Bu::TafNode::PropList &Bu::TafNode::getProperties( const Bu::FString &sName ) const
19{
20 return hProp.get( sName );
21}
22
23const Bu::TafNode::NodeList &Bu::TafNode::getChildren( const Bu::FString &sName ) const
24{
25 return hChildren.get( sName );
26}
27
28const Bu::FString &Bu::TafNode::getProperty( const Bu::FString &sName ) const
29{
30 return getProperties( sName ).first();
31}
32
33const Bu::TafNode *Bu::TafNode::getChild( const Bu::FString &sName ) const
34{
35 return getChildren( sName ).first();
36}
37*/
38
39Bu::TafGroup::TafGroup( const Bu::FString &sName ) :
40 TafNode( typeGroup ),
41 sName( sName )
42{
43}
44
45Bu::TafGroup::~TafGroup()
46{
9 //printf("Entering Bu::TafNode::~TafNode() \"%s\"\n", sName.getStr() ); 47 //printf("Entering Bu::TafNode::~TafNode() \"%s\"\n", sName.getStr() );
10 for( NodeHash::iterator i = hChildren.begin(); i != hChildren.end(); i++ ) 48 for( NodeList::iterator i = lChildren.begin(); i != lChildren.end(); i++ )
11 { 49 {
12 NodeList &l = i.getValue(); 50 delete (*i);
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 } 51 }
19} 52}
20 53
21void Bu::TafNode::setProperty( Bu::FString sName, Bu::FString sValue ) 54const Bu::FString &Bu::TafGroup::getName() const
22{ 55{
23 if( !hProp.has( sName ) ) 56 return sName;
57}
58
59void Bu::TafGroup::addChild( Bu::TafNode *pNode )
60{
61 switch( pNode->getType() )
24 { 62 {
25 hProp.insert( sName, PropList() ); 63 case typeGroup:
64 {
65 TafGroup *pGroup = (TafGroup *)pNode;
66 if( !hChildren.has( pGroup->getName() ) )
67 hChildren.insert( pGroup->getName(), GroupList() );
68 hChildren.get( pGroup->getName() ).append( pGroup );
69 }
70 break;
71
72 case typeProperty:
73 {
74 TafProperty *pProperty = (TafProperty *)pNode;
75 if( !hProp.has( pProperty->getName() ) )
76 hProp.insert( pProperty->getName(), PropList() );
77 hProp.get( pProperty->getName() ).append( pProperty->getValue() );
78 }
79 break;
80
81 case typeComment:
82 break;
26 } 83 }
27 84
28 hProp.get( sName ).append( sValue ); 85 lChildren.append( pNode );
29} 86}
30 87
31void Bu::TafNode::addChild( TafNode *pNode ) 88const Bu::TafGroup::GroupList &Bu::TafGroup::getChildren( const Bu::FString &sName ) const
32{ 89{
33 if( !hChildren.has( pNode->getName() ) ) 90 return hChildren.get( sName );
34 { 91}
35 hChildren.insert( pNode->getName(), NodeList() );
36 }
37 92
38 //printf("Appending \"%s\"\n", pNode->getName().getStr() ); 93const Bu::TafGroup::NodeList &Bu::TafGroup::getChildren() const
39 hChildren.get( pNode->getName() ).append( pNode ); 94{
40 //printf("[%08X]\n", hChildren.get( pNode->getName() ).last() ); 95 return lChildren;
41} 96}
42 97
43const Bu::TafNode::PropList &Bu::TafNode::getProperties( const Bu::FString &sName ) const 98const Bu::TafGroup *Bu::TafGroup::getChild( const Bu::FString &sName ) const
44{ 99{
45 return hProp.get( sName ); 100 return hChildren.get( sName ).first();
46} 101}
47 102
48const Bu::TafNode::NodeList &Bu::TafNode::getChildren( const Bu::FString &sName ) const 103const Bu::TafGroup::PropList &Bu::TafGroup::getProperties( const Bu::FString &sName ) const
49{ 104{
50 return hChildren.get( sName ); 105 return hProp.get( sName );
51} 106}
52 107
53const Bu::FString &Bu::TafNode::getProperty( const Bu::FString &sName ) const 108const Bu::FString &Bu::TafGroup::getProperty( const Bu::FString &sName ) const
54{ 109{
55 return getProperties( sName ).first(); 110 return hProp.get( sName ).first();
56} 111}
57 112
58const Bu::TafNode *Bu::TafNode::getChild( const Bu::FString &sName ) const 113Bu::TafProperty::TafProperty( const Bu::FString &sName, const Bu::FString &sValue ) :
114 TafNode( typeProperty ),
115 sName( sName ),
116 sValue( sValue )
59{ 117{
60 return getChildren( sName ).first();
61} 118}
62 119
63void Bu::TafNode::setName( const Bu::FString &sName ) 120Bu::TafProperty::~TafProperty()
64{ 121{
65 this->sName = sName;
66} 122}
67 123
68const Bu::FString &Bu::TafNode::getName() const 124const Bu::FString &Bu::TafProperty::getName() const
69{ 125{
70 return sName; 126 return sName;
71} 127}
72 128
129const Bu::FString &Bu::TafProperty::getValue() const
130{
131 return sValue;
132}
133
134Bu::TafComment::TafComment( const Bu::FString &sText ) :
135 TafNode( typeComment ),
136 sText( sText )
137{
138}
139
140Bu::TafComment::~TafComment()
141{
142}
143
144const Bu::FString &Bu::TafComment::getText() const
145{
146 return sText;
147}
148