aboutsummaryrefslogtreecommitdiff
path: root/src/stable/tafgroup.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/stable/tafgroup.cpp')
-rw-r--r--src/stable/tafgroup.cpp224
1 files changed, 112 insertions, 112 deletions
diff --git a/src/stable/tafgroup.cpp b/src/stable/tafgroup.cpp
index 27af09e..7e15b26 100644
--- a/src/stable/tafgroup.cpp
+++ b/src/stable/tafgroup.cpp
@@ -10,215 +10,215 @@
10#include "bu/tafcomment.h" 10#include "bu/tafcomment.h"
11 11
12Bu::TafGroup::TafGroup( const TafGroup &rSrc ) : 12Bu::TafGroup::TafGroup( const TafGroup &rSrc ) :
13 TafNode( typeGroup ), 13 TafNode( typeGroup ),
14 sName( rSrc.sName ) 14 sName( rSrc.sName )
15{ 15{
16 for( NodeList::const_iterator i = rSrc.lChildren.begin(); i; i++ ) 16 for( NodeList::const_iterator i = rSrc.lChildren.begin(); i; i++ )
17 { 17 {
18 switch( (*i)->getType() ) 18 switch( (*i)->getType() )
19 { 19 {
20 case typeGroup: 20 case typeGroup:
21 addChild( new TafGroup( *dynamic_cast<const TafGroup *>(*i) ) ); 21 addChild( new TafGroup( *dynamic_cast<const TafGroup *>(*i) ) );
22 break; 22 break;
23 23
24 case typeProperty: 24 case typeProperty:
25 addChild( new TafProperty( *dynamic_cast<const TafProperty *>(*i) ) ); 25 addChild( new TafProperty( *dynamic_cast<const TafProperty *>(*i) ) );
26 break; 26 break;
27 27
28 case typeComment: 28 case typeComment:
29 addChild( new TafComment( *dynamic_cast<const TafComment *>(*i) ) ); 29 addChild( new TafComment( *dynamic_cast<const TafComment *>(*i) ) );
30 break; 30 break;
31 } 31 }
32 } 32 }
33} 33}
34 34
35Bu::TafGroup::TafGroup( const Bu::String &sName ) : 35Bu::TafGroup::TafGroup( const Bu::String &sName ) :
36 TafNode( typeGroup ), 36 TafNode( typeGroup ),
37 sName( sName ) 37 sName( sName )
38{ 38{
39} 39}
40 40
41Bu::TafGroup::~TafGroup() 41Bu::TafGroup::~TafGroup()
42{ 42{
43 for( NodeList::iterator i = lChildren.begin(); i != lChildren.end(); i++ ) 43 for( NodeList::iterator i = lChildren.begin(); i != lChildren.end(); i++ )
44 { 44 {
45 delete (*i); 45 delete (*i);
46 } 46 }
47} 47}
48 48
49const Bu::String &Bu::TafGroup::getName() const 49const Bu::String &Bu::TafGroup::getName() const
50{ 50{
51 return sName; 51 return sName;
52} 52}
53 53
54void Bu::TafGroup::setName( const Bu::String &sName ) 54void Bu::TafGroup::setName( const Bu::String &sName )
55{ 55{
56 this->sName = sName; 56 this->sName = sName;
57} 57}
58 58
59Bu::TafNode *Bu::TafGroup::addChild( Bu::TafNode *pNode ) 59Bu::TafNode *Bu::TafGroup::addChild( Bu::TafNode *pNode )
60{ 60{
61 switch( pNode->getType() ) 61 switch( pNode->getType() )
62 { 62 {
63 case typeGroup: 63 case typeGroup:
64 addChild( (Bu::TafGroup *)pNode ); 64 addChild( (Bu::TafGroup *)pNode );
65 break; 65 break;
66 66
67 case typeProperty: 67 case typeProperty:
68 addChild( (Bu::TafProperty *)pNode ); 68 addChild( (Bu::TafProperty *)pNode );
69 break; 69 break;
70 70
71 case typeComment: 71 case typeComment:
72 addChild( (Bu::TafComment *)pNode ); 72 addChild( (Bu::TafComment *)pNode );
73 break; 73 break;
74 } 74 }
75 75
76 return pNode; 76 return pNode;
77} 77}
78 78
79Bu::TafGroup *Bu::TafGroup::addChild( TafGroup *pNode ) 79Bu::TafGroup *Bu::TafGroup::addChild( TafGroup *pNode )
80{ 80{
81 TafGroup *pGroup = (TafGroup *)pNode; 81 TafGroup *pGroup = (TafGroup *)pNode;
82 if( !hChildren.has( pGroup->getName() ) ) 82 if( !hChildren.has( pGroup->getName() ) )
83 hChildren.insert( pGroup->getName(), GroupList() ); 83 hChildren.insert( pGroup->getName(), GroupList() );
84 hChildren.get( pGroup->getName() ).append( pGroup ); 84 hChildren.get( pGroup->getName() ).append( pGroup );
85 lChildren.append( pNode ); 85 lChildren.append( pNode );
86 return pNode; 86 return pNode;
87} 87}
88 88
89Bu::TafProperty *Bu::TafGroup::addChild( TafProperty *pNode ) 89Bu::TafProperty *Bu::TafGroup::addChild( TafProperty *pNode )
90{ 90{
91 TafProperty *pProperty = (TafProperty *)pNode; 91 TafProperty *pProperty = (TafProperty *)pNode;
92 if( !hProp.has( pProperty->getName() ) ) 92 if( !hProp.has( pProperty->getName() ) )
93 hProp.insert( pProperty->getName(), PropList() ); 93 hProp.insert( pProperty->getName(), PropList() );
94 hProp.get( pProperty->getName() ).append( pProperty->getValue() ); 94 hProp.get( pProperty->getName() ).append( pProperty->getValue() );
95 lChildren.append( pNode ); 95 lChildren.append( pNode );
96 return pNode; 96 return pNode;
97} 97}
98 98
99Bu::TafComment *Bu::TafGroup::addChild( TafComment *pNode ) 99Bu::TafComment *Bu::TafGroup::addChild( TafComment *pNode )
100{ 100{
101 lChildren.append( pNode ); 101 lChildren.append( pNode );
102 return pNode; 102 return pNode;
103} 103}
104 104
105Bu::TafGroup *Bu::TafGroup::addGroup( const Bu::String &sName ) 105Bu::TafGroup *Bu::TafGroup::addGroup( const Bu::String &sName )
106{ 106{
107 return addChild( new TafGroup( sName ) ); 107 return addChild( new TafGroup( sName ) );
108} 108}
109 109
110Bu::TafProperty *Bu::TafGroup::addProperty( 110Bu::TafProperty *Bu::TafGroup::addProperty(
111 const Bu::String &sName, const Bu::String &sValue ) 111 const Bu::String &sName, const Bu::String &sValue )
112{ 112{
113 return addChild( new TafProperty( sName, sValue ) ); 113 return addChild( new TafProperty( sName, sValue ) );
114} 114}
115 115
116bool Bu::TafGroup::hasChild( const Bu::String &sName ) const 116bool Bu::TafGroup::hasChild( const Bu::String &sName ) const
117{ 117{
118 return hChildren.has( sName ); 118 return hChildren.has( sName );
119} 119}
120 120
121const Bu::TafGroup::GroupList &Bu::TafGroup::getChildren( const Bu::String &sName ) const 121const Bu::TafGroup::GroupList &Bu::TafGroup::getChildren( const Bu::String &sName ) const
122{ 122{
123 try { 123 try {
124 return hChildren.get( sName ); 124 return hChildren.get( sName );
125 } catch( Bu::HashException &e ) 125 } catch( Bu::HashException &e )
126 { 126 {
127 throw Bu::TafException("No children of group \"%s\" match \"%s\".", 127 throw Bu::TafException("No children of group \"%s\" match \"%s\".",
128 this->sName.getStr(), sName.getStr() ); 128 this->sName.getStr(), sName.getStr() );
129 } 129 }
130} 130}
131 131
132const Bu::TafGroup::NodeList &Bu::TafGroup::getChildren() const 132const Bu::TafGroup::NodeList &Bu::TafGroup::getChildren() const
133{ 133{
134 return lChildren; 134 return lChildren;
135} 135}
136 136
137const Bu::TafGroup *Bu::TafGroup::getChild( const Bu::String &sName ) const 137const Bu::TafGroup *Bu::TafGroup::getChild( const Bu::String &sName ) const
138{ 138{
139 try { 139 try {
140 return hChildren.get( sName ).first(); 140 return hChildren.get( sName ).first();
141 } catch( Bu::HashException &e ) 141 } catch( Bu::HashException &e )
142 { 142 {
143 throw Bu::TafException("No children of group \"%s\" match \"%s\".", 143 throw Bu::TafException("No children of group \"%s\" match \"%s\".",
144 this->sName.getStr(), sName.getStr() ); 144 this->sName.getStr(), sName.getStr() );
145 } 145 }
146} 146}
147 147
148bool Bu::TafGroup::hasProperty( const Bu::String &sName ) const 148bool Bu::TafGroup::hasProperty( const Bu::String &sName ) const
149{ 149{
150 return hProp.has( sName ); 150 return hProp.has( sName );
151} 151}
152 152
153const Bu::TafGroup::PropList &Bu::TafGroup::getProperties( const Bu::String &sName ) const 153const Bu::TafGroup::PropList &Bu::TafGroup::getProperties( const Bu::String &sName ) const
154{ 154{
155 try { 155 try {
156 return hProp.get( sName ); 156 return hProp.get( sName );
157 } catch( Bu::HashException &e ) 157 } catch( Bu::HashException &e )
158 { 158 {
159 throw Bu::TafException("No properties of group \"%s\" match \"%s\".", 159 throw Bu::TafException("No properties of group \"%s\" match \"%s\".",
160 this->sName.getStr(), sName.getStr() ); 160 this->sName.getStr(), sName.getStr() );
161 } 161 }
162} 162}
163 163
164const Bu::String &Bu::TafGroup::getProperty( const Bu::String &sName ) const 164const Bu::String &Bu::TafGroup::getProperty( const Bu::String &sName ) const
165{ 165{
166 try { 166 try {
167 return hProp.get( sName ).first(); 167 return hProp.get( sName ).first();
168 } catch( Bu::HashException &e ) 168 } catch( Bu::HashException &e )
169 { 169 {
170 throw Bu::TafException("No properties of group \"%s\" match \"%s\".", 170 throw Bu::TafException("No properties of group \"%s\" match \"%s\".",
171 this->sName.getStr(), sName.getStr() ); 171 this->sName.getStr(), sName.getStr() );
172 } 172 }
173} 173}
174 174
175const Bu::String &Bu::TafGroup::getProperty( const Bu::String &sName, 175const Bu::String &Bu::TafGroup::getProperty( const Bu::String &sName,
176 const Bu::String &sDef ) const 176 const Bu::String &sDef ) const
177{ 177{
178 try 178 try
179 { 179 {
180 return hProp.get( sName ).first(); 180 return hProp.get( sName ).first();
181 } 181 }
182 catch( Bu::HashException &e ) 182 catch( Bu::HashException &e )
183 { 183 {
184 return sDef; 184 return sDef;
185 } 185 }
186} 186}
187 187
188const Bu::TafGroup *Bu::TafGroup::getChildByPath( 188const Bu::TafGroup *Bu::TafGroup::getChildByPath(
189 const Bu::String &sPath ) const 189 const Bu::String &sPath ) const
190{ 190{
191 return getChildByPath( sPath.split('/') ); 191 return getChildByPath( sPath.split('/') );
192} 192}
193 193
194const Bu::TafGroup *Bu::TafGroup::getChildByPath( Bu::StrList lPath ) const 194const Bu::TafGroup *Bu::TafGroup::getChildByPath( Bu::StrList lPath ) const
195{ 195{
196 const Bu::TafGroup *cur = this; 196 const Bu::TafGroup *cur = this;
197 197
198 for( Bu::StrList::const_iterator i = lPath.begin(); i; i++ ) 198 for( Bu::StrList::const_iterator i = lPath.begin(); i; i++ )
199 { 199 {
200 cur = cur->getChild( *i ); 200 cur = cur->getChild( *i );
201 } 201 }
202 202
203 return cur; 203 return cur;
204} 204}
205 205
206const Bu::String &Bu::TafGroup::getByPath( const Bu::String &sPath ) const 206const Bu::String &Bu::TafGroup::getByPath( const Bu::String &sPath ) const
207{ 207{
208 return getByPath( sPath.split('/') ); 208 return getByPath( sPath.split('/') );
209} 209}
210 210
211const Bu::String &Bu::TafGroup::getByPath( Bu::StrList lPath ) const 211const Bu::String &Bu::TafGroup::getByPath( Bu::StrList lPath ) const
212{ 212{
213 const Bu::TafGroup *cur = this; 213 const Bu::TafGroup *cur = this;
214 214
215 for( Bu::StrList::const_iterator i = lPath.begin(); i; i++ ) 215 for( Bu::StrList::const_iterator i = lPath.begin(); i; i++ )
216 { 216 {
217 if( !(i+1) ) 217 if( !(i+1) )
218 break; 218 break;
219 cur = cur->getChild( *i ); 219 cur = cur->getChild( *i );
220 } 220 }
221 221
222 return cur->getProperty( lPath.last() ); 222 return cur->getProperty( lPath.last() );
223} 223}
224 224