aboutsummaryrefslogtreecommitdiff
path: root/src/tafgroup.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2009-10-16 12:59:45 +0000
committerMike Buland <eichlan@xagasoft.com>2009-10-16 12:59:45 +0000
commit96b07a22f5392f5d7f821f5743deb3d64bd94e89 (patch)
treef8610916735e2bc5304031168f724cde7d909653 /src/tafgroup.cpp
parent835c3420326a3a3a94baa8690bf09941182d29b0 (diff)
downloadlibbu++-96b07a22f5392f5d7f821f5743deb3d64bd94e89.tar.gz
libbu++-96b07a22f5392f5d7f821f5743deb3d64bd94e89.tar.bz2
libbu++-96b07a22f5392f5d7f821f5743deb3d64bd94e89.tar.xz
libbu++-96b07a22f5392f5d7f821f5743deb3d64bd94e89.zip
Although this looks like a load of code changes, this represents no functional
change to the Taf system. Really all that's happened is I've broken out the core taf data types into seperate files, and gone ahead and created a helpful new header file ("taf.h") that will include the entire taf system, including the reader and writer for you. This means that a lot of programs will start complaining, but fortunately, there's an easy solution, if it complains about taf, make sure to include taf.h at the top, instead of other taf files and you'll be set. The next set of changes will add lots of helpers to the taf system and change the reader to read non-const structures, i.e. I'll actually add editing support to created taf structures.
Diffstat (limited to 'src/tafgroup.cpp')
-rw-r--r--src/tafgroup.cpp164
1 files changed, 164 insertions, 0 deletions
diff --git a/src/tafgroup.cpp b/src/tafgroup.cpp
new file mode 100644
index 0000000..1837bd8
--- /dev/null
+++ b/src/tafgroup.cpp
@@ -0,0 +1,164 @@
1/*
2 * Copyright (C) 2007-2008 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
12Bu::TafGroup::TafGroup( const Bu::FString &sName ) :
13 TafNode( typeGroup ),
14 sName( sName )
15{
16}
17
18Bu::TafGroup::~TafGroup()
19{
20 for( NodeList::iterator i = lChildren.begin(); i != lChildren.end(); i++ )
21 {
22 delete (*i);
23 }
24}
25
26const Bu::FString &Bu::TafGroup::getName() const
27{
28 return sName;
29}
30
31void Bu::TafGroup::setName( const Bu::FString &sName )
32{
33 this->sName = sName;
34}
35
36Bu::TafNode *Bu::TafGroup::addChild( Bu::TafNode *pNode )
37{
38 switch( pNode->getType() )
39 {
40 case typeGroup:
41 addChild( (Bu::TafGroup *)pNode );
42 break;
43
44 case typeProperty:
45 addChild( (Bu::TafProperty *)pNode );
46 break;
47
48 case typeComment:
49 addChild( (Bu::TafComment *)pNode );
50 break;
51 }
52
53 return pNode;
54}
55
56Bu::TafGroup *Bu::TafGroup::addChild( TafGroup *pNode )
57{
58 TafGroup *pGroup = (TafGroup *)pNode;
59 if( !hChildren.has( pGroup->getName() ) )
60 hChildren.insert( pGroup->getName(), GroupList() );
61 hChildren.get( pGroup->getName() ).append( pGroup );
62 lChildren.append( pNode );
63 return pNode;
64}
65
66Bu::TafProperty *Bu::TafGroup::addChild( TafProperty *pNode )
67{
68 TafProperty *pProperty = (TafProperty *)pNode;
69 if( !hProp.has( pProperty->getName() ) )
70 hProp.insert( pProperty->getName(), PropList() );
71 hProp.get( pProperty->getName() ).append( pProperty->getValue() );
72 lChildren.append( pNode );
73 return pNode;
74}
75
76Bu::TafComment *Bu::TafGroup::addChild( TafComment *pNode )
77{
78 lChildren.append( pNode );
79 return pNode;
80}
81
82Bu::TafGroup *Bu::TafGroup::addGroup( const Bu::FString &sName )
83{
84 return addChild( new TafGroup( sName ) );
85}
86
87Bu::TafProperty *Bu::TafGroup::addProperty(
88 const Bu::FString &sName, const Bu::FString &sValue )
89{
90 return addChild( new TafProperty( sName, sValue ) );
91}
92
93bool Bu::TafGroup::hasChild( const Bu::FString &sName ) const
94{
95 return hChildren.has( sName );
96}
97
98const Bu::TafGroup::GroupList &Bu::TafGroup::getChildren( const Bu::FString &sName ) const
99{
100 try {
101 return hChildren.get( sName );
102 } catch( Bu::HashException &e )
103 {
104 throw Bu::TafException("No children of group \"%s\" match \"%s\".",
105 this->sName.getStr(), sName.getStr() );
106 }
107}
108
109const Bu::TafGroup::NodeList &Bu::TafGroup::getChildren() const
110{
111 return lChildren;
112}
113
114const Bu::TafGroup *Bu::TafGroup::getChild( const Bu::FString &sName ) const
115{
116 try {
117 return hChildren.get( sName ).first();
118 } catch( Bu::HashException &e )
119 {
120 throw Bu::TafException("No children of group \"%s\" match \"%s\".",
121 this->sName.getStr(), sName.getStr() );
122 }
123}
124
125bool Bu::TafGroup::hasProperty( const Bu::FString &sName ) const
126{
127 return hProp.has( sName );
128}
129
130const Bu::TafGroup::PropList &Bu::TafGroup::getProperties( const Bu::FString &sName ) const
131{
132 try {
133 return hProp.get( sName );
134 } catch( Bu::HashException &e )
135 {
136 throw Bu::TafException("No properties of group \"%s\" match \"%s\".",
137 this->sName.getStr(), sName.getStr() );
138 }
139}
140
141const Bu::FString &Bu::TafGroup::getProperty( const Bu::FString &sName ) const
142{
143 try {
144 return hProp.get( sName ).first();
145 } catch( Bu::HashException &e )
146 {
147 throw Bu::TafException("No properties of group \"%s\" match \"%s\".",
148 this->sName.getStr(), sName.getStr() );
149 }
150}
151
152const Bu::FString &Bu::TafGroup::getProperty( const Bu::FString &sName,
153 const Bu::FString &sDef ) const
154{
155 try
156 {
157 return hProp.get( sName ).first();
158 }
159 catch( Bu::HashException &e )
160 {
161 return sDef;
162 }
163}
164