16 #if defined(EVO_CPP11) 17 #include <initializer_list> 175 #if defined(EVO_CPP11) 179 Var(std::initializer_list<Var> init) : type_(
tNULL) {
181 ListType& items =
list();
183 for (
const auto& val : init)
194 memcpy(
buf_obj_, src.buf_obj_,
sizeof(ObjectType));
197 memcpy(
buf_list_, src.buf_list_,
sizeof(ListType));
229 memcpy(
buf_obj_, src.buf_obj_,
sizeof(ObjectType));
232 memcpy(
buf_list_, src.buf_list_,
sizeof(ListType));
268 const ObjectType* src_ptr = (
const ObjectType*)src.
buf_obj_;
273 const ListType* src_ptr = (
const ListType*)src.
buf_list_;
463 return (type_ ==
tLIST);
529 return (type_ ==
tBOOL);
541 const ObjectType* p = (
const ObjectType*)
buf_obj_;
545 const ListType* p = (
const ListType*)
buf_list_;
568 const ObjectType* p = (
const ObjectType*)
buf_obj_;
569 const ObjectType& obj = *p;
573 if (iter->key().shared() || iter->value().shared_scan())
578 const ListType* p = (
const ListType*)
buf_list_;
579 const ListType&
list = *p;
583 if (iter->shared_scan())
603 const ObjectType* p = (
const ObjectType*)
buf_obj_;
607 const ListType* p = (
const ListType*)
buf_list_;
630 const ObjectType* p = (
const ObjectType*)
buf_obj_;
634 const ListType* p = (
const ListType*)
buf_list_;
649 const ObjectType* p = (
const ObjectType*)
buf_obj_;
653 const ListType* p = (
const ListType*)
buf_list_;
679 ObjectType* p = (ObjectType*)
buf_obj_;
720 ObjectType* p = (ObjectType*)
buf_obj_;
750 ObjectType* p = (ObjectType*)
buf_obj_;
751 ObjectType& obj = *p;
790 const ObjectType* p = (ObjectType*)
buf_obj_;
809 if (type_ ==
tLIST) {
810 const ListType* l = (ListType*)
buf_list_;
811 if (l != NULL && index < l->
size())
812 return l->
item(index);
822 const ObjectType* p = (
const ObjectType*)
buf_obj_;
832 if (type_ ==
tLIST) {
833 const ListType* l = (
const ListType*)
buf_list_;
834 if (l != NULL && index < l->
size())
835 return &l->
item(index);
845 ObjectType* p = (ObjectType*)
buf_obj_;
846 return p->
findM(key);
855 if (type_ ==
tLIST) {
857 return &l->
itemM(index);
868 ObjectType* ptr = (ObjectType*)
buf_obj_;
897 ListType* ptr = (ListType*)
buf_obj_;
900 ObjectType* p = (ObjectType*)
buf_obj_;
929 ObjectType* p = (ObjectType*)
buf_obj_;
959 ObjectType* p = (ObjectType*)
buf_obj_;
1002 ObjectType* p = (ObjectType*)
buf_obj_;
1044 ObjectType* p = (ObjectType*)
buf_obj_;
1067 const double num = (double)
buf_int_;
1089 ObjectType* p = (ObjectType*)
buf_obj_;
1126 const ObjectType* p = (
const ObjectType*)
buf_obj_;
1134 const ListType* p = (
const ListType*)
buf_list_;
1159 val.
set(
"false", 5);
1174 static const ObjectType DEF;
1177 const ObjectType* p = (
const ObjectType*)
buf_obj_;
1187 if (type_ !=
tLIST) {
1188 static const ListType DEF;
1191 const ListType* p = (
const ListType*)
buf_list_;
1246 return p->
getnum<uint64>();
1272 return p->
getnum<int64>();
1323 const ObjectType* src_p = (
const ObjectType*)src.
buf_obj_;
1328 const ListType* src_p = (
const ListType*)src.
buf_list_;
1546 dump_impl(out, newline, indent);
1567 ObjectType* p = (ObjectType*)
buf_obj_;
1586 const Var& null_var()
const {
1587 static const Var NULL_VAR;
1592 void dump_val(T& out,
char end_delim)
const {
1611 out.writetext(
"true", 4);
1613 out.writetext(
"false", 5);
1616 out.writetext(
"null", 4);
1623 template<
class T,
class TNL>
1624 void dump_impl(T& out,
const TNL& newline, uint indent,
bool first=
true)
const {
1627 const ObjectType* p = (
const ObjectType*)
buf_obj_;
1628 const ObjectType& obj = *p;
1633 out <<
'{' << newline;
1642 out.writechar(
' ', indent);
1644 out.writequoted(key.
data(), key.
size(),
':',
true);
1649 val.dump_impl(out, newline, indent,
false);
1651 val.dump_val(out, delim);
1655 out <<
',' << newline;
1660 out.writechar(
' ', indent);
1666 const ListType* p = (
const ListType*)
buf_list_;
1667 const ListType&
list = *p;
1676 const Var& val = *iter;
1680 val.dump_impl(out, newline, indent,
false);
1682 val.dump_val(out, delim);
1703 #if defined(EVO_CPP11) 1725 InitPair(
const char* key,
const T& value) : key(key), value(value) {
1741 for (
const auto& val : init)
1742 map[val.key] = val.value;
Var & operator=(ushort val)
Assignment operator to set as unsigned integer value (ushort).
Definition: var.h:1427
Var & operator=(const Var &src)
Assignment copy operator.
Definition: var.h:1318
Size size() const
Get size.
Definition: list.h:759
const Var * child(Size index) const
Find child in list using index (const).
Definition: var.h:831
Var(uint val)
Constructor to initialize as unsigned integer value (uint).
Definition: var.h:363
Var * childM(const StringBase &key)
Find child in object using key (mutable).
Definition: var.h:843
double buf_float_
Definition: var.h:1558
Var & operator[](const StringBase &key)
Object field access operator.
Definition: var.h:1519
Integer value (unsigned)
Definition: var.h:169
bool buf_bool_
Definition: var.h:1561
bool is_signed() const
Get whether a signed integer number type (tINTEGER).
Definition: var.h:521
Var & operator=(Var &&src)
Move assignment operator (C++11).
Definition: var.h:224
Holds a Newline value that can be null, which implicitly converts to NL_SYS (system default newline)...
Definition: sys.h:813
VarObject(std::initializer_list< InitPair > init)
Sequence constructor for object initializer.
Definition: var.h:1737
char buf_list_[sizeof(List< char >)]
Definition: var.h:1556
bool shared() const
Get whether shared.
Definition: maplist.h:381
Var & operator=(ValNull)
Assignment operator to set as null using vNULL.
Definition: var.h:1507
Null value
Definition: var.h:172
double & numf()
Get floating-point number reference, recreate as floating-point if needed.
Definition: var.h:1041
uint64 get_uint() const
Get unsigned integer number value (const).
Definition: var.h:1242
Var(const String &val)
Constructor to copy from a string value.
Definition: var.h:322
~Var()
Destructor.
Definition: var.h:421
T first(T val1, T val2)
Definition: alg.h:85
Random access iterator.
Definition: iter.h:904
Size writequoted(const char *buf, Size size, char delim, bool optional=false)
Write (append) quoted output to string.
Definition: string.h:4305
Var(const ObjectType &val)
Constructor to copy from an object map type.
Definition: var.h:304
ValNull
Unique null value type and value (vNULL).
Definition: sys.h:1096
Var & unshare()
Unshare current value.
Definition: var.h:717
ObjectType & object()
Get object reference, recreate as object if needed.
Definition: var.h:867
const Var & childref(const StringBase &key) const
Get child in object using key, default to null instance (const).
Definition: var.h:788
Var & operator=(short val)
Assignment operator to set as signed integer value (short).
Definition: var.h:1463
const Var * child(const StringBase &key) const
Find child in object using key (const).
Definition: var.h:820
VarObject()
Default constructor creates an empty object.
Definition: var.h:1730
ThisType & unshare()
Make data unique by allocating new buffer, if needed (modifier).
Definition: maplist.h:513
const ListType & get_list() const
Get read-only list reference (const).
Definition: var.h:1186
Var & operator=(longl val)
Assignment operator to set as signed integer value (longl).
Definition: var.h:1490
Explicit variant of Var used for initializing as an object with an initializer list of key/value pair...
Definition: var.h:1709
Var(bool val)
Constructor to initialize as boolean value (bool).
Definition: var.h:412
bool is_container() const
Get whether a container type (object or list).
Definition: var.h:437
String & clear()
Clear by removing all items.
Definition: string.h:4975
Var(long val)
Constructor to initialize as integer value (long).
Definition: var.h:398
String key
Field key string.
Definition: var.h:1713
bool empty() const
Get whether empty.
Definition: var.h:627
bool get_bool() const
Get boolean value (const).
Definition: var.h:1293
bool getbool(Error &error) const
Convert to bool value for given boolean type.
Definition: string.h:4006
Basic integer type.
Definition: type.h:980
Var & operator=(VarObject &&src)
Move assignment operator.
Definition: var.h:1755
const Item & item(Key index) const
Get item at position (const).
Definition: list.h:804
bool is_number() const
Get whether a number type (tFLOAT, tUNSIGNED, tINTEGER).
Definition: var.h:478
MapList< String, Var > ObjectType
Object map type.
Definition: var.h:160
Var & operator=(ulongl val)
Assignment operator to set as unsigned integer value (ulongl).
Definition: var.h:1454
Var & operator=(bool val)
Assignment operator to set as boolean value (bool).
Definition: var.h:1499
TSize Size
List size integer type
Definition: list.h:247
Var & operator=(const ObjectType &val)
Assignment operator to copy from object map type.
Definition: var.h:1361
bool is_integer() const
Get whether an integer number type (tUNSIGNED or tINTEGER).
Definition: var.h:500
Var & operator=(double val)
Assignment operator to set as floating-point value.
Definition: var.h:1418
Var & clear()
Clear current value.
Definition: var.h:676
bool is_list() const
Get whether a list type (tLIST).
Definition: var.h:462
bool get_val(String &val) const
Get value as a string (const).
Definition: var.h:1123
int64 & numi()
Get signed integer number reference, recreate as signed integer if not an integer.
Definition: var.h:999
Var(longl val)
Constructor to initialize as integer value (longl).
Definition: var.h:405
Floating-point value.
Definition: var.h:168
Var(const char *val)
Constructor to copy from an string value.
Definition: var.h:340
ThisType & setempty()
Set as empty but not null.
Definition: maplist.h:364
int64 get_int() const
Get signed integer number value (const).
Definition: var.h:1268
const char * data() const
Get string pointer (const).
Definition: string.h:1533
bool empty() const
Get whether empty.
Definition: list.h:753
ThisType & clear()
Clear by removing all items.
Definition: maplist.h:370
String container.
Definition: string.h:674
Var & unshare_all()
Unshare current value and all nested objects, lists, and strings.
Definition: var.h:747
bool null() const
Get whether null.
Definition: list.h:745
Initializer key/value pair.
Definition: var.h:1712
InitPair(const String &key, const T &value)
Definition: var.h:1717
Size size() const
Get size as number of children.
Definition: var.h:646
ListType & addmin(Size minsize)
Append new items up to a given minimum size (modifier).
Definition: list.h:2005
InitPair(const char *key, const T &value)
Definition: var.h:1725
const Value & value() const
Get value for pair (second value) (const).
Definition: pair.h:138
bool is_object() const
Get whether an object type (tOBJECT).
Definition: var.h:453
Var(std::initializer_list< Var > init)
Sequence constructor (C++11).
Definition: var.h:179
Var & operator[](Size index)
List item access operator.
Definition: var.h:1530
String & setn(int num, int base=fDEC)
Set as formatted signed number (modifier).
Definition: string.h:1117
General purpose variable that can hold a basic value (string, number, bool, etc) or children with nes...
Definition: var.h:157
ListType & clear()
Clear by removing all items.
Definition: list.h:574
Object with key/value fields.
Definition: var.h:165
String & setempty()
Set as empty but not null.
Definition: string.h:982
Var(short val)
Constructor to initialize as integer value (short).
Definition: var.h:384
const String & get_str() const
Get read-only string value reference (const).
Definition: var.h:1200
SizeT Size
Size type used.
Definition: var.h:159
Var value
Field value.
Definition: var.h:1714
bool shared() const
Get whether shared.
Definition: list.h:767
static const NewlineDefault & NL
Default newline type.
Definition: sys.h:785
Var & operator=(uint val)
Assignment operator to set as unsigned integer value (uint).
Definition: var.h:1436
Var()
Default constructor sets as null.
Definition: var.h:258
bool is_bool() const
Get whether a boolean type (tBOOL).
Definition: var.h:528
const Var & childref(Size index) const
Get child in list using index, default to null instance (const).
Definition: var.h:808
Var(ushort val)
Constructor to initialize as unsigned integer value (ushort).
Definition: var.h:356
ListType & setempty()
Set as empty but not null.
Definition: list.h:735
Evo C++ Library namespace.
Definition: alg.h:11
Type
Variable type.
Definition: var.h:164
Var & operator=(const StringBase &val)
Assignment operator to copy from string value.
Definition: var.h:1394
TSize Size
Size type for size values (must be unsigned integer) – default: SizeT.
Definition: map.h:134
Var(ulongl val)
Constructor to initialize as unsigned integer value (ulongl).
Definition: var.h:377
char buf_str_[sizeof(String)]
Definition: var.h:1557
bool is_float() const
Get whether a floating-point number type (tFLOAT).
Definition: var.h:493
Var(const ListType &val)
Constructor to copy from an object list type.
Definition: var.h:313
const Key & key() const
Get key for pair (first value) (const).
Definition: pair.h:114
uint64 buf_uint_
Definition: var.h:1559
List of values
Definition: var.h:166
T getnumf(Error &error) const
Convert to floating point number value for given type.
Definition: string.h:4084
String & unshare()
Make data unique by allocating new buffer, if needed (modifier).
Definition: string.h:5031
String & string()
Get string reference, recreate as string if needed.
Definition: var.h:925
Boolean value.
Definition: var.h:171
int64 buf_int_
Definition: var.h:1560
Size size() const
Get map size (number of items).
Definition: map.h:272
bool is_string() const
Get whether a string type (tSTRING).
Definition: var.h:471
Map implemented as an ordered list.
Definition: maplist.h:229
InitPair(const StringBase &key, const T &value)
Definition: var.h:1721
bool & boolref()
Get bool reference, recreate as bool if needed.
Definition: var.h:1086
String value
Definition: var.h:167
VarObject(VarObject &&src)
Move constructor.
Definition: var.h:1748
Var * childM(Size index)
Find child in list using index (mutable).
Definition: var.h:854
Value * findM(const Key &key)
Find (lookup) value for given key (mutable).
Definition: maplist.h:443
T getnum(Error &error, int base=0) const
Convert to number value for given integer type.
Definition: string.h:4045
Var(int val)
Constructor to initialize as integer value (int).
Definition: var.h:391
Var(ValNull)
Constructor to initialize as as null with vNULL as argument.
Definition: var.h:417
Var(Var &&src)
Move constructor (C++11).
Definition: var.h:190
bool shared_scan() const
Get whether this or any nested key or value has any shared data.
Definition: var.h:565
Var & operator=(const char *val)
Assignment operator to copy from terminated string value.
Definition: var.h:1405
Var(ulong val)
Constructor to initialize as unsigned integer value (ulong).
Definition: var.h:370
const ObjectType & get_object() const
Get read-only object reference (const).
Definition: var.h:1172
bool empty() const
Get whether map is empty (size is 0).
Definition: map.h:266
Var(double val)
Constructor to initialize as floating-point value.
Definition: var.h:349
Sequential list container with random access.
Definition: list.h:240
bool shared() const
Get whether this has shared data.
Definition: var.h:538
const Value * find(const Key &key) const
Find (lookup) value for given key (const).
Definition: maplist.h:437
Var(const Var &src)
Copy constructor.
Definition: var.h:264
Var & operator=(const ListType &val)
Assignment operator to copy from list type.
Definition: var.h:1372
ListType & unshare()
Make data unique by allocating new buffer, if needed (modifier).
Definition: list.h:1783
String & set()
Set as null and empty.
Definition: string.h:995
uint64 & numu()
Get unsigned integer number reference, recreate as unsigned integer if not an integer.
Definition: var.h:956
T & itemM(Key index)
Get item at position (mutable).
Definition: list.h:1487
char buf_obj_[sizeof(MapList< String, char >)]
Definition: var.h:1555
Var & operator=(long val)
Assignment operator to set as signed integer value (long).
Definition: var.h:1481
Stores a key/value pair of independent objects or values.
Definition: pair.h:32
List< Var > ListType
Item list type.
Definition: var.h:161
uint32 SizeT
Default Evo container size type.
Definition: sys.h:729
Integer value (signed)
Definition: var.h:170
Var & operator=(const String &val)
Assignment operator to copy from string value.
Definition: var.h:1383
bool null() const
Get whether null.
Definition: var.h:600
double get_float() const
Get value as a floating-point number (const).
Definition: var.h:1215
Base for all Evo list types (used internally).
Definition: sys.h:976
Var & operator=(ulong val)
Assignment operator to set as unsigned integer value (ulong).
Definition: var.h:1445
bool is_unsigned() const
Get whether an unsigned integer number type (tUNSIGNED).
Definition: var.h:514
T & dump(T &out, const NewlineValue &newline=NL, uint indent=0) const
Dump all children and values to stream or string.
Definition: var.h:1545
bool null() const
Get whether map is null.
Definition: maplist.h:378
Var VarList
Alias for Var, useful for explicitly passing a list to a VarObject field value (C++11).
Definition: var.h:1768
ListType & list()
Get list reference, recreate as list if needed.
Definition: var.h:896
Var & operator=(int val)
Assignment operator to set as signed integer value (int).
Definition: var.h:1472
Type type() const
Get current type.
Definition: var.h:428
Var(const StringBase &val)
Constructor to copy from a string value.
Definition: var.h:331