TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
G3D::AnyTableReader Class Reference

#include <Any.h>

Public Member Functions

 AnyTableReader (const std::string &name, const Any &a)
 
 AnyTableReader (const Any &a)
 
bool hasMore () const
 
void verifyDone () const
 
const Anyany () const
 
void get (const std::string &s, std::string &v)
 
void get (const std::string &s, uint8 &v)
 
void get (const std::string &s, uint16 &v)
 
template<class T >
void get (const std::string &s, Array< T > &v)
 
template<class T >
void get (const std::string &s, Table< std::string, T > &v)
 
template<class ValueType >
void get (const std::string &s, ValueType &v)
 
const Anyoperator[] (const std::string &s)
 
template<class ValueType >
bool getIfPresent (const std::string &s, ValueType &v)
 
bool containsUnread (const std::string &s) const
 

Private Attributes

Any m_any
 
Set< std::string > m_alreadyRead
 

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

G3D::AnyTableReader::AnyTableReader ( const std::string &  name,
const Any a 
)

Verifies that is a TABLE with the given name.

6  : m_any(a) {
7  try {
9  m_any.verifyName(name);
10  } catch (const ParseError& e) {
11  // If an exception is thrown, the destructors will not be
12  // invoked automatically.
13  m_any.~Any();
15  throw e;
16  }
17 }
Definition: Any.h:187
Any m_any
Definition: Any.h:892
Set< std::string > m_alreadyRead
Definition: Any.h:893
virtual ~Set()
Definition: Set.h:48
void verifyType(Type t) const
Definition: Any.cpp:1739
void verifyName(const std::string &n) const
Definition: Any.cpp:1637
~Any()
Definition: Any.cpp:443

+ Here is the call graph for this function:

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

Verifies that is a TABLE.

20  : m_any(a) {
21  try {
23  } catch (const ParseError& e) {
24  // If an exception is thrown, the destructors will not be
25  // invoked automatically.
26  m_any.~Any();
28  throw e;
29  }
30 }
Definition: Any.h:187
Any m_any
Definition: Any.h:892
Set< std::string > m_alreadyRead
Definition: Any.h:893
virtual ~Set()
Definition: Set.h:48
void verifyType(Type t) const
Definition: Any.cpp:1739
~Any()
Definition: Any.cpp:443

+ Here is the call graph for this function:

Member Function Documentation

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

Return the underlying Any.

910  {
911  return m_any;
912  }
Any m_any
Definition: Any.h:892
bool G3D::AnyTableReader::containsUnread ( const std::string &  s) const
inline
Returns
True if s is in the table and has not yet been read using get() or getIfPresent().
1002  {
1003  return m_any.containsKey(s) && ! m_alreadyRead.contains(s);
1004  }
bool containsKey(const std::string &key) const
Definition: Any.cpp:313
Any m_any
Definition: Any.h:892
bool contains(const T &member) const
Definition: Set.h:54
Set< std::string > m_alreadyRead
Definition: Any.h:893

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void G3D::AnyTableReader::get ( const std::string &  s,
std::string &  v 
)
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.

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.

925  {
926  v = m_any[s].string();
928  }
const std::string & string() const
Definition: Any.cpp:548
Any m_any
Definition: Any.h:892
Set< std::string > m_alreadyRead
Definition: Any.h:893
bool insert(const T &member)
Definition: Set.h:62

+ Here is the call graph for this function:

void G3D::AnyTableReader::get ( const std::string &  s,
uint8 v 
)
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.

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.

931  {
932  v = uint8(m_any[s].number());
934  }
Any m_any
Definition: Any.h:892
Set< std::string > m_alreadyRead
Definition: Any.h:893
bool insert(const T &member)
Definition: Set.h:62
uint8_t uint8
Definition: g3dmath.h:164

+ Here is the call graph for this function:

void G3D::AnyTableReader::get ( const std::string &  s,
uint16 v 
)
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.

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.

937  {
938  v = uint16(m_any[s].number());
940  }
Any m_any
Definition: Any.h:892
Set< std::string > m_alreadyRead
Definition: Any.h:893
uint16_t uint16
Definition: g3dmath.h:166
bool insert(const T &member)
Definition: Set.h:62

+ Here is the call graph for this function:

template<class T >
void G3D::AnyTableReader::get ( const std::string &  s,
Array< T > &  v 
)
inline

Read an entire array at once.

944  {
945  m_any[s].getArray(v);
947  }
Any m_any
Definition: Any.h:892
Set< std::string > m_alreadyRead
Definition: Any.h:893
bool insert(const T &member)
Definition: Set.h:62
void getArray(Array< T > &array) const
Definition: Any.h:840

+ Here is the call graph for this function:

template<class T >
void G3D::AnyTableReader::get ( const std::string &  s,
Table< std::string, T > &  v 
)
inline
950  {
951  m_any[s].getTable(v);
953  }
void getTable(Table< std::string, T > &table) const
Definition: Any.h:850
Any m_any
Definition: Any.h:892
Set< std::string > m_alreadyRead
Definition: Any.h:893
bool insert(const T &member)
Definition: Set.h:62

+ Here is the call graph for this function:

template<class ValueType >
void G3D::AnyTableReader::get ( const std::string &  s,
ValueType &  v 
)
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.

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.

965  {
966  v = ValueType(m_any[s]);
968  }
Any m_any
Definition: Any.h:892
Set< std::string > m_alreadyRead
Definition: Any.h:893
bool insert(const T &member)
Definition: Set.h:62

+ Here is the call graph for this function:

template<class ValueType >
bool G3D::AnyTableReader::getIfPresent ( const std::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.
989  {
990  if (m_any.containsKey(s)) {
991  debugAssertM(! m_alreadyRead.contains(s), "read twice");
992 
993  get(s, v);
994  return true;
995  } else {
996  return false;
997  }
998  }
bool containsKey(const std::string &key) const
Definition: Any.cpp:313
Any m_any
Definition: Any.h:892
bool contains(const T &member) const
Definition: Set.h:54
Set< std::string > m_alreadyRead
Definition: Any.h:893
#define debugAssertM(exp, message)
Definition: debugAssert.h:161

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool G3D::AnyTableReader::hasMore ( ) const
inline
902  {
903  return m_any.size() > m_alreadyRead.size();
904  }
Any m_any
Definition: Any.h:892
Set< std::string > m_alreadyRead
Definition: Any.h:893
int size() const
Definition: Set.h:50
int size() const
Definition: Any.cpp:580

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Same as get()

971  {
973  return m_any[s];
974  }
Any m_any
Definition: Any.h:892
Set< std::string > m_alreadyRead
Definition: Any.h:893
bool insert(const T &member)
Definition: Set.h:62

+ Here is the call graph for this function:

void G3D::AnyTableReader::verifyDone ( ) const

Verifies that all keys have been read.

33  {
34  if (hasMore()) {
35  // Some entries were unread. Find them.
36  const Table<std::string, Any>& table = m_any.table();
37 
38  for (Table<std::string, Any>::Iterator it = table.begin();
39  it.hasMore();
40  ++it) {
41 
42  if (containsUnread(it->key)) {
43  it->value.verify(false, std::string("Unread Any table key \"") + it->key + "\"");
44  }
45  }
46  }
47 }
bool containsUnread(const std::string &s) const
Definition: Any.h:1002
Any m_any
Definition: Any.h:892
const Table< std::string, Any > & table() const
Definition: Any.cpp:706
bool hasMore() const
Definition: Any.h:902

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

Set<std::string> G3D::AnyTableReader::m_alreadyRead
private
Any G3D::AnyTableReader::m_any
private

The documentation for this class was generated from the following files: