aboutsummaryrefslogtreecommitdiff
path: root/src/dictionary.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/dictionary.cpp64
1 files changed, 62 insertions, 2 deletions
diff --git a/src/dictionary.cpp b/src/dictionary.cpp
index b789bbf..29bbd4e 100644
--- a/src/dictionary.cpp
+++ b/src/dictionary.cpp
@@ -70,12 +70,12 @@ void Gats::Dictionary::insert( const Bu::FString &sKey, int64_t i )
70 ); 70 );
71} 71}
72 72
73void Gats::Dictionary::insert( const Bu::FString &sKey, bool b ) 73/*void Gats::Dictionary::insert( const Bu::FString &sKey, bool b )
74{ 74{
75 Bu::Hash<Gats::String, Gats::Object *>::insert( 75 Bu::Hash<Gats::String, Gats::Object *>::insert(
76 sKey, new Gats::Boolean( b ) 76 sKey, new Gats::Boolean( b )
77 ); 77 );
78} 78}*/
79 79
80void Gats::Dictionary::insert( const Bu::FString &sKey, double d ) 80void Gats::Dictionary::insert( const Bu::FString &sKey, double d )
81{ 81{
@@ -158,6 +158,66 @@ Gats::Dictionary *Gats::Dictionary::getDict( const Bu::FString &sKey )
158 return pOb; 158 return pOb;
159} 159}
160 160
161bool Gats::Dictionary::getBool( const Bu::FString &sKey ) const
162{
163 Gats::Boolean *pOb = dynamic_cast<Gats::Boolean *>( get( sKey ) );
164 if( !pOb )
165 throw Bu::ExceptionBase("Cannot cast item '%s' to bool.",
166 sKey.getStr() );
167
168 return pOb->getValue();
169}
170
171int64_t Gats::Dictionary::getInt( const Bu::FString &sKey ) const
172{
173 Gats::Integer *pOb = dynamic_cast<Gats::Integer *>( get( sKey ) );
174 if( !pOb )
175 throw Bu::ExceptionBase("Cannot cast item '%s' to int.",
176 sKey.getStr() );
177
178 return pOb->getValue();
179}
180
181double Gats::Dictionary::getFloat( const Bu::FString &sKey ) const
182{
183 Gats::Boolean *pOb = dynamic_cast<Gats::Boolean *>( get( sKey ) );
184 if( pOb )
185 throw Bu::ExceptionBase("Cannot cast item '%s' to bool.",
186 sKey.getStr() );
187
188 return pOb->getValue();
189}
190
191Bu::FString Gats::Dictionary::getStr( const Bu::FString &sKey ) const
192{
193 Gats::String *pOb = dynamic_cast<Gats::String *>( get( sKey ) );
194 if( !pOb )
195 throw Bu::ExceptionBase("Cannot cast item '%s' to string.",
196 sKey.getStr() );
197
198 return *pOb;
199}
200
201Gats::List *Gats::Dictionary::getList( const Bu::FString &sKey ) const
202{
203 Gats::List *pOb = dynamic_cast<Gats::List *>( get( sKey ) );
204 if( !pOb )
205 throw Bu::ExceptionBase("Cannot cast item '%s' to list.",
206 sKey.getStr() );
207
208 return pOb;
209}
210
211Gats::Dictionary *Gats::Dictionary::getDict( const Bu::FString &sKey ) const
212{
213 Gats::Dictionary *pOb = dynamic_cast<Gats::Dictionary *>( get( sKey ) );
214 if( !pOb )
215 throw Bu::ExceptionBase("Cannot cast item '%s' to dictionary.",
216 sKey.getStr() );
217
218 return pOb;
219}
220
161Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Dictionary &d ) 221Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::Dictionary &d )
162{ 222{
163 f << "(dict) {"; 223 f << "(dict) {";