diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/dictionary.cpp | 57 | ||||
| -rw-r--r-- | src/dictionary.h | 8 | ||||
| -rw-r--r-- | src/list.cpp | 89 | ||||
| -rw-r--r-- | src/list.h | 20 |
4 files changed, 166 insertions, 8 deletions
diff --git a/src/dictionary.cpp b/src/dictionary.cpp index aaba7b8..9728804 100644 --- a/src/dictionary.cpp +++ b/src/dictionary.cpp | |||
| @@ -168,6 +168,63 @@ void Gats::Dictionary::insert( const Bu::String &sKey, const Bu::String &s ) | |||
| 168 | ); | 168 | ); |
| 169 | } | 169 | } |
| 170 | 170 | ||
| 171 | void Gats::Dictionary::insertBool( const Bu::String &sKey, bool b ) | ||
| 172 | { | ||
| 173 | Bu::Hash<Gats::String, Gats::Object *>::insert( | ||
| 174 | sKey, new Gats::Boolean( b ) | ||
| 175 | ); | ||
| 176 | } | ||
| 177 | |||
| 178 | void Gats::Dictionary::insertInt( const Bu::String &sKey, int64_t i ) | ||
| 179 | { | ||
| 180 | Bu::Hash<Gats::String, Gats::Object *>::insert( | ||
| 181 | sKey, new Gats::Integer( i ) | ||
| 182 | ); | ||
| 183 | } | ||
| 184 | |||
| 185 | void Gats::Dictionary::insertFloat( const Bu::String &sKey, double d ) | ||
| 186 | { | ||
| 187 | Bu::Hash<Gats::String, Gats::Object *>::insert( | ||
| 188 | sKey, new Gats::Float( d ) | ||
| 189 | ); | ||
| 190 | } | ||
| 191 | |||
| 192 | void Gats::Dictionary::insertStr( const Bu::String &sKey, const Bu::String &s ) | ||
| 193 | { | ||
| 194 | Bu::Hash<Gats::String, Gats::Object *>::insert( | ||
| 195 | sKey, new Gats::String( s ) | ||
| 196 | ); | ||
| 197 | } | ||
| 198 | |||
| 199 | void Gats::Dictionary::insertList( const Bu::String &sKey, Gats::List *pL ) | ||
| 200 | { | ||
| 201 | Bu::Hash<Gats::String, Gats::Object *>::insert( | ||
| 202 | sKey, pL | ||
| 203 | ); | ||
| 204 | } | ||
| 205 | |||
| 206 | void Gats::Dictionary::insertDict( const Bu::String &sKey, | ||
| 207 | Gats::Dictionary *pD ) | ||
| 208 | { | ||
| 209 | Bu::Hash<Gats::String, Gats::Object *>::insert( | ||
| 210 | sKey, pD | ||
| 211 | ); | ||
| 212 | } | ||
| 213 | |||
| 214 | Gats::List *Gats::Dictionary::insertList( const Bu::String &sKey ) | ||
| 215 | { | ||
| 216 | Gats::List *pLst = new Gats::List(); | ||
| 217 | insertList( sKey, pLst ); | ||
| 218 | return pLst; | ||
| 219 | } | ||
| 220 | |||
| 221 | Gats::Dictionary *Gats::Dictionary::insertDict( const Bu::String &sKey ) | ||
| 222 | { | ||
| 223 | Gats::Dictionary *pDict = new Gats::Dictionary(); | ||
| 224 | insertDict( sKey, pDict ); | ||
| 225 | return pDict; | ||
| 226 | } | ||
| 227 | |||
| 171 | bool Gats::Dictionary::getBool( const Bu::String &sKey ) | 228 | bool Gats::Dictionary::getBool( const Bu::String &sKey ) |
| 172 | { | 229 | { |
| 173 | Gats::Boolean *pOb = dynamic_cast<Gats::Boolean *>( get( sKey ) ); | 230 | Gats::Boolean *pOb = dynamic_cast<Gats::Boolean *>( get( sKey ) ); |
diff --git a/src/dictionary.h b/src/dictionary.h index d421720..cde51be 100644 --- a/src/dictionary.h +++ b/src/dictionary.h | |||
| @@ -37,6 +37,14 @@ namespace Gats | |||
| 37 | void insert( const Bu::String &sKey, float d ); | 37 | void insert( const Bu::String &sKey, float d ); |
| 38 | void insert( const Bu::String &sKey, double d ); | 38 | void insert( const Bu::String &sKey, double d ); |
| 39 | using Bu::Hash<Gats::String, Gats::Object *>::insert; | 39 | using Bu::Hash<Gats::String, Gats::Object *>::insert; |
| 40 | void insertBool( const Bu::String &sKey, bool b ); | ||
| 41 | void insertInt( const Bu::String &sKey, int64_t i ); | ||
| 42 | void insertFloat( const Bu::String &sKey, double d ); | ||
| 43 | void insertStr( const Bu::String &sKey, const Bu::String &s ); | ||
| 44 | void insertList( const Bu::String &sKey, Gats::List *pL ); | ||
| 45 | void insertDict( const Bu::String &sKey, Gats::Dictionary *pD ); | ||
| 46 | Gats::List *insertList( const Bu::String &sKey ); | ||
| 47 | Gats::Dictionary *insertDict( const Bu::String &sKey ); | ||
| 40 | 48 | ||
| 41 | bool getBool( const Bu::String &sKey ); | 49 | bool getBool( const Bu::String &sKey ); |
| 42 | int64_t getInt( const Bu::String &sKey ); | 50 | int64_t getInt( const Bu::String &sKey ); |
diff --git a/src/list.cpp b/src/list.cpp index 02e2a8d..3e871d6 100644 --- a/src/list.cpp +++ b/src/list.cpp | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | #include "gats/integer.h" | 4 | #include "gats/integer.h" |
| 5 | #include "gats/float.h" | 5 | #include "gats/float.h" |
| 6 | #include "gats/boolean.h" | 6 | #include "gats/boolean.h" |
| 7 | #include "gats/dictionary.h" | ||
| 7 | 8 | ||
| 8 | #include <bu/formatter.h> | 9 | #include <bu/formatter.h> |
| 9 | #include <bu/stream.h> | 10 | #include <bu/stream.h> |
| @@ -57,16 +58,54 @@ void Gats::List::append( int64_t i ) | |||
| 57 | Bu::List<Gats::Object *>::append( new Gats::Integer( i ) ); | 58 | Bu::List<Gats::Object *>::append( new Gats::Integer( i ) ); |
| 58 | } | 59 | } |
| 59 | 60 | ||
| 60 | void Gats::List::append( bool b ) | 61 | void Gats::List::append( double d ) |
| 61 | { | 62 | { |
| 62 | Bu::List<Gats::Object *>::append( new Gats::Boolean( b ) ); | 63 | Bu::List<Gats::Object *>::append( new Gats::Float( d ) ); |
| 63 | } | 64 | } |
| 64 | 65 | ||
| 65 | void Gats::List::append( double d ) | 66 | void Gats::List::appendStr( const Bu::String &s ) |
| 67 | { | ||
| 68 | Bu::List<Gats::Object *>::append( new Gats::String( s ) ); | ||
| 69 | } | ||
| 70 | |||
| 71 | void Gats::List::appendInt( int64_t i ) | ||
| 72 | { | ||
| 73 | Bu::List<Gats::Object *>::append( new Gats::Integer( i ) ); | ||
| 74 | } | ||
| 75 | |||
| 76 | void Gats::List::appendFloat( double d ) | ||
| 66 | { | 77 | { |
| 67 | Bu::List<Gats::Object *>::append( new Gats::Float( d ) ); | 78 | Bu::List<Gats::Object *>::append( new Gats::Float( d ) ); |
| 68 | } | 79 | } |
| 69 | 80 | ||
| 81 | void Gats::List::appendBool( bool b ) | ||
| 82 | { | ||
| 83 | Bu::List<Gats::Object *>::append( new Gats::Boolean( b ) ); | ||
| 84 | } | ||
| 85 | |||
| 86 | void Gats::List::appendList( Gats::List *pL ) | ||
| 87 | { | ||
| 88 | Bu::List<Gats::Object *>::append( pL ); | ||
| 89 | } | ||
| 90 | |||
| 91 | void Gats::List::appendDict( Gats::Dictionary *pD ) | ||
| 92 | { | ||
| 93 | Bu::List<Gats::Object *>::append( pD ); | ||
| 94 | } | ||
| 95 | |||
| 96 | Gats::List *Gats::List::appendList() | ||
| 97 | { | ||
| 98 | Gats::List *pLst = new Gats::List(); | ||
| 99 | appendList( pLst ); | ||
| 100 | return pLst; | ||
| 101 | } | ||
| 102 | |||
| 103 | Gats::Dictionary *Gats::List::appendDict() | ||
| 104 | { | ||
| 105 | Gats::Dictionary *pDict = new Gats::Dictionary(); | ||
| 106 | appendDict( pDict ); | ||
| 107 | return pDict; | ||
| 108 | } | ||
| 70 | 109 | ||
| 71 | void Gats::List::prepend( const char *s ) | 110 | void Gats::List::prepend( const char *s ) |
| 72 | { | 111 | { |
| @@ -88,16 +127,54 @@ void Gats::List::prepend( int64_t i ) | |||
| 88 | Bu::List<Gats::Object *>::prepend( new Gats::Integer( i ) ); | 127 | Bu::List<Gats::Object *>::prepend( new Gats::Integer( i ) ); |
| 89 | } | 128 | } |
| 90 | 129 | ||
| 91 | void Gats::List::prepend( bool b ) | 130 | void Gats::List::prepend( double d ) |
| 92 | { | 131 | { |
| 93 | Bu::List<Gats::Object *>::prepend( new Gats::Boolean( b ) ); | 132 | Bu::List<Gats::Object *>::prepend( new Gats::Float( d ) ); |
| 94 | } | 133 | } |
| 95 | 134 | ||
| 96 | void Gats::List::prepend( double d ) | 135 | void Gats::List::prependStr( const Bu::String &s ) |
| 136 | { | ||
| 137 | Bu::List<Gats::Object *>::prepend( new Gats::String( s ) ); | ||
| 138 | } | ||
| 139 | |||
| 140 | void Gats::List::prependInt( int64_t i ) | ||
| 141 | { | ||
| 142 | Bu::List<Gats::Object *>::prepend( new Gats::Integer( i ) ); | ||
| 143 | } | ||
| 144 | |||
| 145 | void Gats::List::prependFloat( double d ) | ||
| 97 | { | 146 | { |
| 98 | Bu::List<Gats::Object *>::prepend( new Gats::Float( d ) ); | 147 | Bu::List<Gats::Object *>::prepend( new Gats::Float( d ) ); |
| 99 | } | 148 | } |
| 100 | 149 | ||
| 150 | void Gats::List::prependBool( bool b ) | ||
| 151 | { | ||
| 152 | Bu::List<Gats::Object *>::prepend( new Gats::Boolean( b ) ); | ||
| 153 | } | ||
| 154 | |||
| 155 | void Gats::List::prependList( Gats::List *pL ) | ||
| 156 | { | ||
| 157 | Bu::List<Gats::Object *>::prepend( pL ); | ||
| 158 | } | ||
| 159 | |||
| 160 | void Gats::List::prependDict( Gats::Dictionary *pD ) | ||
| 161 | { | ||
| 162 | Bu::List<Gats::Object *>::prepend( pD ); | ||
| 163 | } | ||
| 164 | |||
| 165 | Gats::List *Gats::List::prependList() | ||
| 166 | { | ||
| 167 | Gats::List *pLst = new Gats::List(); | ||
| 168 | prependList( pLst ); | ||
| 169 | return pLst; | ||
| 170 | } | ||
| 171 | |||
| 172 | Gats::Dictionary *Gats::List::prependDict() | ||
| 173 | { | ||
| 174 | Gats::Dictionary *pDict = new Gats::Dictionary(); | ||
| 175 | prependDict( pDict ); | ||
| 176 | return pDict; | ||
| 177 | } | ||
| 101 | 178 | ||
| 102 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::List &l ) | 179 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::List &l ) |
| 103 | { | 180 | { |
| @@ -7,6 +7,8 @@ | |||
| 7 | 7 | ||
| 8 | namespace Gats | 8 | namespace Gats |
| 9 | { | 9 | { |
| 10 | class Dictionary; | ||
| 11 | |||
| 10 | class List : public Gats::Object, public Bu::List<Gats::Object *> | 12 | class List : public Gats::Object, public Bu::List<Gats::Object *> |
| 11 | { | 13 | { |
| 12 | public: | 14 | public: |
| @@ -22,17 +24,31 @@ namespace Gats | |||
| 22 | void append( const Bu::String &s ); | 24 | void append( const Bu::String &s ); |
| 23 | void append( int32_t i ); | 25 | void append( int32_t i ); |
| 24 | void append( int64_t i ); | 26 | void append( int64_t i ); |
| 25 | void append( bool b ); | ||
| 26 | void append( double d ); | 27 | void append( double d ); |
| 27 | using Bu::List<Gats::Object *>::append; | 28 | using Bu::List<Gats::Object *>::append; |
| 29 | void appendStr( const Bu::String &s ); | ||
| 30 | void appendInt( int64_t i ); | ||
| 31 | void appendFloat( double d ); | ||
| 32 | void appendBool( bool b ); | ||
| 33 | void appendList( Gats::List *pL ); | ||
| 34 | void appendDict( Gats::Dictionary *pD ); | ||
| 35 | Gats::List *appendList(); | ||
| 36 | Gats::Dictionary *appendDict(); | ||
| 28 | 37 | ||
| 29 | void prepend( const char *s ); | 38 | void prepend( const char *s ); |
| 30 | void prepend( const Bu::String &s ); | 39 | void prepend( const Bu::String &s ); |
| 31 | void prepend( int32_t i ); | 40 | void prepend( int32_t i ); |
| 32 | void prepend( int64_t i ); | 41 | void prepend( int64_t i ); |
| 33 | void prepend( bool b ); | ||
| 34 | void prepend( double d ); | 42 | void prepend( double d ); |
| 35 | using Bu::List<Gats::Object *>::prepend; | 43 | using Bu::List<Gats::Object *>::prepend; |
| 44 | void prependStr( const Bu::String &s ); | ||
| 45 | void prependInt( int64_t i ); | ||
| 46 | void prependFloat( double d ); | ||
| 47 | void prependBool( bool b ); | ||
| 48 | void prependList( Gats::List *pL ); | ||
| 49 | void prependDict( Gats::Dictionary *pD ); | ||
| 50 | Gats::List *prependList(); | ||
| 51 | Gats::Dictionary *prependDict(); | ||
| 36 | }; | 52 | }; |
| 37 | }; | 53 | }; |
| 38 | 54 | ||
