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 Attributes | List of all members
Menge::Attribute Class Referenceabstract

An element attribute. More...

#include <Attribute.h>

Inheritance diagram for Menge::Attribute:
Menge::BoolAttribute Menge::FloatAttribute Menge::FloatDistributionAttribute Menge::IntAttribute Menge::IntDistributionAttribute Menge::SizeTAttribute Menge::StringAttribute Menge::Vec2DDistributionAttribute

Public Member Functions

 Attribute (const std::string &name, bool required)
 Constructor. More...
 
virtual ~Attribute ()
 Destructor.
 
virtual bool extract (TiXmlElement *node)=0
 Extracts the values for this attribute from the xml node. More...
 
const std::string & getName () const
 Returns a const reference to the name of the attribute. More...
 
bool isRequired () const
 Reports if this attribute is required to be specified. More...
 
bool isValid () const
 Reports if the attribute is valid. More...
 
void clear ()
 Prepares the attribute for a parse attempt.
 
virtual void setDefault ()=0
 If defined, sets the default value for the attribute.
 
virtual int getInt ()
 Retrieve the parsed int value. More...
 
virtual bool getBool ()
 Retrieve the parsed boolean value. More...
 
virtual float getFloat ()
 Retrieve the parsed float value. More...
 
virtual std::string getString ()
 Retrieve the parsed string value. More...
 
virtual size_t getSizeT ()
 Retrieve the parsed size_t value. More...
 
virtual FloatGeneratorgetFloatGenerator ()
 Retrieve the parsed float generator. More...
 
virtual Vec2DGeneratorgetVec2DGenerator ()
 Retrieve the parsed 2D float generator. More...
 
virtual IntGeneratorgetIntGenerator ()
 Retrieve the parsed int generator. More...
 

Protected Attributes

std::string _name
 The name of the xml attribute.
 
bool _required
 Determines if the XML must specify this attribute.
 
bool _valid
 Reports if the attribute is valid. An attribute is always valid if it is not required. Otherwise, it is only valid if it was able to be initialized from the XML.
 

Detailed Description

An element attribute.

This serves as a simple mechanism to configure XML parsing for elements who only require simple xml-parameter-style arguments. See AttributeSet for proper user. This is the entity responsible for parsing the XML and extracting the value specified.

The Attribute also stores the parsed value and reports on its own "validity". The validity of an Attribute is based on whether it is set to be "required" (i.e., the user must explicitly specify a value). If a required attribute is not defined in the XML, then it is invalid.

Constructor & Destructor Documentation

Menge::Attribute::Attribute ( const std::string &  name,
bool  required 
)
inline

Constructor.

Parameters
nameThe attribute name - used in parsing XML attributes.
requiredWhether or not the attribute is required (true) or not (false).

Member Function Documentation

virtual bool Menge::Attribute::extract ( TiXmlElement *  node)
pure virtual

Extracts the values for this attribute from the xml node.

This is the main parsing work. It must be performed by each attribute sub-class.

Parameters
nodeThe XML node containing the attributes.
Returns
True on sucessful extraction, false otherwise.

Implemented in Menge::IntDistributionAttribute, Menge::Vec2DDistributionAttribute, Menge::FloatDistributionAttribute, Menge::SizeTAttribute, Menge::BoolAttribute, Menge::FloatAttribute, Menge::IntAttribute, and Menge::StringAttribute.

virtual bool Menge::Attribute::getBool ( )
inlinevirtual

Retrieve the parsed boolean value.

If the type of this attribute is not a bool, an exception will be thrown.

Returns
The boolean value.
Exceptions
AnAttributeDefinitionException if the types are wrong.

Reimplemented in Menge::BoolAttribute.

virtual float Menge::Attribute::getFloat ( )
inlinevirtual

Retrieve the parsed float value.

If the type of this attribute is not a float, an exception will be thrown.

Returns
The float value.
Exceptions
AnAttributeDefinitionException if the types are wrong.

Reimplemented in Menge::FloatAttribute.

virtual FloatGenerator* Menge::Attribute::getFloatGenerator ( )
inlinevirtual

Retrieve the parsed float generator.

If the type of this attribute is not a float generator, an exception will be thrown.

Returns
A pointer to a float generator. The float generator becomes the responsibility of the caller.
Exceptions
AnAttributeDefinitionException if the types are wrong.

Reimplemented in Menge::FloatDistributionAttribute.

virtual int Menge::Attribute::getInt ( )
inlinevirtual

Retrieve the parsed int value.

If the type of this attribute is not an int, an exception will be thrown.

Returns
The int value.
Exceptions
AnAttributeDefinitionException if the types are wrong.

Reimplemented in Menge::IntAttribute.

virtual IntGenerator* Menge::Attribute::getIntGenerator ( )
inlinevirtual

Retrieve the parsed int generator.

If the type of this attribute is not an int generator, an exception will be thrown.

Returns
A pointer to a float generator. The float generator becomes the responsibility of the caller.
Exceptions
AnAttributeDefinitionException if the types are wrong.

Reimplemented in Menge::IntDistributionAttribute.

const std::string& Menge::Attribute::getName ( ) const
inline

Returns a const reference to the name of the attribute.

Returns
The name of the attribute.
virtual size_t Menge::Attribute::getSizeT ( )
inlinevirtual

Retrieve the parsed size_t value.

If the type of this attribute is not a size_t, an exception will be thrown.

Returns
The size_t value.
Exceptions
AnAttributeDefinitionException if the types are wrong.

Reimplemented in Menge::SizeTAttribute.

virtual std::string Menge::Attribute::getString ( )
inlinevirtual

Retrieve the parsed string value.

If the type of this attribute is not a string, an exception will be thrown.

Returns
The string value.
Exceptions
AnAttributeDefinitionException if the types are wrong.

Reimplemented in Menge::StringAttribute.

virtual Vec2DGenerator* Menge::Attribute::getVec2DGenerator ( )
inlinevirtual

Retrieve the parsed 2D float generator.

Returns
A pointer to a 2D float generator. The float generator becomes the responsibility of the caller.
Exceptions
AnAttributeDefinitionException if the types are wrong.

Reimplemented in Menge::Vec2DDistributionAttribute.

bool Menge::Attribute::isRequired ( ) const
inline

Reports if this attribute is required to be specified.

Returns
True if this attribute must be specified, false otherwise.
bool Menge::Attribute::isValid ( ) const
inline

Reports if the attribute is valid.

Returns
True if the attribute is properly initialized, false otherwise.

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