Menge
Modular Pedestrian Simulation Framework for Research and Development
|
A set of attributes. More...
#include <AttributeSet.h>
Public Member Functions | |
AttributeSet () | |
Constructor. | |
~AttributeSet () | |
Destructor. | |
size_t | addBoolAttribute (const std::string &name, bool required, bool defValue=false) |
Adds a boolean attribute to the set. More... | |
size_t | addIntAttribute (const std::string &name, bool required, int defValue=0) |
Adds an integer attribute to the set. More... | |
size_t | addSizeTAttribute (const std::string &name, bool required, size_t defValue=0) |
Adds a size_t attribute to the set. More... | |
size_t | addFloatAttribute (const std::string &name, bool required, float defValue=0) |
Adds a float attribute to the set. More... | |
size_t | addFloatDistAttribute (const std::string &prefix, bool required, float defValue, float scale) |
Adds a float distribution attribute to the set. More... | |
size_t | addVec2DDistAttribute (bool required, const Vector2 &defValue, float scale=1.f) |
Adds a Vector2 distribution attribute to the set. More... | |
size_t | addIntDistAttribute (const std::string &prefix, bool required, int defValue=0) |
Adds an integer distribution attribute to the set. More... | |
size_t | addStringAttribute (const std::string &name, bool required, const std::string &defValue="") |
Adds an integer attribute to the set. More... | |
void | clear () |
Prepares the set to parse a new instance. | |
bool | extract (TiXmlElement *node) |
Parses the node for the given attributes. More... | |
int | getInt (size_t propID) |
Retrieve the int value from the given property ID. More... | |
size_t | getSizeT (size_t propID) |
Retrieve the size_t value from the given property ID. More... | |
bool | getBool (size_t propID) |
Retrieve the int value from the given property ID. More... | |
float | getFloat (size_t propID) |
Retrieve the float value from the given property ID. More... | |
std::string | getString (size_t propID) |
Retrieve the string value from the given property ID. More... | |
FloatGenerator * | getFloatGenerator (size_t propID) |
Retrieve the float generator from the given property ID. More... | |
Vec2DGenerator * | getVec2DGenerator (size_t propID) |
Retrieve the Vector2 generator from the given property ID. More... | |
IntGenerator * | getIntGenerator (size_t propID) |
Retrieve the int generator from the given property ID. More... | |
Protected Member Functions | |
bool | isUniqueName (const std::string &name) |
reports if the new attribute name clashes with a previous attribute name. | |
Protected Attributes | |
std::vector< Attribute * > | _attrs |
The attributes in the set. | |
A set of attributes.
This is a utility class for facilitating parsing XML specifications. It is used for elements who can be completely defined strictly via XML attributes in a single tag. It allows handling these types of specifications without explicitly dealing with the XML.
Making use of this utility is a two-step process. 1 Define the expected attributes. 2 Use the extracted values to initialize the agent.
Every element factory has a built-in attribute set (called _attrSet). In the factory's constructor, simply make calls into the attribute set providing the details of each desired attribute. The attribute set returns a unique identifier for each new attribute. Store these attributes, you will use them to extract the parsed values later.
In the setFromXML function, first, call the parent class's implementation of the function. If there is a parsing error, an exception will be automatically thrown. You don't need to catch it. The framework will catch the exception and respond accordingly. Assuming there is no exception, simply use the stored identifiers to extract values from the attribute set and set it to the instance.
size_t Menge::AttributeSet::addBoolAttribute | ( | const std::string & | name, |
bool | required, | ||
bool | defValue = false |
||
) |
Adds a boolean attribute to the set.
name | The attribute name. |
required | Whether or not the attribute is required (true) or not (false). |
defValue | The default value for the attribute if none is provided. This value will serve no purpose if required is passed true. |
An | AttributeDefinitionException if the attribute name is not unique. |
size_t Menge::AttributeSet::addFloatAttribute | ( | const std::string & | name, |
bool | required, | ||
float | defValue = 0 |
||
) |
Adds a float attribute to the set.
name | The attribute name. |
required | Whether or not the attribute is required (true) or not (false). |
defValue | The default value for the attribute if none is provided. This value will serve no purpose if required is passed true. |
An | AttributeDefinitionException if the attribute name is not unique. |
size_t Menge::AttributeSet::addFloatDistAttribute | ( | const std::string & | prefix, |
bool | required, | ||
float | defValue, | ||
float | scale | ||
) |
Adds a float distribution attribute to the set.
prefix | The prefix for the distribution (provide the empty string to use defaults.) |
required | Whether or not the attribute is required (true) or not (false). |
defValue | The default value for the attribute if none is provided. This value will serve no purpose if required is passed true. |
scale | The scale value for this distribution. |
An | AttributeDefinitionException if the attribute name is not unique. |
size_t Menge::AttributeSet::addIntAttribute | ( | const std::string & | name, |
bool | required, | ||
int | defValue = 0 |
||
) |
Adds an integer attribute to the set.
name | The attribute name. |
required | Whether or not the attribute is required (true) or not (false). |
defValue | The default value for the attribute if none is provided. This value will serve no purpose if required is passed true. |
An | AttributeDefinitionException if the attribute name is not unique. |
size_t Menge::AttributeSet::addIntDistAttribute | ( | const std::string & | prefix, |
bool | required, | ||
int | defValue = 0 |
||
) |
Adds an integer distribution attribute to the set.
prefix | The prefix for the distribution (provide the empty string to use defaults.) |
required | Whether or not the attribute is required (true) or not (false). |
defValue | The default value for the attribute if none is provided. This value will serve no purpose if required is passed true. |
An | AttributeDefinitionException if the attribute name is not unique. |
size_t Menge::AttributeSet::addSizeTAttribute | ( | const std::string & | name, |
bool | required, | ||
size_t | defValue = 0 |
||
) |
Adds a size_t attribute to the set.
name | The attribute name. |
required | Whether or not the attribute is required (true) or not (false). |
defValue | The default value for the attribute if none is provided. This value will serve no purpose if required is passed true. |
An | AttributeDefinitionException if the attribute name is not unique. |
size_t Menge::AttributeSet::addStringAttribute | ( | const std::string & | name, |
bool | required, | ||
const std::string & | defValue = "" |
||
) |
Adds an integer attribute to the set.
name | The attribute name. |
required | Whether or not the attribute is required (true) or not (false). |
defValue | The default value for the attribute if none is provided. This value will serve no purpose if required is passed true. |
An | AttributeDefinitionException if the attribute name is not unique. |
size_t Menge::AttributeSet::addVec2DDistAttribute | ( | bool | required, |
const Vector2 & | defValue, | ||
float | scale = 1.f |
||
) |
Adds a Vector2 distribution attribute to the set.
required | Whether or not the attribute is required (true) or not (false). |
defValue | The default value for the attribute if none is provided. This value will serve no purpose if required is passed true. |
scale | The optional scale value for this distribution. |
An | AttributeDefinitionException if the attribute name is not unique. |
bool Menge::AttributeSet::extract | ( | TiXmlElement * | node | ) |
Parses the node for the given attributes.
node | The XML node containing the attributes. |
bool Menge::AttributeSet::getBool | ( | size_t | propID | ) |
Retrieve the int value from the given property ID.
If the attribute associated with the given property ID is of the wrong type, this will throw an exception.
propID | The property ID – this is given as the result of AttributeSet::addAttribute. |
An | AttributeDefinitionException if the types are wrong. |
float Menge::AttributeSet::getFloat | ( | size_t | propID | ) |
Retrieve the float value from the given property ID.
If the attribute associated with the given property ID is of the wrong type, this will throw an exception.
propID | The property ID – this is given as the result of AttributeSet::addAttribute. |
An | AttributeDefinitionException if the types are wrong. |
FloatGenerator * Menge::AttributeSet::getFloatGenerator | ( | size_t | propID | ) |
Retrieve the float generator from the given property ID.
If the attribute associated with the given property ID is of the wrong type, this will throw an exception.
propID | The property ID – this is given as the result of AttributeSet::addAttribute. |
An | AttributeDefinitionException if the types are wrong. |
int Menge::AttributeSet::getInt | ( | size_t | propID | ) |
Retrieve the int value from the given property ID.
If the attribute associated with the given property ID is of the wrong type, this will throw an exception.
propID | The property ID – this is given as the result of AttributeSet::addAttribute. |
An | AttributeDefinitionException if the types are wrong. |
IntGenerator * Menge::AttributeSet::getIntGenerator | ( | size_t | propID | ) |
Retrieve the int generator from the given property ID.
If the attribute associated with the given property ID is of the wrong type, this will throw an exception.
propID | The property ID – this is given as the result of AttributeSet::addAttribute. |
An | AttributeDefinitionException if the types are wrong. |
size_t Menge::AttributeSet::getSizeT | ( | size_t | propID | ) |
Retrieve the size_t value from the given property ID.
If the attribute associated with the given property ID is of the wrong type, this will throw an exception.
propID | The property ID – this is given as the result of AttributeSet::addAttribute. |
An | AttributeDefinitionException if the types are wrong. |
std::string Menge::AttributeSet::getString | ( | size_t | propID | ) |
Retrieve the string value from the given property ID.
If the attribute associated with the given property ID is of the wrong type, this will throw an exception.
propID | The property ID – this is given as the result of AttributeSet::addAttribute. |
An | AttributeDefinitionException if the types are wrong. |
Vec2DGenerator * Menge::AttributeSet::getVec2DGenerator | ( | size_t | propID | ) |
Retrieve the Vector2 generator from the given property ID.
If the attribute associated with the given property ID is of the wrong type, this will throw an exception.
propID | The property ID – this is given as the result of AttributeSet::addAttribute. |
An | AttributeDefinitionException if the types are wrong. |