23 #ifndef __ccxx_Variant_hxx 24 #define __ccxx_Variant_hxx 30 #include <sys/types.h> 123 explicit Variant(uint32_t val);
137 explicit Variant(
const double& val);
144 explicit Variant(
const int64_t& val);
151 explicit Variant(
const uint64_t& val);
165 explicit Variant(
const char* val);
201 void setType(
Type type);
205 {
return(_type == TypeNull); }
209 {
return(_type == TypeBool); }
213 {
return(_type == TypeChar); }
217 {
return(_type == TypeChar16); }
221 {
return(_type == TypeInt); }
225 {
return(_type == TypeUInt); }
229 {
return(_type == TypeFloat); }
233 {
return(_type == TypeDouble); }
237 {
return(_type == TypeInt64); }
241 {
return(_type == TypeUInt64); }
245 {
return(_type == TypeString); }
249 {
return(_type == TypeBlob); }
253 {
return(_type == TypeOpaque); }
257 {
return(_type == TypeList); }
261 {
return(_type == TypeMap); }
289 int32_t toInt()
const;
296 uint32_t toUInt()
const;
303 float toFloat()
const;
310 double toDouble()
const;
317 int64_t toInt64()
const;
324 uint64_t toUInt64()
const;
330 void* toOpaque()
const;
347 inline operator bool()
const 348 {
return(toBool()); }
351 inline operator char()
const 352 {
return(toChar()); }
356 {
return(toChar16()); }
359 inline operator int32_t()
const 363 inline operator uint32_t()
const 364 {
return(toUInt()); }
367 inline operator float()
const 368 {
return(toFloat()); }
371 inline operator double()
const 372 {
return(toDouble()); }
376 {
return(toString()); }
380 {
return(toBlob()); }
383 inline operator int64_t()
const 384 {
return(toInt64()); }
387 inline operator uint64_t()
const 388 {
return(toUInt64()); }
394 inline operator const void*()
const 395 {
return(isNull() ? NULL :
this); }
399 {
return(isNull()); }
427 Variant& operator=(int32_t val);
430 Variant& operator=(uint32_t val);
436 Variant& operator=(
const double& val);
439 Variant& operator=(
const int64_t& val);
442 Variant& operator=(
const uint64_t& val);
449 {
return(
operator=(
String(val))); }
483 {
return(
operator[](
String(name))); }
504 {
return(
get(name)); }
515 {
return(
get(
String(name))); }
529 Variant& operator[](
int index);
540 const Variant &
get(
int index)
const;
552 {
return(
get(index)); }
570 bool hasKey(
const String& key)
const;
577 {
return(!
operator==(other)); }
584 void write(std::ostream &stream)
const;
594 void _copy(
const Variant& other);
632 #endif // __ccxx_Variant_hxx bool isDouble() const
Test if the Variant's value is a double.
Definition: Variant.h++:232
double value
Definition: Variant.h++:67
char16_t char16Val
Definition: Variant.h++:603
String value.
Definition: Variant.h++:73
unsigned int value
Definition: Variant.h++:63
float floatVal
Definition: Variant.h++:606
const Variant & operator[](int index) const
Return the value at the given index from this Variant, whose value is assumed to be a list...
Definition: Variant.h++:551
list value
Definition: Variant.h++:79
bool isChar16() const
Test if the Variant's value is a char16_t.
Definition: Variant.h++:216
A String vector.
Definition: String.h++:1159
Type getType() const
Get the type of this Variant.
Definition: Variant.h++:192
VariantMap * mapVal
Definition: Variant.h++:613
char16_t value
Definition: Variant.h++:59
opaque pointer value
Definition: Variant.h++:77
bool isString() const
Test if the Variant's value is a String.
Definition: Variant.h++:244
void write(std::ostream &stream) const
Write the value of this Variant to a stream.
Definition: Variant.c++:1255
bool isMap() const
Test if the Variant's value is a map.
Definition: Variant.h++:260
bool operator==(const Blob &b1, const Blob &b2)
Definition: Blob.h++:344
int64_t int64Val
Definition: Variant.h++:608
unsigned int uint_t
An alias for unsigned int.
Definition: Integers.h++:74
bool boolVal
Definition: Variant.h++:601
void * opaqueVal
Definition: Variant.h++:614
bool isFloat() const
Test if the Variant's value is a float.
Definition: Variant.h++:228
VariantList * listVal
Definition: Variant.h++:612
bool operator!=(const Variant &other) const
Inequality operator.
Definition: Variant.h++:576
Blob value.
Definition: Variant.h++:75
String * stringVal
Definition: Variant.h++:610
const Variant & operator[](const String &name) const
Return the value for the given name from this Variant, whose value is assumed to be a map...
Definition: Variant.h++:503
Blob * blobVal
Definition: Variant.h++:611
bool operator!() const
Equivalent to isNull().
Definition: Variant.h++:398
char value
Definition: Variant.h++:57
uint64_t uint64Val
Definition: Variant.h++:609
std::ostream & operator<<(std::ostream &stream, const BitSet &bs)
Definition: BitSet.h++:383
const Variant & operator[](const char *name) const
Return the value for the given name from this Variant, whose value is assumed to be a map...
Definition: Variant.h++:514
bool isBool() const
Test if the Variant's value is a bool.
Definition: Variant.h++:208
int32_t intVal
Definition: Variant.h++:604
A general-purpose variant type.
Definition: Variant.h++:46
#define COMMONCPP_API
Definition: Common.h++:126
int value
Definition: Variant.h++:61
A reference-counting, copy-on-write, threadsafe container for arbitrary binary data.
Definition: Blob.h++:45
64-bit unsigned int value
Definition: Variant.h++:71
static const Variant null
A null Variant.
Definition: Variant.h++:587
A flexible, reference counted, copy-on-write, thread-safe, nullable string.
Definition: String.h++:50
bool isList() const
Test if the Variant's value is a list.
Definition: Variant.h++:256
char charVal
Definition: Variant.h++:602
bool isBlob() const
Test if the Variant's value is a Blob.
Definition: Variant.h++:248
Variant & operator[](const char *name)
Return the value for the given name from this Variant, whose value is assumed to be a map...
Definition: Variant.h++:482
bool isInt64() const
Test if the Variant's value is an int64_t.
Definition: Variant.h++:236
bool isChar() const
Test if the Variant's value is a char.
Definition: Variant.h++:212
uint16_t char16_t
A UTF-16 character.
Definition: Common.h++:201
float value
Definition: Variant.h++:65
64-bit int value
Definition: Variant.h++:69
double doubleVal
Definition: Variant.h++:607
uint32_t uintVal
Definition: Variant.h++:605
bool isNull() const
Test if the Variant is null.
Definition: Variant.h++:204
bool value
Definition: Variant.h++:55
bool isOpaque() const
Test if the Variant's value is opaque.
Definition: Variant.h++:252
Definition: AllocationMap.c++:25
bool isUInt64() const
Test if the Variant's value is a uint64_t.
Definition: Variant.h++:240
Variant & operator=(const char *val)
Assign a string value to the Variant.
Definition: Variant.h++:448
bool isUInt() const
Test if the Variant's value is a uint32_t.
Definition: Variant.h++:224
bool isInt() const
Test if the Variant's value is an int32_t.
Definition: Variant.h++:220
Type
Variant value types.
Definition: Variant.h++:51