diff options
author | Mike Buland <eichlan@xagasoft.com> | 2012-03-25 20:00:08 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2012-03-25 20:00:08 +0000 |
commit | 469bbcf0701e1eb8a6670c23145b0da87357e178 (patch) | |
tree | b5b062a16e46a6c5d3410b4e574cd0cc09057211 /src/tafgroup.cpp | |
parent | ee1b79396076edc4e30aefb285fada03bb45e80d (diff) | |
download | libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.tar.gz libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.tar.bz2 libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.tar.xz libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.zip |
Code is all reorganized. We're about ready to release. I should write up a
little explenation of the arrangement.
Diffstat (limited to 'src/tafgroup.cpp')
-rw-r--r-- | src/tafgroup.cpp | 224 |
1 files changed, 0 insertions, 224 deletions
diff --git a/src/tafgroup.cpp b/src/tafgroup.cpp deleted file mode 100644 index ee180c3..0000000 --- a/src/tafgroup.cpp +++ /dev/null | |||
@@ -1,224 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include "bu/tafgroup.h" | ||
9 | #include "bu/tafproperty.h" | ||
10 | #include "bu/tafcomment.h" | ||
11 | |||
12 | Bu::TafGroup::TafGroup( const TafGroup &rSrc ) : | ||
13 | TafNode( typeGroup ), | ||
14 | sName( rSrc.sName ) | ||
15 | { | ||
16 | for( NodeList::const_iterator i = rSrc.lChildren.begin(); i; i++ ) | ||
17 | { | ||
18 | switch( (*i)->getType() ) | ||
19 | { | ||
20 | case typeGroup: | ||
21 | addChild( new TafGroup( *dynamic_cast<const TafGroup *>(*i) ) ); | ||
22 | break; | ||
23 | |||
24 | case typeProperty: | ||
25 | addChild( new TafProperty( *dynamic_cast<const TafProperty *>(*i) ) ); | ||
26 | break; | ||
27 | |||
28 | case typeComment: | ||
29 | addChild( new TafComment( *dynamic_cast<const TafComment *>(*i) ) ); | ||
30 | break; | ||
31 | } | ||
32 | } | ||
33 | } | ||
34 | |||
35 | Bu::TafGroup::TafGroup( const Bu::String &sName ) : | ||
36 | TafNode( typeGroup ), | ||
37 | sName( sName ) | ||
38 | { | ||
39 | } | ||
40 | |||
41 | Bu::TafGroup::~TafGroup() | ||
42 | { | ||
43 | for( NodeList::iterator i = lChildren.begin(); i != lChildren.end(); i++ ) | ||
44 | { | ||
45 | delete (*i); | ||
46 | } | ||
47 | } | ||
48 | |||
49 | const Bu::String &Bu::TafGroup::getName() const | ||
50 | { | ||
51 | return sName; | ||
52 | } | ||
53 | |||
54 | void Bu::TafGroup::setName( const Bu::String &sName ) | ||
55 | { | ||
56 | this->sName = sName; | ||
57 | } | ||
58 | |||
59 | Bu::TafNode *Bu::TafGroup::addChild( Bu::TafNode *pNode ) | ||
60 | { | ||
61 | switch( pNode->getType() ) | ||
62 | { | ||
63 | case typeGroup: | ||
64 | addChild( (Bu::TafGroup *)pNode ); | ||
65 | break; | ||
66 | |||
67 | case typeProperty: | ||
68 | addChild( (Bu::TafProperty *)pNode ); | ||
69 | break; | ||
70 | |||
71 | case typeComment: | ||
72 | addChild( (Bu::TafComment *)pNode ); | ||
73 | break; | ||
74 | } | ||
75 | |||
76 | return pNode; | ||
77 | } | ||
78 | |||
79 | Bu::TafGroup *Bu::TafGroup::addChild( TafGroup *pNode ) | ||
80 | { | ||
81 | TafGroup *pGroup = (TafGroup *)pNode; | ||
82 | if( !hChildren.has( pGroup->getName() ) ) | ||
83 | hChildren.insert( pGroup->getName(), GroupList() ); | ||
84 | hChildren.get( pGroup->getName() ).append( pGroup ); | ||
85 | lChildren.append( pNode ); | ||
86 | return pNode; | ||
87 | } | ||
88 | |||
89 | Bu::TafProperty *Bu::TafGroup::addChild( TafProperty *pNode ) | ||
90 | { | ||
91 | TafProperty *pProperty = (TafProperty *)pNode; | ||
92 | if( !hProp.has( pProperty->getName() ) ) | ||
93 | hProp.insert( pProperty->getName(), PropList() ); | ||
94 | hProp.get( pProperty->getName() ).append( pProperty->getValue() ); | ||
95 | lChildren.append( pNode ); | ||
96 | return pNode; | ||
97 | } | ||
98 | |||
99 | Bu::TafComment *Bu::TafGroup::addChild( TafComment *pNode ) | ||
100 | { | ||
101 | lChildren.append( pNode ); | ||
102 | return pNode; | ||
103 | } | ||
104 | |||
105 | Bu::TafGroup *Bu::TafGroup::addGroup( const Bu::String &sName ) | ||
106 | { | ||
107 | return addChild( new TafGroup( sName ) ); | ||
108 | } | ||
109 | |||
110 | Bu::TafProperty *Bu::TafGroup::addProperty( | ||
111 | const Bu::String &sName, const Bu::String &sValue ) | ||
112 | { | ||
113 | return addChild( new TafProperty( sName, sValue ) ); | ||
114 | } | ||
115 | |||
116 | bool Bu::TafGroup::hasChild( const Bu::String &sName ) const | ||
117 | { | ||
118 | return hChildren.has( sName ); | ||
119 | } | ||
120 | |||
121 | const Bu::TafGroup::GroupList &Bu::TafGroup::getChildren( const Bu::String &sName ) const | ||
122 | { | ||
123 | try { | ||
124 | return hChildren.get( sName ); | ||
125 | } catch( Bu::HashException &e ) | ||
126 | { | ||
127 | throw Bu::TafException("No children of group \"%s\" match \"%s\".", | ||
128 | this->sName.getStr(), sName.getStr() ); | ||
129 | } | ||
130 | } | ||
131 | |||
132 | const Bu::TafGroup::NodeList &Bu::TafGroup::getChildren() const | ||
133 | { | ||
134 | return lChildren; | ||
135 | } | ||
136 | |||
137 | const Bu::TafGroup *Bu::TafGroup::getChild( const Bu::String &sName ) const | ||
138 | { | ||
139 | try { | ||
140 | return hChildren.get( sName ).first(); | ||
141 | } catch( Bu::HashException &e ) | ||
142 | { | ||
143 | throw Bu::TafException("No children of group \"%s\" match \"%s\".", | ||
144 | this->sName.getStr(), sName.getStr() ); | ||
145 | } | ||
146 | } | ||
147 | |||
148 | bool Bu::TafGroup::hasProperty( const Bu::String &sName ) const | ||
149 | { | ||
150 | return hProp.has( sName ); | ||
151 | } | ||
152 | |||
153 | const Bu::TafGroup::PropList &Bu::TafGroup::getProperties( const Bu::String &sName ) const | ||
154 | { | ||
155 | try { | ||
156 | return hProp.get( sName ); | ||
157 | } catch( Bu::HashException &e ) | ||
158 | { | ||
159 | throw Bu::TafException("No properties of group \"%s\" match \"%s\".", | ||
160 | this->sName.getStr(), sName.getStr() ); | ||
161 | } | ||
162 | } | ||
163 | |||
164 | const Bu::String &Bu::TafGroup::getProperty( const Bu::String &sName ) const | ||
165 | { | ||
166 | try { | ||
167 | return hProp.get( sName ).first(); | ||
168 | } catch( Bu::HashException &e ) | ||
169 | { | ||
170 | throw Bu::TafException("No properties of group \"%s\" match \"%s\".", | ||
171 | this->sName.getStr(), sName.getStr() ); | ||
172 | } | ||
173 | } | ||
174 | |||
175 | const Bu::String &Bu::TafGroup::getProperty( const Bu::String &sName, | ||
176 | const Bu::String &sDef ) const | ||
177 | { | ||
178 | try | ||
179 | { | ||
180 | return hProp.get( sName ).first(); | ||
181 | } | ||
182 | catch( Bu::HashException &e ) | ||
183 | { | ||
184 | return sDef; | ||
185 | } | ||
186 | } | ||
187 | |||
188 | const Bu::TafGroup *Bu::TafGroup::getChildByPath( | ||
189 | const Bu::String &sPath ) const | ||
190 | { | ||
191 | return getChildByPath( sPath.split('/') ); | ||
192 | } | ||
193 | |||
194 | const Bu::TafGroup *Bu::TafGroup::getChildByPath( Bu::StrList lPath ) const | ||
195 | { | ||
196 | const Bu::TafGroup *cur = this; | ||
197 | |||
198 | for( Bu::StrList::const_iterator i = lPath.begin(); i; i++ ) | ||
199 | { | ||
200 | cur = cur->getChild( *i ); | ||
201 | } | ||
202 | |||
203 | return cur; | ||
204 | } | ||
205 | |||
206 | const Bu::String &Bu::TafGroup::getByPath( const Bu::String &sPath ) const | ||
207 | { | ||
208 | return getByPath( sPath.split('/') ); | ||
209 | } | ||
210 | |||
211 | const Bu::String &Bu::TafGroup::getByPath( Bu::StrList lPath ) const | ||
212 | { | ||
213 | const Bu::TafGroup *cur = this; | ||
214 | |||
215 | for( Bu::StrList::const_iterator i = lPath.begin(); i; i++ ) | ||
216 | { | ||
217 | if( !(i+1) ) | ||
218 | break; | ||
219 | cur = cur->getChild( *i ); | ||
220 | } | ||
221 | |||
222 | return cur->getProperty( lPath.last() ); | ||
223 | } | ||
224 | |||