Menge
Modular Pedestrian Simulation Framework for Research and Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Menge::AttributeSet Class Reference

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...
 
FloatGeneratorgetFloatGenerator (size_t propID)
 Retrieve the float generator from the given property ID. More...
 
Vec2DGeneratorgetVec2DGenerator (size_t propID)
 Retrieve the Vector2 generator from the given property ID. More...
 
IntGeneratorgetIntGenerator (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.
 

Detailed Description

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.

Member Function Documentation

size_t Menge::AttributeSet::addBoolAttribute ( const std::string &  name,
bool  required,
bool  defValue = false 
)

Adds a boolean attribute to the set.

Parameters
nameThe attribute name.
requiredWhether or not the attribute is required (true) or not (false).
defValueThe default value for the attribute if none is provided. This value will serve no purpose if required is passed true.
Returns
The unique identifier for this attribute.
Exceptions
AnAttributeDefinitionException 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.

Parameters
nameThe attribute name.
requiredWhether or not the attribute is required (true) or not (false).
defValueThe default value for the attribute if none is provided. This value will serve no purpose if required is passed true.
Returns
The unique identifier for this attribute.
Exceptions
AnAttributeDefinitionException 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.

Parameters
prefixThe prefix for the distribution (provide the empty string to use defaults.)
requiredWhether or not the attribute is required (true) or not (false).
defValueThe default value for the attribute if none is provided. This value will serve no purpose if required is passed true.
scaleThe scale value for this distribution.
Returns
The unique identifier for this attribute.
Exceptions
AnAttributeDefinitionException 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.

Parameters
nameThe attribute name.
requiredWhether or not the attribute is required (true) or not (false).
defValueThe default value for the attribute if none is provided. This value will serve no purpose if required is passed true.
Returns
The unique identifier for this attribute.
Exceptions
AnAttributeDefinitionException 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.

Parameters
prefixThe prefix for the distribution (provide the empty string to use defaults.)
requiredWhether or not the attribute is required (true) or not (false).
defValueThe default value for the attribute if none is provided. This value will serve no purpose if required is passed true.
Returns
The unique identifier for this attribute.
Exceptions
AnAttributeDefinitionException 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.

Parameters
nameThe attribute name.
requiredWhether or not the attribute is required (true) or not (false).
defValueThe default value for the attribute if none is provided. This value will serve no purpose if required is passed true.
Returns
The unique identifier for this attribute.
Exceptions
AnAttributeDefinitionException 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.

Parameters
nameThe attribute name.
requiredWhether or not the attribute is required (true) or not (false).
defValueThe default value for the attribute if none is provided. This value will serve no purpose if required is passed true.
Returns
The unique identifier for this attribute.
Exceptions
AnAttributeDefinitionException 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.

Parameters
requiredWhether or not the attribute is required (true) or not (false).
defValueThe default value for the attribute if none is provided. This value will serve no purpose if required is passed true.
scaleThe optional scale value for this distribution.
Returns
The unique identifier for this attribute.
Exceptions
AnAttributeDefinitionException if the attribute name is not unique.
bool Menge::AttributeSet::extract ( TiXmlElement *  node)

Parses the node for the given attributes.

Parameters
nodeThe XML node containing the attributes.
Returns
True on sucessful extraction, false otherwise.
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.

Parameters
propIDThe property ID – this is given as the result of AttributeSet::addAttribute.
Returns
The boolean value.
Exceptions
AnAttributeDefinitionException 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.

Parameters
propIDThe property ID – this is given as the result of AttributeSet::addAttribute.
Returns
The float value.
Exceptions
AnAttributeDefinitionException 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.

Parameters
propIDThe property ID – this is given as the result of AttributeSet::addAttribute.
Returns
A pointer to the float generator. The caller now is responsible for the memory to which this pointer refers.
Exceptions
AnAttributeDefinitionException 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.

Parameters
propIDThe property ID – this is given as the result of AttributeSet::addAttribute.
Returns
The int value.
Exceptions
AnAttributeDefinitionException 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.

Parameters
propIDThe property ID – this is given as the result of AttributeSet::addAttribute.
Returns
A pointer to the int generator. The caller now is responsible for the memory to which this pointer refers.
Exceptions
AnAttributeDefinitionException 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.

Parameters
propIDThe property ID – this is given as the result of AttributeSet::addAttribute.
Returns
The size_t value.
Exceptions
AnAttributeDefinitionException 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.

Parameters
propIDThe property ID – this is given as the result of AttributeSet::addAttribute.
Returns
The int value.
Exceptions
AnAttributeDefinitionException 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.

Parameters
propIDThe property ID – this is given as the result of AttributeSet::addAttribute.
Returns
A pointer to the Vector2 generator. The caller now is responsible for the memory to which this pointer refers.
Exceptions
AnAttributeDefinitionException if the types are wrong.

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