280 inline Data(
Type t,
const char* b,
char s) : type(t), referenceCount(1), bracket(b), separator(s) {}
349 Any(
const std::string& key,
Data* data);
352 return ! m_placeholderName.empty();
359 Any _get(
const std::string& key,
const Any& defaultVal)
const;
360 void _set(
const std::string& key,
const Any& val);
362 void _parse(
const std::string& src);
392 message =
format(
"Index out of bounds: index = %d, array size = %d", i, s);
405 explicit Any(
double x);
407 explicit Any(
float x);
409 #if defined(G3D_32Bit) || defined(_MSC_VER)
415 explicit Any(
long x);
421 explicit Any(
char x);
424 explicit Any(
short x);
427 explicit Any(
bool x);
430 explicit Any(
const std::string&
x);
433 explicit Any(
const char*
x);
439 explicit Any(
Type t,
const std::string&
name =
"",
const std::string& brackets =
"",
const char separator =
'\0');
460 for (
int i = 0; i < array.
size(); ++i) {
480 static Any parse(
const std::string& src);
489 const std::string&
comment()
const;
499 const std::string&
string()
const;
516 const std::string&
name()
const;
564 return (*
this)[
size() - 1];
568 return (*
this)[
size() - 1];
579 template<
class T0,
class T1>
584 template<
class T0,
class T1,
class T2>
589 template<
class T0,
class T1,
class T2,
class T3>
642 Any get(
const std::string& key,
const T& defaultVal)
const {
643 return _get(key,
Any(defaultVal));
651 void set(
const std::string& key,
const T& val) {
667 return *
this ==
Any(s);
671 return *
this ==
Any(v);
675 return *
this ==
Any(v);
679 return *
this ==
Any(v);
685 return *
this !=
Any(s);
689 return *
this !=
Any(v);
693 return *
this !=
Any(v);
697 return *
this !=
Any(v);
700 operator int()
const;
702 operator float()
const;
703 operator double()
const;
704 operator bool()
const;
705 operator std::string()
const;
707 operator char()
const {
708 return char(
int(*
this));
712 return uint8(
int(*
this));
716 return int16(
int(*
this));
720 return uint16(
int(*
this));
735 void load(
const std::string& filename);
744 void save(
const std::string& filename)
const;
756 const Source&
source()
const;
759 void remove(
const std::string& key);
763 void remove(
int index);
768 void verify(
bool value,
const std::string& message =
"")
const;
777 void verifyName(
const std::string& n,
const std::string& m)
const;
781 void verifyName(
const std::string& n,
const std::string& m,
const std::string& p)
const;
785 void verifyName(
const std::string& n,
const std::string& m,
const std::string& p,
const std::string& q)
const;
797 void verifyNameBeginsWith(
const std::string& n,
const std::string& m,
const std::string& p)
const;
801 void verifyNameBeginsWith(
const std::string& n,
const std::string& m,
const std::string& p,
const std::string& q)
const;
805 void verifyNameBeginsWith(
const std::string& n,
const std::string& m,
const std::string& p,
const std::string& q,
const std::string& r)
const;
809 void verifyNameBeginsWith(
const std::string& n,
const std::string& m,
const std::string& p,
const std::string& q,
const std::string& r,
const std::string& s)
const;
813 void verifyNameBeginsWith(
const std::string& n,
const std::string& m,
const std::string& p,
const std::string& q,
const std::string& r,
const std::string& s,
const std::string& t)
const;
833 for (
int i = 0; i < array.
size(); ++i) {
834 (*this)[i] =
Any(array[i]);
843 for (
int i = 0; i < array.
size(); ++i) {
844 array[i] = T((*
this)[i]);
853 table.
set(it.key(), T(it.value()));
903 return m_any.
size() > m_alreadyRead.
size();
916 const std::string& key()
const;
925 void get(
const std::string& s, std::string& v) {
931 void get(
const std::string& s,
uint8& v) {
932 v =
uint8(m_any[s].number());
937 void get(
const std::string& s,
uint16& v) {
938 v =
uint16(m_any[s].number());
964 template<
class ValueType>
965 void get(
const std::string& s, ValueType& v) {
966 v = ValueType(m_any[s]);
988 template<
class ValueType>
1021 #define PARSE_ANY(x) Any::parse(#x)
void getTable(Table< std::string, T > &table) const
Definition: Any.h:850
Type type() const
Definition: Any.cpp:505
~Data()
Definition: Any.cpp:282
Any(const Array< T > &array, const std::string &name="")
Definition: Any.h:830
std::string key
Definition: Any.h:369
Value()
Definition: Any.h:237
void clear()
Definition: Any.cpp:613
AtomicInt32 referenceCount
Definition: Any.h:267
const std::string & string() const
Definition: Any.cpp:548
const char * bracket
Definition: Any.h:272
Any & next()
Definition: Any.cpp:641
Value value
Definition: Any.h:246
bool getIfPresent(const std::string &s, ValueType &v)
Definition: Any.h:989
bool operator==(const std::string &s) const
Definition: Any.h:666
int16_t int16
Definition: g3dmath.h:165
void resize(size_t n, bool shrinkIfNecessary=true)
Definition: Array.h:490
bool isNil() const
Definition: Any.cpp:530
bool containsKey(const std::string &key) const
Definition: Any.cpp:313
int line
Definition: ParseError.h:37
bool containsUnread(const std::string &s) const
Definition: Any.h:1002
const std::string & filename() const
Definition: TextInput.cpp:1238
SimpleValue()
Definition: Any.h:220
void _set(const std::string &key, const Any &val)
Definition: Any.cpp:758
Any m_any
Definition: Any.h:892
int size
Definition: Any.h:384
bool contains(const T &member) const
Definition: Set.h:54
Set< std::string > m_alreadyRead
Definition: Any.h:893
Source()
Definition: Any.h:198
std::string sourceDirectory() const
Definition: Any.cpp:1604
void append(const T0 &v0, const T1 &v1, const T2 &v2, const T3 &v3)
Definition: Any.h:590
int index
Definition: Any.h:383
void loadIfExists(const std::string &filename)
Definition: Any.cpp:103
Definition: TextOutput.h:63
Any()
Definition: Any.cpp:347
std::string name
Definition: Any.h:250
const Table< std::string, Any > & table() const
Definition: Any.cpp:706
void append(const T0 &v0, const T1 &v1, const T2 &v2)
Definition: Any.h:585
static void destroy(Data *d)
Definition: Any.cpp:274
void resize(int n)
Definition: Any.cpp:602
SimpleValue m_simpleValue
Definition: Any.h:307
SimpleValue(bool x)
Definition: Any.h:221
const Any & operator[](const char *key) const
Definition: Any.h:605
Source source
Definition: Any.h:269
Any & last()
Definition: Any.h:567
int line() const
Definition: TextInput.h:125
static void deserializeComment(TextInput &ti, Token &token, std::string &comment)
Definition: Any.cpp:1178
Dynamic 1D array tuned for performance.
Definition: Array.h:95
Any & operator[](const char *key)
Definition: Any.h:635
Definition: AtomicInt32.h:29
static void deserializeName(TextInput &ti, Token &token, std::string &name)
Definition: Any.cpp:1206
arena_t NULL
Definition: jemalloc_internal.h:624
std::string filename
Definition: ParseError.h:27
void append(const T0 &v0)
Definition: Any.h:575
std::string resolveStringAsFilename(bool errorIfNotFound=true) const
Definition: Any.cpp:49
Any _get(const std::string &key, const Any &defaultVal) const
Definition: Any.cpp:771
AnyTable * t
Definition: Any.h:236
void set(const Key &key, const Value &value)
Definition: Table.h:599
Table< std::string, Any > AnyTable
Definition: Any.h:208
#define debugAssertM(exp, message)
Definition: debugAssert.h:161
static void readUntilSeparatorOrClose(TextInput &ti, Token &token)
Definition: Any.cpp:1393
uint16_t uint16
Definition: g3dmath.h:166
SimpleValue(double x)
Definition: Any.h:222
#define T1
Definition: Crypto_md5.cpp:153
Any(const T &v)
Definition: Any.h:443
Array< Any > AnyArray
Definition: Any.h:207
bool operator!=(int v) const
Definition: Any.h:692
void dropReference()
Definition: Any.cpp:327
#define bool
Definition: CascPort.h:16
int character
Definition: ParseError.h:42
bool nameEquals(const std::string &s) const
Definition: Any.cpp:115
void beforeWrite()
Definition: Any.cpp:448
Any & operator=(const Array< T > &array)
Definition: Any.h:457
IndexOutOfBounds(const Data *data, int i, int s)
Definition: Any.h:386
void deserializeArray(TextInput &ti, const std::string &term)
void serialize(TextOutput &to, bool json=false, bool coerce=false) const
Definition: Any.cpp:956
void deserialize(TextInput &ti, Token &token)
Definition: Any.cpp:1233
std::string filename
Definition: Any.h:194
Easy loading and saving of human-readable configuration files.
Definition: Any.h:184
int character() const
Definition: TextInput.h:133
void verifyType(Type t) const
Definition: Any.cpp:1739
const Any & any() const
Definition: Any.h:910
Definition: TextInput.h:34
bool nameBeginsWith(const std::string &s) const
Definition: Any.cpp:110
Type m_type
Definition: Any.h:306
bool operator!=(bool v) const
Definition: Any.h:696
double n
Definition: Any.h:218
#define T3
Definition: Crypto_md5.cpp:155
#define T2
Definition: Crypto_md5.cpp:154
Any & operator=(const T &v)
Definition: Any.h:468
Type
Definition: Any.h:187
int size() const
Definition: Set.h:50
void ensureData()
Definition: Any.cpp:1381
void setName(const std::string &name)
Set the name used when serializing an ARRAY or TABLE.
Definition: Any.cpp:573
std::string unparse(const TextOutput::Settings &s=TextOutput::Settings()) const
Definition: Any.cpp:881
bool operator!=(const double &v) const
Definition: Any.h:688
std::string comment
Definition: Any.h:248
bool insert(const T &member)
Definition: Set.h:62
double number() const
Definition: Any.cpp:535
A simple tokenizer for parsing text files.
Definition: TextInput.h:223
Type type
Definition: Any.h:242
bool operator!=(const std::string &s) const
Definition: Any.h:684
float floatValue() const
Definition: Any.cpp:541
void verifyName(const std::string &n) const
Definition: Any.cpp:1637
Array< Any > * a
Definition: Any.h:235
void verifySize(int low, int high) const
Definition: Any.cpp:1756
Data * m_data
Definition: Any.h:308
bool operator==(const Any &x) const
Definition: Any.cpp:782
bool operator!=(const Any &x) const
Definition: Any.cpp:857
bool hasMore() const
Definition: Any.h:902
void deserializeBody(TextInput &ti, Token &token)
Definition: Any.cpp:1459
void beforeRead() const
Definition: Any.cpp:154
void setComment(const std::string &c)
Definition: Any.cpp:523
std::string __cdecl format(const char *fmt...) G3D_CHECK_PRINTF_ARGS
IndexOutOfBounds()
Definition: Any.h:385
int size() const
Definition: Array.h:430
bool operator==(const double &v) const
Definition: Any.h:670
bool isPlaceholder() const
Definition: Any.h:351
Definition: TextOutput.h:60
static const char * BRACKET
Definition: Any.h:227
int character
Definition: Any.h:196
bool operator==(bool v) const
Definition: Any.h:678
void getArray(Array< T > &array) const
Definition: Any.h:840
int line
Definition: Any.h:195
~Any()
Definition: Any.cpp:443
const Any & last() const
Definition: Any.h:563
void append(const T0 &v0, const T1 &v1)
Definition: Any.h:580
char separator
Definition: Any.h:275
static Any parse(const std::string &src)
Definition: Any.cpp:889
int64_t int64
Definition: g3dmath.h:169
bool boolean() const
Definition: Any.cpp:555
static Data * create(const Data *d)
Definition: Any.cpp:169
void load(const std::string &filename)
Definition: Any.cpp:906
const std::string & name() const
Definition: Any.cpp:562
uint8_t uint8
Definition: g3dmath.h:164
bool b
Definition: Any.h:217
std::string * s
Definition: Any.h:234
void set(const std::string &key, const T &val)
Definition: Any.h:651
int length() const
Definition: Any.cpp:596
void verifyDone() const
Definition: AnyTableReader.cpp:33
void verifyNameBeginsWith(const std::string &n) const
Definition: Any.cpp:1670
int size() const
Definition: Any.cpp:580
Definition: ParseError.h:22
void verify(bool value, const std::string &message="") const
Definition: Any.cpp:1612
Definition: BinaryOutput.h:52
void become(const Type &t)
Definition: Any.cpp:68
static Any fromFile(const std::string &filename)
Definition: Any.cpp:96
KeyNotFound(const Data *data)
Definition: Any.h:371
void deserializeTable(TextInput &ti)
static std::string toString(Type t)
Definition: Any.cpp:1774
Any & operator=(const Any &x)
Definition: Any.cpp:462
std::string unparseJSON(const TextOutput::Settings &s=TextOutput::Settings(), bool allowCoercion=true) const
Definition: Any.cpp:873
const std::string & comment() const
Definition: Any.cpp:511
AnyTableReader(const std::string &name, const Any &a)
Definition: AnyTableReader.cpp:6
const Any & operator[](int i) const
Definition: Any.cpp:629
const FieldDescriptor value
Definition: descriptor.h:1522
const Any & operator[](const std::string &s)
Definition: Any.h:971
uint32_t uint32
Definition: g3dmath.h:168
std::string message
Definition: ParseError.h:44
void set(const TextInput &ti, const Token &t)
Definition: Any.h:200
G3D::int16 x
Definition: Vector2int16.h:37
static const char * BRACE
Definition: Any.h:228
const Array< Any > & array() const
Definition: Any.cpp:663
Type
Type of JSON value.
Definition: rapidjson.h:642
std::string includeLine
Definition: Any.h:260
static const char * PAREN
Definition: Any.h:226
std::string m_placeholderName
Definition: Any.h:304
void save(const std::string &filename) const
Definition: Any.cpp:916
void _append(const Any &v0)
Definition: Any.cpp:671
Data(Type t, const char *b, char s)
Definition: Any.h:280
void ensureMutable()
Definition: Any.cpp:336
BG_AV_Nodes & operator++(BG_AV_Nodes &i)
Definition: BattlegroundAV.h:1550
const Source & source() const
Definition: Any.cpp:1594
void _parse(const std::string &src)
Definition: Any.cpp:896
bool operator==(int v) const
Definition: Any.h:674