Support Forum       G3D Web Page     
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
G3D::Any Class Reference


Easy loading and saving of human-readable configuration files. More...

Classes

class  IndexOutOfBounds
 Thrown by operator[] when an array index is not present. More...
 
class  KeyNotFound
 Thrown by operator[] when a key is not present in a const table. More...
 
class  Source
 Where an Any came from in a file. More...
 

Public Types

typedef Array< AnyAnyArray
 
typedef Table< String, AnyAnyTable
 
enum  Type {
  NIL,
  BOOLEAN,
  NUMBER,
  STRING,
  ARRAY,
  TABLE,
  EMPTY_CONTAINER
}
 

Public Member Functions

 Any ()
 NIL constructor. More...
 
 Any (TextInput &t)
 Deserialize. More...
 
 Any (const Any &x)
 
 Any (double x)
 NUMBER constructor. More...
 
 Any (float x)
 
 Any (int64 x)
 NUMBER constructor. More...
 
 Any (long x)
 NUMBER constructor. More...
 
 Any (int x)
 NUMBER constructor. More...
 
 Any (char x)
 NUMBER constructor. More...
 
 Any (short x)
 NUMBER constructor. More...
 
 Any (bool x)
 BOOLEAN constructor. More...
 
 Any (const String &x)
 STRING constructor. More...
 
 Any (const char *x)
 STRING constructor. More...
 
 Any (Type t, const String &name="", const String &brackets="", const char separator='\0')
 t must be ARRAY or TABLE More...
 
template<class T >
 Any (const T &v)
 Extensible constructor: call the toAny() method of any class. More...
 
template<class T >
 Any (const Array< T > &array, const String &name="")
 Assumes that Any(T) is well-defined, e.g., by T defining a T::toAny() method. More...
 
 ~Any ()
 
template<class T0 >
void append (const T0 &v0)
 
template<class T0 , class T1 >
void append (const T0 &v0, const T1 &v1)
 
template<class T0 , class T1 , class T2 >
void append (const T0 &v0, const T1 &v1, const T2 &v2)
 
template<class T0 , class T1 , class T2 , class T3 >
void append (const T0 &v0, const T1 &v1, const T2 &v2, const T3 &v3)
 
const Array< Any > & array () const
 Directly exposes the underlying data structure for an ARRAY. More...
 
bool boolean () const
 
void clear ()
 Clears all entries. More...
 
const Stringcomment () const
 Comments appear before values when they are in serialized form. More...
 
bool containsKey (const String &key) const
 Returns true if this key is in the TABLE. More...
 
void deserialize (TextInput &ti)
 Parse from a stream. More...
 
void deserialize (class BinaryInput &b)
 
float floatValue () const
 
template<class T >
Any get (const String &key, const T &defaultVal) const
 For a table, returns the element for key x and defaultVal if it does not exist. More...
 
template<class T >
void getArray (Array< T > &array) const
 Assumes that T defines T(const Any&) More...
 
template<>
void getArray (Array< String > &array) const
 Template specialization to avoid defining G3DString(const Any&) and related methods. More...
 
template<class T >
void getTable (Table< String, T > &table) const
 Assumes that T defines T(const Any&) More...
 
bool isNil () const
 True if this is the NIL value. More...
 
const Anylast () const
 
Anylast ()
 
int length () const
 
void load (const String &filename)
 Parse from a file. More...
 
void loadIfExists (const String &filename)
 Load filename file if it exists, otherwise do not modify this. More...
 
const Stringname () const
 If this is named ARRAY or TABLE, returns the name. More...
 
bool nameBeginsWith (const String &s) const
 If this is named ARRAY or TABLE, returns true if the name begins with s. More...
 
bool nameBeginsWith (const char *s) const
 If this is named ARRAY or TABLE, returns true if the name begins with s. More...
 
bool nameEquals (const String &s) const
 If this is named ARRAY or TABLE, returns true if the name is s. More...
 
bool nameEquals (const char *s) const
 If this is named ARRAY or TABLE, returns true if the name iss. More...
 
Anynext ()
 for an ARRAY, resizes and returns the last element More...
 
double number () const
 Throws a ParseError exception if this is not a number. More...
 
 operator bool () const
 
 operator char () const
 
 operator double () const
 
 operator float () const
 
 operator int () const
 
 operator int16 () const
 
 operator String () const
 
 operator uint16 () const
 
 operator uint32 () const
 
 operator uint8 () const
 
bool operator!= (const Any &x) const
 
bool operator!= (const String &s) const
 
bool operator!= (const double &v) const
 
bool operator!= (int v) const
 
bool operator!= (bool v) const
 
Anyoperator= (const Any &x)
 Removes the comment and name. More...
 
Anyoperator= (Type t)
 t must be ARRAY, TABLE, or NIL. More...
 
template<class T >
Anyoperator= (const Array< T > &array)
 Assigns from an array. More...
 
template<class T >
Anyoperator= (const T &v)
 Removes the comment and name. More...
 
bool operator== (const Any &x) const
 True if the Anys are exactly equal, ignoring comments. More...
 
bool operator== (const String &s) const
 
bool operator== (const double &v) const
 
bool operator== (int v) const
 
bool operator== (bool v) const
 
const Anyoperator[] (int i) const
 For an array, returns the ith element. More...
 
Anyoperator[] (int i)
 
const Anyoperator[] (const String &key) const
 For a table, returns the element for key. More...
 
const Anyoperator[] (const char *key) const
 
Anyoperator[] (const String &key)
 Fetch an element from a table. More...
 
Anyoperator[] (const char *key)
 Fetch an element from a table.
More...
 
void remove (const String &key)
 Removes this key from the Any, which must be a table. More...
 
void remove (int index)
 Removes this key from the Any, which must be an array, and shifts other elements down to maintain order. More...
 
void resize (int n)
 Resize to n elements, where new elements are NIL It is an error to call this method if this is not an Any::ARRAY. More...
 
String resolveStringAsFilename (bool errorIfNotFound=true) const
 If a valid string, takes the string value and creates a fully qualified filename. More...
 
void save (const String &filename, bool json=false) const
 Uses the serialize method. More...
 
void serialize (TextOutput &to, bool json=false, bool coerce=false) const
 
void serialize (class BinaryOutput &b) const
 
template<class T >
void set (const String &key, const T &val)
 For a table, assigns the element for key k. More...
 
void setComment (const String &c)
 
void setName (const String &name)
 Set the name used when serializing an ARRAY or TABLE. More...
 
int size () const
 Number of elements if this is an ARRAY or TABLE. More...
 
const Sourcesource () const
 
String sourceDirectory () const
 The parent directory of the location from which this Any was loaded. More...
 
const Stringstring () const
 
const Table< String, Any > & table () const
 Directly exposes the underlying data structure for table. More...
 
Type type () const
 
String unparse (const TextOutput::Settings &s=TextOutput::Settings()) const
 
String unparseJSON (const TextOutput::Settings &s=TextOutput::Settings(), bool allowCoercion=true) const
 
void verify (bool value, const String &message="") const
 Throws a ParseError if value is false. More...
 
void verifyName (const String &n) const
 Verifies that the name is identifier n (case sensitive). More...
 
void verifyName (const String &n, const String &m) const
 Verifies that the name is identifier n or m (case sensitive). More...
 
void verifyName (const String &n, const String &m, const String &p) const
 Verifies that the name is identifier n or m or p (case sensitive). More...
 
void verifyName (const String &n, const String &m, const String &p, const String &q) const
 Verifies that the name is identifier n or m or p or q (case sensitive). More...
 
void verifyNameBeginsWith (const String &n) const
 Verifies that the name begins with identifier n (case sensitive). More...
 
void verifyNameBeginsWith (const String &n, const String &m) const
 Verifies that the name begins with identifier n or m (case sensitive). More...
 
void verifyNameBeginsWith (const String &n, const String &m, const String &p) const
 Verifies that the name begins with identifier n or m or p (case sensitive). More...
 
void verifyNameBeginsWith (const String &n, const String &m, const String &p, const String &q) const
 Verifies that the name begins with identifier n or m or p or q (case sensitive). More...
 
void verifyNameBeginsWith (const String &n, const String &m, const String &p, const String &q, const String &r) const
 Verifies that the name begins with identifier n or m or p or q or r (case sensitive). More...
 
void verifyNameBeginsWith (const String &n, const String &m, const String &p, const String &q, const String &r, const String &s) const
 Verifies that the name begins with identifier n or m or p or q or r or s (case sensitive). More...
 
void verifyNameBeginsWith (const String &n, const String &m, const String &p, const String &q, const String &r, const String &s, const String &t) const
 Verifies that the name begins with identifier n or m or p or q or r or s or t(case sensitive). More...
 
void verifySize (int low, int high) const
 Verifies that the size is between low and high, inclusive. More...
 
void verifySize (int s) const
 Verifies that the size is exactly s. More...
 
void verifyType (Type t) const
 Verifies that the type is t. More...
 
void verifyType (Type t0, Type t1) const
 Throws an exception if the type is not t0 or t1. More...
 

Static Public Member Functions

static Any fromFile (const String &filename)
 Load a new Any from filename. More...
 
static Any parse (const String &src)
 Same as deserialize or load, but operates on a string instead of a stream or file. More...
 
static String toString (Type t)
 

Detailed Description


Easy loading and saving of human-readable configuration files.

Any encodes typed, structured data and can serialize it to a human readable format that is very similar to the Python language's data syntax, and fully supports Python's data syntax as well. It is well-suited for quickly creating human-readable file formats, especially since deserialization and serialization preserve comments and an Any can tell you what file and line it came from. The syntax allows most C++ editors to properly highlight Any files, and makes it easy to design little ad-hoc C-like languages in configuration files.

The class is designed so that copying Anys generally is fast, even if it is a large array or table. This is because data is shared between copies until it is mutated, at which point an actual copy occurs.

Example

A sample .Any file:

{
   shape = "round",
   // in meters
   radius = 3.7,
   position = Vector3(1.0, -1.0, 0.0),
   video = { format = "RGB8", size = (320, 200)},
   data = [1, 7, 15, 2, -inf, 21, 0],
   material = #include("rocks.mat")
}

Sample code for constructing an Any at runtime:

// Read from an Any format in a string
Any a = Any::parse(mydata);
// Read from a file
Any a;
a.load(filename);
// Construct a new Any
Any a = "Hello";
Any a = 7;
t["key"] = value;
// Construct a nil value (null is a reserved word in C++)
Any a;
x.append(8);

Reading from an Any:

// Using AnyTableReader:
bool enabled = true, showSamples = false;
String name = "";
Any a;
a.load("occluder.Any");
AnyTableReader r(a);
// Optional properties
r.getIfPresent("enabled", enabled);
r.getIfPresent("name", name);
// Mandatory, error if missing
r.get("showSamples", showSamples);
// Error if any fields were not read.
r.verifyDone();
// Manual:
Any x;
x.load("occluder.Any");
if (x["shape"] == "round") {
const float r = x["radius"];
size = Vector2(r, r);
} else {
size = x["dimnsions"];
}

Generating an Any file:

a["name"] = name;
a["showSamples"] = showSamples;
a["dimensions"] = Vector2(w, h);
t["h"] = 3;
t["k"] = Matrix3::identity();
a["params"] = t;
a.save("parameters.Any");

Interoperation with your own classes:

class MyClass {
protected:
float m_value = 0.0f;
public:
...
explicit MyClass(const Any& any) {
*this = MyClass();
any.verifyName("MyClass");
AnyTableReader r;
r.getIfPresent("m_value", m_value);
r.done();
}
MyClass& operator=(const Any& a) {
return *this = MyClass(a);
}
Any toAny() const {
Any any(Any::TABLE, "MyClass");
any["value"] = m_value;
return any;
}
};

The custom serialization format was chosen to be terse, easy for humans to read, and easy for machines to parse. It was specifically chosen over formats like XML, YAML, JSON, S-expressions, and Protocol Buffers, although there is no reason you could not write readers and writers for G3D::Any that support those. Any also currently supports the JSON format.

Cycles Allowed

G3D::Any assumes that structures do not contain cycles; it is an error to create a structure like:

Any x(Any::ARRAY);
x.array().append(x);    // don't do this!

although no exception will be thrown at runtime during that append.

Member Typedef Documentation

◆ AnyArray

◆ AnyTable

Member Enumeration Documentation

◆ Type

Enumerator
NIL 
BOOLEAN 
NUMBER 
STRING 
ARRAY 
TABLE 
EMPTY_CONTAINER 

Constructor & Destructor Documentation

◆ Any() [1/16]

G3D::Any::Any ( )

NIL constructor.

Referenced by Any(), append(), get(), operator!=(), operator=(), operator==(), and set().

◆ Any() [2/16]

G3D::Any::Any ( TextInput t)
explicit

Deserialize.

◆ Any() [3/16]

G3D::Any::Any ( const Any x)

◆ Any() [4/16]

G3D::Any::Any ( double  x)
explicit

NUMBER constructor.

◆ Any() [5/16]

G3D::Any::Any ( float  x)
explicit

◆ Any() [6/16]

G3D::Any::Any ( int64  x)
inlineexplicit

NUMBER constructor.

◆ Any() [7/16]

G3D::Any::Any ( long  x)
explicit

NUMBER constructor.

◆ Any() [8/16]

G3D::Any::Any ( int  x)
explicit

NUMBER constructor.

◆ Any() [9/16]

G3D::Any::Any ( char  x)
explicit

NUMBER constructor.

◆ Any() [10/16]

G3D::Any::Any ( short  x)
explicit

NUMBER constructor.

◆ Any() [11/16]

G3D::Any::Any ( bool  x)
explicit

BOOLEAN constructor.

◆ Any() [12/16]

G3D::Any::Any ( const String x)
explicit

STRING constructor.

◆ Any() [13/16]

G3D::Any::Any ( const char *  x)
explicit

STRING constructor.

◆ Any() [14/16]

G3D::Any::Any ( Type  t,
const String name = "",
const String brackets = "",
const char  separator = '\0' 
)
explicit

t must be ARRAY or TABLE

Parameters
bracketsmust be "" (defaults to {} for table, () for array), "[]", "()", or "{}"
separatormust be ';', ',', or '\0' (defaults to ',' for array and ';' for table)

◆ Any() [15/16]

template<class T >
G3D::Any::Any ( const T &  v)
inlineexplicit

Extensible constructor: call the toAny() method of any class.

◆ ~Any()

G3D::Any::~Any ( )

◆ Any() [16/16]

template<class T >
G3D::Any::Any ( const Array< T > &  array,
const String name = "" 
)
inlineexplicit

Assumes that Any(T) is well-defined, e.g., by T defining a T::toAny() method.

Member Function Documentation

◆ append() [1/4]

template<class T0 >
void G3D::Any::append ( const T0 &  v0)
inline

◆ append() [2/4]

template<class T0 , class T1 >
void G3D::Any::append ( const T0 &  v0,
const T1 &  v1 
)
inline

◆ append() [3/4]

template<class T0 , class T1 , class T2 >
void G3D::Any::append ( const T0 &  v0,
const T1 &  v1,
const T2 &  v2 
)
inline

◆ append() [4/4]

template<class T0 , class T1 , class T2 , class T3 >
void G3D::Any::append ( const T0 &  v0,
const T1 &  v1,
const T2 &  v2,
const T3 &  v3 
)
inline

◆ array()

const Array<Any>& G3D::Any::array ( ) const

Directly exposes the underlying data structure for an ARRAY.

Referenced by Any(), getArray(), and operator=().

◆ boolean()

bool G3D::Any::boolean ( ) const

◆ clear()

void G3D::Any::clear ( )

Clears all entries.

This must be a TABLE or ARRAY

◆ comment()

const String& G3D::Any::comment ( ) const

Comments appear before values when they are in serialized form.

◆ containsKey()

bool G3D::Any::containsKey ( const String key) const

Returns true if this key is in the TABLE.

Illegal to call on an object that is not a TABLE.

Referenced by G3D::AnyTableReader::containsUnread(), G3D::AnyTableReader::getFilenameIfPresent(), and G3D::AnyTableReader::getIfPresent().

◆ deserialize() [1/2]

void G3D::Any::deserialize ( TextInput ti)

Parse from a stream.

See also
load, parse

◆ deserialize() [2/2]

void G3D::Any::deserialize ( class BinaryInput b)

◆ floatValue()

float G3D::Any::floatValue ( ) const

◆ fromFile()

static Any G3D::Any::fromFile ( const String filename)
static

Load a new Any from filename.

See also
load, save, loadIfExists

◆ get()

template<class T >
Any G3D::Any::get ( const String key,
const T &  defaultVal 
) const
inline

For a table, returns the element for key x and defaultVal if it does not exist.

◆ getArray() [1/2]

template<class T >
void G3D::Any::getArray ( Array< T > &  array) const
inline

Assumes that T defines T(const Any&)

Referenced by G3D::AnyTableReader::get().

◆ getArray() [2/2]

template<>
void G3D::Any::getArray ( Array< String > &  array) const
inline

Template specialization to avoid defining G3DString(const Any&) and related methods.

◆ getTable()

template<class T >
void G3D::Any::getTable ( Table< String, T > &  table) const
inline

Assumes that T defines T(const Any&)

Referenced by G3D::AnyTableReader::get().

◆ isNil()

bool G3D::Any::isNil ( ) const

True if this is the NIL value.

◆ last() [1/2]

const Any& G3D::Any::last ( ) const
inline

◆ last() [2/2]

Any& G3D::Any::last ( )
inline

◆ length()

int G3D::Any::length ( ) const

◆ load()

void G3D::Any::load ( const String filename)

Parse from a file.

See also
deserialize, parse, fromFile, loadIfExists

◆ loadIfExists()

void G3D::Any::loadIfExists ( const String filename)

Load filename file if it exists, otherwise do not modify this.

◆ name()

const String& G3D::Any::name ( ) const

If this is named ARRAY or TABLE, returns the name.

Referenced by Any().

◆ nameBeginsWith() [1/2]

bool G3D::Any::nameBeginsWith ( const String s) const

If this is named ARRAY or TABLE, returns true if the name begins with s.

The comparision is case insensitive.

◆ nameBeginsWith() [2/2]

bool G3D::Any::nameBeginsWith ( const char *  s) const

If this is named ARRAY or TABLE, returns true if the name begins with s.

The comparision is case insensitive.

◆ nameEquals() [1/2]

bool G3D::Any::nameEquals ( const String s) const

If this is named ARRAY or TABLE, returns true if the name is s.

The comparision is case insensitive.

◆ nameEquals() [2/2]

bool G3D::Any::nameEquals ( const char *  s) const

If this is named ARRAY or TABLE, returns true if the name iss.

The comparision is case insensitive.

◆ next()

Any& G3D::Any::next ( )

for an ARRAY, resizes and returns the last element

◆ number()

double G3D::Any::number ( ) const

Throws a ParseError exception if this is not a number.

◆ operator bool()

G3D::Any::operator bool ( ) const

◆ operator char()

G3D::Any::operator char ( ) const
inline

◆ operator double()

G3D::Any::operator double ( ) const

◆ operator float()

G3D::Any::operator float ( ) const

◆ operator int()

G3D::Any::operator int ( ) const

◆ operator int16()

G3D::Any::operator int16 ( ) const
inline

◆ operator String()

G3D::Any::operator String ( ) const

◆ operator uint16()

G3D::Any::operator uint16 ( ) const
inline

◆ operator uint32()

G3D::Any::operator uint32 ( ) const

◆ operator uint8()

G3D::Any::operator uint8 ( ) const
inline

◆ operator!=() [1/5]

bool G3D::Any::operator!= ( const Any x) const

◆ operator!=() [2/5]

bool G3D::Any::operator!= ( const String s) const
inline

◆ operator!=() [3/5]

bool G3D::Any::operator!= ( const double &  v) const
inline

◆ operator!=() [4/5]

bool G3D::Any::operator!= ( int  v) const
inline

◆ operator!=() [5/5]

bool G3D::Any::operator!= ( bool  v) const
inline

◆ operator=() [1/4]

Any& G3D::Any::operator= ( const Any x)

Removes the comment and name.

◆ operator=() [2/4]

Any& G3D::Any::operator= ( Type  t)

t must be ARRAY, TABLE, or NIL.

Removes the comment and name

◆ operator=() [3/4]

template<class T >
Any& G3D::Any::operator= ( const Array< T > &  array)
inline

Assigns from an array.

Assumes that T can be converted to Any. Removes the comment and name

◆ operator=() [4/4]

template<class T >
Any& G3D::Any::operator= ( const T &  v)
inline

Removes the comment and name.

◆ operator==() [1/5]

bool G3D::Any::operator== ( const Any x) const

True if the Anys are exactly equal, ignoring comments.

Applies deeply on arrays and tables.

◆ operator==() [2/5]

bool G3D::Any::operator== ( const String s) const
inline

◆ operator==() [3/5]

bool G3D::Any::operator== ( const double &  v) const
inline

◆ operator==() [4/5]

bool G3D::Any::operator== ( int  v) const
inline

◆ operator==() [5/5]

bool G3D::Any::operator== ( bool  v) const
inline

◆ operator[]() [1/6]

const Any& G3D::Any::operator[] ( int  i) const

For an array, returns the ith element.

Referenced by operator=(), and operator[]().

◆ operator[]() [2/6]

Any& G3D::Any::operator[] ( int  i)

◆ operator[]() [3/6]

const Any& G3D::Any::operator[] ( const String key) const

For a table, returns the element for key.

Throws KeyNotFound exception if the element does not exist.

◆ operator[]() [4/6]

const Any& G3D::Any::operator[] ( const char *  key) const
inline

◆ operator[]() [5/6]

Any& G3D::Any::operator[] ( const String key)

Fetch an element from a table.

This can be used as:

a["key"] = value;  (create the key if it did not exist)

or

value = a["key"];  (throw an error if the key did not exist)

Note: In order to cause elements to be correctly created in the first case while still providing "key not found" errors in the second case, the Any returned is a special object that delays the actual fetch until the following assignment or method call. This means that in the event of an error, the exception may be thrown from a line other than the actual fetch. Use the Any::get() or the const Any::operator[]() methods to avoid this behavior and ensure error-checking at fetch time.

◆ operator[]() [6/6]

Any& G3D::Any::operator[] ( const char *  key)
inline

Fetch an element from a table.

This can be used as:

a["key"] = value;  (create the key if it did not exist)

or

value = a["key"];  (throw an error if the key did not exist)

Note: In order to cause elements to be correctly created in the first case while still providing "key not found" errors in the second case, the Any returned is a special object that delays the actual fetch until the following assignment or method call. This means that in the event of an error, the exception may be thrown from a line other than the actual fetch. Use the Any::get() or the const Any::operator[]() methods to avoid this behavior and ensure error-checking at fetch time.

◆ parse()

static Any G3D::Any::parse ( const String src)
static

Same as deserialize or load, but operates on a string instead of a stream or file.

See also
deserialize, load, unparse

◆ remove() [1/2]

void G3D::Any::remove ( const String key)

Removes this key from the Any, which must be a table.

◆ remove() [2/2]

void G3D::Any::remove ( int  index)

Removes this key from the Any, which must be an array, and shifts other elements down to maintain order.

◆ resize()

void G3D::Any::resize ( int  n)

Resize to n elements, where new elements are NIL It is an error to call this method if this is not an Any::ARRAY.

Referenced by Any(), and operator=().

◆ resolveStringAsFilename()

String G3D::Any::resolveStringAsFilename ( bool  errorIfNotFound = true) const

If a valid string, takes the string value and creates a fully qualified filename.

The file is searched for the following ways:

  • In the directory from which the Any was loaded.
  • By calling System::findDataFile as you would with other data files.

Strings that begin with '<' and end with '>' are treated as escape sequences and are returned unmodifed.

Referenced by G3D::AnyTableReader::getFilenameIfPresent().

◆ save()

void G3D::Any::save ( const String filename,
bool  json = false 
) const

Uses the serialize method.

If the extension is ".json", uses JSON format with coercion, otherwise uses native Any format.

◆ serialize() [1/2]

void G3D::Any::serialize ( TextOutput to,
bool  json = false,
bool  coerce = false 
) const
Parameters
coerce.If json=true, should features that JSON doesn't support be coerced or produce errors?

◆ serialize() [2/2]

void G3D::Any::serialize ( class BinaryOutput b) const

◆ set()

template<class T >
void G3D::Any::set ( const String key,
const T &  val 
)
inline

For a table, assigns the element for key k.

◆ setComment()

void G3D::Any::setComment ( const String c)

◆ setName()

void G3D::Any::setName ( const String name)

Set the name used when serializing an ARRAY or TABLE.

Only legal for ARRAY or TABLE. The name must begin with a letter and contain only letters, numbers, underscores and scope operators.

 a2z
 hello
 Foo::bar
 color.red
 this->that
 __x
 

The scope operators "::", "->", and ".", may have spaces around them. The name may not contain parentheses.

Referenced by Any().

◆ size()

int G3D::Any::size ( ) const

Number of elements if this is an ARRAY or TABLE.

Referenced by getArray(), G3D::AnyTableReader::hasMore(), and last().

◆ source()

const Source& G3D::Any::source ( ) const

◆ sourceDirectory()

String G3D::Any::sourceDirectory ( ) const

The parent directory of the location from which this Any was loaded.

This is useful for interpreting filenames relative to the Any's source location, which may not match the current directory if the Any was from an included file.

◆ string()

const String& G3D::Any::string ( ) const

◆ table()

const Table<String, Any>& G3D::Any::table ( ) const

Directly exposes the underlying data structure for table.

See also
G3D::AnyTableReader

Referenced by getTable().

◆ toString()

static String G3D::Any::toString ( Type  t)
static

◆ type()

Type G3D::Any::type ( ) const

◆ unparse()

String G3D::Any::unparse ( const TextOutput::Settings s = TextOutput::Settings()) const

◆ unparseJSON()

String G3D::Any::unparseJSON ( const TextOutput::Settings s = TextOutput::Settings(),
bool  allowCoercion = true 
) const
Parameters
allowCoercionIf false, throws an error if the Any uses features that are not supported by JSON such as named arrays. Otherwise, silently coerces to JSON.

◆ verify()

void G3D::Any::verify ( bool  value,
const String message = "" 
) const

Throws a ParseError if value is false.

Useful for quickly creating parse rules in classes that deserialize from Any.

◆ verifyName() [1/4]

void G3D::Any::verifyName ( const String n) const

Verifies that the name is identifier n (case sensitive).

It may contain identifier operators after this

◆ verifyName() [2/4]

void G3D::Any::verifyName ( const String n,
const String m 
) const

Verifies that the name is identifier n or m (case sensitive).

It may contain identifier operators after this

◆ verifyName() [3/4]

void G3D::Any::verifyName ( const String n,
const String m,
const String p 
) const

Verifies that the name is identifier n or m or p (case sensitive).

It may contain identifier operators after this

◆ verifyName() [4/4]

void G3D::Any::verifyName ( const String n,
const String m,
const String p,
const String q 
) const

Verifies that the name is identifier n or m or p or q (case sensitive).

It may contain identifier operators after this

◆ verifyNameBeginsWith() [1/7]

void G3D::Any::verifyNameBeginsWith ( const String n) const

Verifies that the name begins with identifier n (case sensitive).

It may contain identifier operators after this

◆ verifyNameBeginsWith() [2/7]

void G3D::Any::verifyNameBeginsWith ( const String n,
const String m 
) const

Verifies that the name begins with identifier n or m (case sensitive).

It may contain identifier operators after this

◆ verifyNameBeginsWith() [3/7]

void G3D::Any::verifyNameBeginsWith ( const String n,
const String m,
const String p 
) const

Verifies that the name begins with identifier n or m or p (case sensitive).

It may contain identifier operators after this

◆ verifyNameBeginsWith() [4/7]

void G3D::Any::verifyNameBeginsWith ( const String n,
const String m,
const String p,
const String q 
) const

Verifies that the name begins with identifier n or m or p or q (case sensitive).

It may contain identifier operators after this

◆ verifyNameBeginsWith() [5/7]

void G3D::Any::verifyNameBeginsWith ( const String n,
const String m,
const String p,
const String q,
const String r 
) const

Verifies that the name begins with identifier n or m or p or q or r (case sensitive).

It may contain identifier operators after this

◆ verifyNameBeginsWith() [6/7]

void G3D::Any::verifyNameBeginsWith ( const String n,
const String m,
const String p,
const String q,
const String r,
const String s 
) const

Verifies that the name begins with identifier n or m or p or q or r or s (case sensitive).

It may contain identifier operators after this

◆ verifyNameBeginsWith() [7/7]

void G3D::Any::verifyNameBeginsWith ( const String n,
const String m,
const String p,
const String q,
const String r,
const String s,
const String t 
) const

Verifies that the name begins with identifier n or m or p or q or r or s or t(case sensitive).

It may contain identifier operators after this

◆ verifySize() [1/2]

void G3D::Any::verifySize ( int  low,
int  high 
) const

Verifies that the size is between low and high, inclusive.

◆ verifySize() [2/2]

void G3D::Any::verifySize ( int  s) const

Verifies that the size is exactly s.

◆ verifyType() [1/2]

void G3D::Any::verifyType ( Type  t) const

Verifies that the type is t.

Referenced by getArray(), and getTable().

◆ verifyType() [2/2]

void G3D::Any::verifyType ( Type  t0,
Type  t1 
) const

Throws an exception if the type is not t0 or t1.


documentation generated on Wed Nov 24 2021 08:01:53 using doxygen 1.8.15