JSON Parser Stack.
More...
JSON Parser Stack.
The JSON parser stack contains three separate stacks and a lookup table:
- The
attribute
stack. Objects that have been translated from JSON to the Hurricane database (or POD objects).
- The
dbo
stack, similar to the previous one, but contains only objects whose base class is DBo.
- The JsonObject stack. The stack of objects currently under parsing.
- A lookup table for the Entity, between the Hurricane
id
and the JSON id
.
◆ size()
size_t Hurricane::JsonStack::size |
( |
| ) |
const |
|
inline |
Returns: The size of the attribute stack.
◆ push_back()
template<typename T >
void Hurricane::JsonStack::push_back |
( |
const std::string & |
key, |
|
|
T |
hobject |
|
) |
| |
|
inline |
◆ pop_back()
void Hurricane::JsonStack::pop_back |
( |
size_t |
count = 1 | ) |
|
|
inline |
◆ rhas()
int Hurricane::JsonStack::rhas |
( |
const std::string & |
key | ) |
const |
|
inline |
- Parameters
-
key | The key element's to look for. |
- Returns
- the index of the element, from the top.
The function name's stands for "Reverse HAS". Search from the top of the attribute stack downward an element with key
. Return an index from the top of the stack, that is, the end of the vector. The returned index is a negative value, for exemple the element on top of the stack has an index of -1
. If no element with a matching key is found, returns 0.
References Hurricane::demangle().
Referenced by Hurricane::JsonObject::get().
◆ as() [1/2]
template<typename T >
T Hurricane::JsonStack::as |
( |
const std::string & |
key | ) |
const |
|
inline |
- Parameters
-
key | The key's element to search. |
- Returns
- The element, casted as type T.
Search an element with key matching key
, from the top of the stack. If found, returns the element casted as type T
. As the cast operation uses boost::any_cast<>
, the exact type T
must be used (not a base class of T
), otherwise the cast will fail and an exception will be thrown.
References Hurricane::demangle().
Referenced by Hurricane::JsonObject::get().
◆ as() [2/2]
template<typename T >
T Hurricane::JsonStack::as |
( |
int |
index | ) |
const |
|
inline |
- Parameters
-
index | the position of the element to convert. |
- Returns
- The element, casted as type T.
Cast the element at index
into type T. As the cast operation uses boost::any_cast<>
, the exact type T
must be used (not a base class of T
), otherwise the cast will fail and an exception will be thrown.
A positive or null index means the element must be taken from the bottom of the stack and a stictly negative one means from the top of the stack.
◆ push_back_dbo()
void Hurricane::JsonStack::push_back_dbo |
( |
DBo * |
dbo | ) |
|
|
inline |
- Parameters
-
Dedicated stack to push objects after they had been casted into the DBo* base class. We need to create this separate stack from the attribute stack due to the inability of boost::any_cast<>
to use a base class.
◆ pop_back_dbo()
void Hurricane::JsonStack::pop_back_dbo |
( |
| ) |
|
|
inline |
Remove one element from the top of the DBo* stack.
◆ back_dbo()
DBo * Hurricane::JsonStack::back_dbo |
( |
| ) |
const |
|
inline |
Returns: The elemet at the top of the DBo* stack.
◆ jobjects()
vector< JsonObject * > & Hurricane::JsonStack::jobjects |
( |
| ) |
|
|
inline |
◆ getEntity()
template<typename T >
T Hurricane::JsonStack::getEntity |
( |
unsigned int |
jsonId | ) |
const |
|
inline |
Returns: The entity, casted as type T
.
Find an Entity with the JSON id jsonId
and cast it into type T
.
Obviously, this Entity must have been registered with a call to addEntity() before.
◆ addEntity()
void Hurricane::JsonStack::addEntity |
( |
unsigned int |
jsonId, |
|
|
Entity * |
entity |
|
) |
| |
- Parameters
-
jsonId | the id of the Entity, in the JSON file |
entity | the associated Entity. |
When parsing a DataBase object not in blob mode, we cannot restore the ids of the Entities as they are in the file. Thus when an Entity is re-created, it comes with a different id. So we have to keep track of the association between this newbox id (in the Hurricane database) and the one in the JSON file.
This function adds such an association.
◆ print()
void Hurricane::JsonStack::print |
( |
std::ostream & |
o | ) |
const |
Dump the contents of the attribute stack int the stream o
. For debugging purposes.
The documentation for this class was generated from the following files: