00001
00032 #ifndef LL_LLSD_NEW_H
00033 #define LL_LLSD_NEW_H
00034
00035 #include <map>
00036 #include <string>
00037 #include <vector>
00038
00039 #include "stdtypes.h"
00040
00041 #include "lldate.h"
00042 #include "lluri.h"
00043 #include "../llmath/lluuid.h"
00044
00091 class LLSD
00092 {
00093 public:
00094 LLSD();
00095 ~LLSD();
00096
00099 LLSD(const LLSD&);
00100 void assign(const LLSD& other);
00101 LLSD& operator=(const LLSD& other) { assign(other); return *this; }
00102
00104
00105 void clear();
00106
00107
00112 typedef bool Boolean;
00113 typedef S32 Integer;
00114 typedef F64 Real;
00115 typedef std::string String;
00116 typedef LLUUID UUID;
00117 typedef LLDate Date;
00118 typedef LLURI URI;
00119 typedef std::vector<U8> Binary;
00121
00124 LLSD(Boolean);
00125 LLSD(Integer);
00126 LLSD(Real);
00127 LLSD(const String&);
00128 LLSD(const UUID&);
00129 LLSD(const Date&);
00130 LLSD(const URI&);
00131 LLSD(const Binary&);
00133
00136 LLSD(F32);
00138
00141 void assign(Boolean);
00142 void assign(Integer);
00143 void assign(Real);
00144 void assign(const String&);
00145 void assign(const UUID&);
00146 void assign(const Date&);
00147 void assign(const URI&);
00148 void assign(const Binary&);
00149
00150 LLSD& operator=(Boolean v) { assign(v); return *this; }
00151 LLSD& operator=(Integer v) { assign(v); return *this; }
00152 LLSD& operator=(Real v) { assign(v); return *this; }
00153 LLSD& operator=(const String& v) { assign(v); return *this; }
00154 LLSD& operator=(const UUID& v) { assign(v); return *this; }
00155 LLSD& operator=(const Date& v) { assign(v); return *this; }
00156 LLSD& operator=(const URI& v) { assign(v); return *this; }
00157 LLSD& operator=(const Binary& v) { assign(v); return *this; }
00159
00186 Boolean asBoolean() const;
00187 Integer asInteger() const;
00188 Real asReal() const;
00189 String asString() const;
00190 UUID asUUID() const;
00191 Date asDate() const;
00192 URI asURI() const;
00193 Binary asBinary() const;
00194
00195 operator Boolean() const { return asBoolean(); }
00196 operator Integer() const { return asInteger(); }
00197 operator Real() const { return asReal(); }
00198 operator String() const { return asString(); }
00199 operator UUID() const { return asUUID(); }
00200 operator Date() const { return asDate(); }
00201 operator URI() const { return asURI(); }
00202 operator Binary() const { return asBinary(); }
00203
00204
00205
00206 bool operator!() const {return !asBoolean();}
00208
00214 LLSD(const char*);
00215 void assign(const char*);
00216 LLSD& operator=(const char* v) { assign(v); return *this; }
00218
00221 static LLSD emptyMap();
00222
00223 bool has(const String&) const;
00224 LLSD get(const String&) const;
00225 void insert(const String&, const LLSD&);
00226 void erase(const String&);
00227
00228 LLSD& operator[](const String&);
00229 LLSD& operator[](const char* c) { return (*this)[String(c)]; }
00230 const LLSD& operator[](const String&) const;
00231 const LLSD& operator[](const char* c) const { return (*this)[String(c)]; }
00233
00236 static LLSD emptyArray();
00237
00238 LLSD get(Integer) const;
00239 void set(Integer, const LLSD&);
00240 void insert(Integer, const LLSD&);
00241 void append(const LLSD&);
00242 void erase(Integer);
00243
00244 const LLSD& operator[](Integer) const;
00245 LLSD& operator[](Integer);
00247
00250 int size() const;
00251
00252 typedef std::map<String, LLSD>::iterator map_iterator;
00253 typedef std::map<String, LLSD>::const_iterator map_const_iterator;
00254
00255 map_iterator beginMap();
00256 map_iterator endMap();
00257 map_const_iterator beginMap() const;
00258 map_const_iterator endMap() const;
00259
00260 typedef std::vector<LLSD>::iterator array_iterator;
00261 typedef std::vector<LLSD>::const_iterator array_const_iterator;
00262
00263 array_iterator beginArray();
00264 array_iterator endArray();
00265 array_const_iterator beginArray() const;
00266 array_const_iterator endArray() const;
00268
00271 enum Type {
00272 TypeUndefined,
00273 TypeBoolean,
00274 TypeInteger,
00275 TypeReal,
00276 TypeString,
00277 TypeUUID,
00278 TypeDate,
00279 TypeURI,
00280 TypeBinary,
00281 TypeMap,
00282 TypeArray
00283 };
00284
00285 Type type() const;
00286
00287 bool isUndefined() const { return type() == TypeUndefined; }
00288 bool isDefined() const { return type() != TypeUndefined; }
00289 bool isBoolean() const { return type() == TypeBoolean; }
00290 bool isInteger() const { return type() == TypeInteger; }
00291 bool isReal() const { return type() == TypeReal; }
00292 bool isString() const { return type() == TypeString; }
00293 bool isUUID() const { return type() == TypeUUID; }
00294 bool isDate() const { return type() == TypeDate; }
00295 bool isURI() const { return type() == TypeURI; }
00296 bool isBinary() const { return type() == TypeBinary; }
00297 bool isMap() const { return type() == TypeMap; }
00298 bool isArray() const { return type() == TypeArray; }
00300
00313 LLSD(const void*);
00314 void assign(const void*);
00315 LLSD& operator=(const void*);
00316
00317 bool has(Integer) const;
00318
00319
00322 public:
00323 class Impl;
00324 private:
00325 Impl* impl;
00327
00330 public:
00331 static U32 allocationCount();
00332 static U32 outstandingCount();
00333
00334 };
00335
00336 struct llsd_select_bool : public std::unary_function<LLSD, LLSD::Boolean>
00337 {
00338 LLSD::Boolean operator()(const LLSD& sd) const
00339 {
00340 return sd.asBoolean();
00341 }
00342 };
00343 struct llsd_select_integer : public std::unary_function<LLSD, LLSD::Integer>
00344 {
00345 LLSD::Integer operator()(const LLSD& sd) const
00346 {
00347 return sd.asInteger();
00348 }
00349 };
00350 struct llsd_select_real : public std::unary_function<LLSD, LLSD::Real>
00351 {
00352 LLSD::Real operator()(const LLSD& sd) const
00353 {
00354 return sd.asReal();
00355 }
00356 };
00357 struct llsd_select_float : public std::unary_function<LLSD, F32>
00358 {
00359 F32 operator()(const LLSD& sd) const
00360 {
00361 return (F32)sd.asReal();
00362 }
00363 };
00364 struct llsd_select_uuid : public std::unary_function<LLSD, LLSD::UUID>
00365 {
00366 LLSD::UUID operator()(const LLSD& sd) const
00367 {
00368 return sd.asUUID();
00369 }
00370 };
00371 struct llsd_select_string : public std::unary_function<LLSD, LLSD::String>
00372 {
00373 LLSD::String operator()(const LLSD& sd) const
00374 {
00375 return sd.asString();
00376 }
00377 };
00378
00379
00389 #endif // LL_LLSD_NEW_H