Support for JSON export.
More...
Inherited by Hurricane::Cell::SlavedsRelation::JsonProperty, Hurricane::Cell::SlavedsRelation::JsonPropertyRef, Hurricane::Cell::UniquifyRelation::JsonProperty, Hurricane::Cell::UniquifyRelation::JsonPropertyRef, Hurricane::JsonBaseArray< T >, Hurricane::JsonBox, Hurricane::JsonDBo, Hurricane::JsonDummy, Hurricane::JsonEntityRef, Hurricane::JsonKey, Hurricane::JsonOccurrence, Hurricane::JsonPlugRef, Hurricane::JsonPoint, Hurricane::JsonTransformation, and Hurricane::StandardPrivateProperty< Value, JsonState >::JsonProperty.
◆ JsonObject()
Hurricane::JsonObject::JsonObject |
( |
unsigned long |
flags | ) |
|
- Parameters
-
flags | Flags sets by derived classes. |
Base object to be used by all JSON parsers. Provides helpers functions. Store three separated lists of requirements/attributes needes to build the object.
stackeds
: thoses are not attributes of the current object, but other objects that are expected to be already in the stack. They are needed to build the current object. Their key must start with a '
.' character.
attributes
: the simple attributes of the object. Their key must start with a '_'
.
collections
: any container, collection or whatever set of other objects part of the current object. Their key must start with a '+'
character.
For adding a requirement/attribute, see JsonObject::add().
◆ isDummy()
bool Hurricane::JsonObject::isDummy |
( |
| ) |
const |
|
virtual |
Returns: true if the concrete object is of type JsonDummy
, false otherwise.
◆ getTypeName()
string Hurricane::JsonObject::getTypeName |
( |
| ) |
const |
|
pure virtual |
Returns: The typename of the concrete object, that is, the value of the @typename
key of the JSON object.
◆ getStackName()
std::string Hurricane::JsonObject::getStackName |
( |
| ) |
const |
|
inline |
Returns: The key with which the DataBase object will be pushed on the parser stack.
If the current object is associated to an attribute (that is, a key in JSON), then the name
attribute of the JsonObject should have been set, and it will be returned here.
If the name
attribute has not been set (for example, because we are in an array). Then the typename (JsonObject::getTypeName()), prefixed by a '
.' character will be returned.
If the JsonObject is, for instance, a JsonBox (typename: "Box"
) :
- If
name
is set to "_abutmentBox"
, the box will be stacked with that key.
- If
name
is not set, then the key will be ".Box"
.
Referenced by update().
◆ check()
bool Hurricane::JsonObject::check |
( |
JsonStack & |
, |
|
|
std::string |
fname |
|
) |
| const |
- Parameters
-
stack | Where the objects already parsed are stored. |
fname | The function name on behalf of which the check is performed. |
- Returns
- true if the check is successful.
Check that the stack
actually contains all the objects (i.e. attributes) needed to build the current object. The list of attributes is built using the JsonObject::add() function. If an attribute is missing, a warning is issued, but the parser will try to continue.
◆ has()
bool Hurricane::JsonObject::has |
( |
const std::string & |
key | ) |
const |
- Parameters
-
key | The key name to search for. |
- Returns
- true if the object possess such a key.
◆ add()
void Hurricane::JsonObject::add |
( |
const std::string & |
key, |
|
|
std::type_index |
tid |
|
) |
| |
- Parameters
-
key | The requirement/attribute to add. |
tid | The type index of the attribute. |
Adds a new requirement or attribute to the object. The first character of the key tells which kind it is:
'
.' : a requirement (not part of the object) that must be present in the stack.
'_'
: a simple attribute of the object.
'+'
: belongs to a collection or container.
A more detailed description could be found in JsonObject::JsonObject().
◆ remove()
void Hurricane::JsonObject::remove |
( |
const std::string & |
key | ) |
|
- Parameters
-
key | The key of the requirement/attribute to remove. |
Removes an attribute from the current object.
◆ get()
template<typename T >
T Hurricane::JsonObject::get |
( |
JsonStack & |
stack, |
|
|
const std::string & |
key |
|
) |
| const |
|
inline |
- Parameters
-
stack | The object stack of the parser. |
key | The key of the requested object. |
- Returns
- The first object associated with
key
, starting from the top of the stack.
Retrieve requirements or attributes from the parser stack.
- If no element with a corresponding key is found, an empty element of type
T
is returned (by calling the default T
constructor).
- If an element matching the key is found, but it's type do not match
T
, an exception from any_cast<>
will be thrown.
References Hurricane::JsonStack::as(), and Hurricane::JsonStack::rhas().
◆ jget()
template<typename T >
T * Hurricane::JsonObject::jget |
( |
JsonStack & |
stack | ) |
const |
|
inline |
- Parameters
-
stack | The parser stack. Returns: the first JsonObject that can be cast into type T* . |
Search the JsonObject stack, from the top, the first object that can be cast into type T*
. Base classes can be used here, as the dynamic_cast<>
operator is used to perform the casts.
This function always return a pointer (never a value).
References Hurricane::JsonStack::jobjects().
◆ copyAttrs()
void Hurricane::JsonObject::copyAttrs |
( |
const JsonObject * |
other, |
|
|
bool |
reset = false |
|
) |
| |
|
inline |
- Parameters
-
other | The object from which to copy attributes. |
reset | Whether to keep or erase the original attributes of the object. |
Copy the attributes from other
into the current object. Only the attributes are copied. Neither the requirements, nor the collections. By default, the attributes are added to the existing one of the object, but if reset
is true, the original ones will be suppresseds.
◆ clear()
void Hurricane::JsonObject::clear |
( |
| ) |
|
|
inline |
Removes all requirements/attributes/collections of the object. Also unbind it from any generated DataBase object.
◆ getName()
std::string Hurricane::JsonObject::getName |
( |
| ) |
const |
|
inline |
Returns: The name of the whole object as attribute.
During the parsing of the JSON structure, excepted when in an array, an object is associated with a key. This is the string returned by this function. It is called getName()
instead of getKey()
to avoid confusing with the attributes keys.
◆ setName()
void Hurricane::JsonObject::setName |
( |
const std::string & |
| ) |
|
|
inline |
- Parameters
-
name | Set the key associated to this object. |
See JsonObject::getName() for the meaning of the name (key).
◆ getObject()
template<typename T >
T Hurricane::JsonObject::getObject |
|
inline |
Returns: The associated DataBase object.
Once all the attributes have been gathered, the creation of the DataBase object is triggered by calling JsonObject::toData(). We keep track of that DataBase object by storing it (or a pointer to it) in an boost::any
field of the JsonObject.
◆ setObject()
template<typename T >
void Hurricane::JsonObject::setObject |
( |
T |
t | ) |
|
|
inline |
- Parameters
-
Associate the constructed DataBase object T
to the JSON object (for later access).
◆ isBound()
bool Hurricane::JsonObject::isBound |
( |
| ) |
const |
|
inline |
◆ clone()
JsonObject * Hurricane::JsonObject::clone |
( |
unsigned long |
flags | ) |
const |
|
pure virtual |
Returns: a new empty object of the same dynamic type as the source one.
This is not a true clone operation in the sense that the datas of the original object are not copied. The cloning is about the type, and is the result of a call to the new
operator.
\Important This method must be overloaded in each concrete derived class.
◆ toData()
void Hurricane::JsonObject::toData |
( |
JsonStack & |
stack | ) |
|
|
virtual |
- Parameters
-
\Important This method must be overloaded in each concrete derived class.
Creates the DataBase object. The requirements and attributes must be on top of the stack, they are popped, the DataBase object is created from them and the result is then pushed back.
◆ presetId()
unsigned int Hurricane::JsonObject::presetId |
( |
JsonStack & |
stack | ) |
|
- Parameters
-
stack | The parser object stack. Returns: the next id that has been set. |
\Remark This is a helper for JsonStack::toData().
In blob mode, the DataBase must be restored as is, including the ids
of all the Entities (see Entity). This function read from the stack the _id
attribute and sets it so that the next Entity created will use it.
◆ update()
template<typename T >
void Hurricane::JsonObject::update |
( |
JsonStack & |
stack, |
|
|
T |
hobject |
|
) |
| |
|
inline |
◆ setFlags()
JsonObject * Hurricane::JsonObject::setFlags |
( |
unsigned long |
mask | ) |
|
|
inline |
- Parameters
-
mask | Flag(s) to be raised. |
- Returns
- The current object.
◆ resetFlags()
JsonObject * Hurricane::JsonObject::resetFlags |
( |
unsigned long |
mask | ) |
|
|
inline |
- Parameters
-
mask | Flag(s) to be lowered. |
- Returns
- The current object.
◆ issetFlags()
bool Hurricane::JsonObject::issetFlags |
( |
unsigned long |
mask | ) |
const |
|
inline |
- Parameters
-
mask | The combination of flags to be checked. |
- Returns
- true if all the flags given in
mask
are sets.
The documentation for this class was generated from the following files: