Support Forum       G3D Web Page     
Public Member Functions | List of all members
G3D::AnyTableReader Class Reference

Convenient iteration over the keys of a Any::TABLE, usually for implementing construction of an object from an Any. More...

Public Member Functions

 AnyTableReader (const String &name, const Any &a)
 Verifies that is a TABLE with the given name. More...
 
 AnyTableReader (const Any &a)
 Verifies that is a TABLE. More...
 
const Anyany () const
 Return the underlying Any. More...
 
bool containsUnread (const String &s) const
 
void get (const String &s, String &v, const String &errMsg="")
 If key s appears in the any, reads its value into v and removes that key from the ones available to iterate over.
More...
 
void get (const String &s, uint8 &v, const String &errMsg="")
 If key s appears in the any, reads its value into v and removes that key from the ones available to iterate over.
More...
 
void get (const String &s, uint16 &v, const String &errMsg="")
 If key s appears in the any, reads its value into v and removes that key from the ones available to iterate over.
More...
 
template<class T >
void get (const String &s, Array< T > &v, const String &errMsg="")
 Read an entire array at once. More...
 
template<class T >
void get (const String &s, Table< String, T > &v, const String &errMsg="")
 Read an entire table at once. More...
 
template<class ValueType >
void get (const String &s, ValueType &v, const String &errMsg="")
 If key s appears in the any, reads its value into v and removes that key from the ones available to iterate over. More...
 
template<class ValueType >
void get (const String &s, ValueType &v, ValueType(*factory)(const Any &), const String &errMsg="")
 
bool getFilenameIfPresent (const String &s, String &v)
 Uses Any::resolveStringAsFilename. More...
 
template<class ValueType >
bool getIfPresent (const String &s, ValueType &v)
 Get the value associated with a key only if the key is actually present. More...
 
template<class ValueType >
bool getIfPresent (const String &s, ValueType &v, ValueType(*factory)(const Any &))
 
Helper method for reading values that depend on a factory design pattern. More...
 
bool hasMore () const
 
const Anyoperator[] (const String &s)
 Same as get() More...
 
void setReadStatus (const String &s, bool read)
 Force the flag used for detecting if a field has been read. More...
 
void verifyDone () const
 Verifies that all keys have been read. More...
 

Detailed Description

Convenient iteration over the keys of a Any::TABLE, usually for implementing construction of an object from an Any.

Getting an element using either iteration or explicit requests consumes that element from the iterator (but not from the Any!) It is an error to consume the same element more than once from the same iterator.

r.getIfPresent("enabled", enabled);
r.getIfPresent("showSamples", showSamples);
r.get("showTiles", showTiles);
r.verifyDone();

Constructor & Destructor Documentation

◆ AnyTableReader() [1/2]

G3D::AnyTableReader::AnyTableReader ( const String name,
const Any a 
)

Verifies that is a TABLE with the given name.

◆ AnyTableReader() [2/2]

G3D::AnyTableReader::AnyTableReader ( const Any a)

Verifies that is a TABLE.

Member Function Documentation

◆ any()

const Any& G3D::AnyTableReader::any ( ) const
inline

Return the underlying Any.

◆ containsUnread()

bool G3D::AnyTableReader::containsUnread ( const String s) const
inline
Returns
True if s is in the table and has not yet been read using get() or getIfPresent().

◆ get() [1/7]

void G3D::AnyTableReader::get ( const String s,
String v,
const String errMsg = "" 
)
inline

If key s appears in the any, reads its value into v and removes that key from the ones available to iterate over.

If key s does not appear in the any, throws a G3D::ParseError.

If a G3D::ParseError is thrown, errMsg (optional) is appended to the G3D::ParseError::message.

Assumes that if key s appears in the any it has not already been extracted by this iterator. If it has been read before, an assertion will fail in debug mode.

◆ get() [2/7]

void G3D::AnyTableReader::get ( const String s,
uint8 v,
const String errMsg = "" 
)
inline

If key s appears in the any, reads its value into v and removes that key from the ones available to iterate over.

If key s does not appear in the any, throws a G3D::ParseError.

If a G3D::ParseError is thrown, errMsg (optional) is appended to the G3D::ParseError::message.

Assumes that if key s appears in the any it has not already been extracted by this iterator. If it has been read before, an assertion will fail in debug mode.

◆ get() [3/7]

void G3D::AnyTableReader::get ( const String s,
uint16 v,
const String errMsg = "" 
)
inline

If key s appears in the any, reads its value into v and removes that key from the ones available to iterate over.

If key s does not appear in the any, throws a G3D::ParseError.

If a G3D::ParseError is thrown, errMsg (optional) is appended to the G3D::ParseError::message.

Assumes that if key s appears in the any it has not already been extracted by this iterator. If it has been read before, an assertion will fail in debug mode.

◆ get() [4/7]

template<class T >
void G3D::AnyTableReader::get ( const String s,
Array< T > &  v,
const String errMsg = "" 
)
inline

Read an entire array at once.

See also
get(const String& s, ValueType& v, const String& errMsg = "")

◆ get() [5/7]

template<class T >
void G3D::AnyTableReader::get ( const String s,
Table< String, T > &  v,
const String errMsg = "" 
)
inline

Read an entire table at once.

See also
get(const String& s, ValueType& v, const String& errMsg = "")

◆ get() [6/7]

template<class ValueType >
void G3D::AnyTableReader::get ( const String s,
ValueType &  v,
const String errMsg = "" 
)
inline

If key s appears in the any, reads its value into v and removes that key from the ones available to iterate over.

If key s does not appear in the any, throws a G3D::ParseError.

If a G3D::ParseError is thrown, errMsg (optional) is appended to the G3D::ParseError::message.

Assumes that if key s appears in the any it has not already been extracted by this iterator. If it has been read before, an assertion will fail in debug mode.

◆ get() [7/7]

template<class ValueType >
void G3D::AnyTableReader::get ( const String s,
ValueType &  v,
ValueType(*)(const Any &)  factory,
const String errMsg = "" 
)
inline
See also
getIfPresent(const String& s, ValueType& v, ValueType (*factory)(const Any&))
get(const String& s, ValueType& v, const String& errMsg = "")

◆ getFilenameIfPresent()

bool G3D::AnyTableReader::getFilenameIfPresent ( const String s,
String v 
)
inline

◆ getIfPresent() [1/2]

template<class ValueType >
bool G3D::AnyTableReader::getIfPresent ( const String s,
ValueType &  v 
)
inline

Get the value associated with a key only if the key is actually present.

If key s appears in the any, reads its value into v and removes that key from the ones available to iterate over.

If key s does not appear in the any, does nothing.

Assumes that if key s appears in the any it has not already been extracted by this iterator. If it has been read before, an assertion will fail in debug mode.

Returns
True if the value was read.

Referenced by G3D::Spline< UprightFrame >::init().

◆ getIfPresent() [2/2]

template<class ValueType >
bool G3D::AnyTableReader::getIfPresent ( const String s,
ValueType &  v,
ValueType(*)(const Any &)  factory 
)
inline


Helper method for reading values that depend on a factory design pattern.

E.g., replaces the idiom:

Any algorithmAny;
if (r.getIfPresent("algorithm", algorithmAny)) {
algorithm = Algorithm::create(algorithmAny);
}

with

r.getIfPresent("algorithm", algorithm, &Algorithm::create);
See also
get

◆ hasMore()

bool G3D::AnyTableReader::hasMore ( ) const
inline

◆ operator[]()

const Any& G3D::AnyTableReader::operator[] ( const String s)
inline

Same as get()

◆ setReadStatus()

void G3D::AnyTableReader::setReadStatus ( const String s,
bool  read 
)
inline

Force the flag used for detecting if a field has been read.

◆ verifyDone()

void G3D::AnyTableReader::verifyDone ( ) const

Verifies that all keys have been read.

Referenced by G3D::Spline< UprightFrame >::Spline().


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