ticpp::Element Class Reference

Wrapper around TiXmlElement. More...

#include <ticpp.h>

Inheritance diagram for ticpp::Element:

ticpp::NodeImp< TiXmlElement > ticpp::Node ticpp::Base

List of all members.

Public Member Functions

 Element ()
 Default Constructor.
 Element (const std::string &value)
 Default Constructor.
 Element (const char *value)
 Default Constructor.
 Element (TiXmlElement *element)
 Constructor.
template<class T>
 Element (const std::string &value, const T &text)
 Constructor that allows you to set the element text.
AttributeFirstAttribute (bool throwIfNoAttributes=true) const
 Access the first attribute in this element.
AttributeLastAttribute (bool throwIfNoAttributes=true) const
 Access the last attribute in this element.
template<class T>
void SetAttribute (const std::string &name, const T &value)
 Sets an attribute of name to a given value.
std::string GetText (bool throwIfNotFound=true) const
 Gets the text of an Element.
std::string GetTextOrDefault (const std::string &defaultValue) const
 Gets the text of an Element, if it doesn't exist it will return the defaultValue.
template<class T, class DefaultT>
void GetTextOrDefault (T *value, const DefaultT &defaultValue) const
 Gets the text value of an Element, if it doesn't exist it will return the defaultValue.
template<class T>
void GetText (T *value, bool throwIfNotFound=true) const
 Gets the text of an Element.
template<class T>
void SetText (const T &value)
 Convenience function to set the text of an element.
template<class T, class DefaulT>
void GetAttributeOrDefault (const std::string &name, T *value, const DefaulT &defaultValue) const
 Gets an attribute of name from an element, if it doesn't exist it will return the defaultValue.
std::string GetAttributeOrDefault (const std::string &name, const std::string &defaultValue) const
 Gets an attribute of name from an element, if it doesn't exist it will return the defaultValue.
template<class T>
GetAttribute (const std::string &name, bool throwIfNotFound=true) const
 Returns an attribute of name from an element.
template<class T>
void GetAttribute (const std::string &name, T *value, bool throwIfNotFound=true) const
 Gets an attribute of name from an element.
std::string GetAttribute (const std::string &name) const
 Gets an attribute of name from an element.
bool HasAttribute (const std::string &name) const
 Returns true, if attribute exists.
void RemoveAttribute (const std::string &name)
 Removes attribute from element.


Detailed Description

Wrapper around TiXmlElement.

Constructor & Destructor Documentation

ticpp::Element::Element ( const std::string &  value  ) 

Default Constructor.

Initializes all the variables.

Parameters:
value The value of the element.

ticpp::Element::Element ( const char *  value  ) 

Default Constructor.

Initializes all the variables.

Parameters:
value The value of the element.

template<class T>
ticpp::Element::Element ( const std::string &  value,
const T &  text 
) [inline]

Constructor that allows you to set the element text.

Parameters:
value The value of the element.
text The text to set.

References ticpp::Base::m_impRC, and SetText().


Member Function Documentation

Attribute* ticpp::Element::FirstAttribute ( bool  throwIfNoAttributes = true  )  const

Access the first attribute in this element.

Parameters:
throwIfNoAttributes [DEF] If true, throws when there are no attributes
Returns:
The first attribute, NULL if there are none and throwIfNoAttributes is true

Attribute* ticpp::Element::LastAttribute ( bool  throwIfNoAttributes = true  )  const

Access the last attribute in this element.

Parameters:
throwIfNoAttributes [DEF] If true, throws when there are no attributes
Returns:
The last attribute, NULL if there are none and throwIfNoAttributes is true

template<class T>
void ticpp::Element::SetAttribute ( const std::string &  name,
const T &  value 
) [inline]

Sets an attribute of name to a given value.

The attribute will be created if it does not exist, or changed if it does. Uses ToString to convert the value to a string, so there is no need to use any other SetAttribute methods.

See also:
GetAttribute

References ticpp::NodeImp< TiXmlElement >::m_tiXmlPointer, TiXmlElement::SetAttribute(), and ticpp::Base::ToString().

std::string ticpp::Element::GetText ( bool  throwIfNotFound = true  )  const [inline]

Gets the text of an Element.

Parameters:
throwIfNotFound [DEF] If true, will throw an exception if there is no text in this element
Note:
This only works if the Text is the FirstChild node
Exceptions:
Exception When there is no text and throwIfNotFound is true
See also:
GetText( T* value, bool throwIfNotFound = false )

GetTextOrDefault

GetTextOrDefault( T* value, const DefaultT& defaultValue )

TiXmlElement::GetText

std::string ticpp::Element::GetTextOrDefault ( const std::string &  defaultValue  )  const [inline]

Gets the text of an Element, if it doesn't exist it will return the defaultValue.

Parameters:
defaultValue What to put in 'value' if there is no text in this element
Note:
This only works if the Text is the FirstChild node
See also:
GetText

GetText( T* value, bool throwIfNotFound = false )

GetTextOrDefault( T* value, const DefaultT& defaultValue )

TiXmlElement::GetText

template<class T, class DefaultT>
void ticpp::Element::GetTextOrDefault ( T *  value,
const DefaultT &  defaultValue 
) const [inline]

Gets the text value of an Element, if it doesn't exist it will return the defaultValue.

Uses FromString to convert the string to the type of choice

Parameters:
value [OUT] The container for the returned value
defaultValue What to put in 'value' if there is no text in this element
Note:
This is different than GetText() in that it will covert the text to what ever type you want.

This only works if the Text is the FirstChild node

See also:
GetText

GetText( T* value, bool throwIfNotFound = false )

GetTextOrDefault( const std::string& defaultValue )

TiXmlElement::GetText

References ticpp::Base::FromString().

template<class T>
void ticpp::Element::GetText ( T *  value,
bool  throwIfNotFound = true 
) const [inline]

Gets the text of an Element.

Uses FromString to convert the string to the type of choice.

Parameters:
value [OUT] The container for the returned value
throwIfNotFound [DEF] If true, will throw an exception if there is no text in this element
Note:
This is different than GetText() in that it will covert the text to what ever type you want

This only works if the Text is the FirstChild node

Exceptions:
Exception When there is no text and throwIfNotFound is true
See also:
GetText

GetTextOrDefault

GetTextOrDefault( T* value, const DefaultT& defaultValue )

TiXmlElement::GetText

References ticpp::Base::FromString().

template<class T>
void ticpp::Element::SetText ( const T &  value  )  [inline]

Convenience function to set the text of an element.

Creates a Text node and inserts it as the first child. Uses ToString to convert the parameter to a string.

Parameters:
value The text to set.

References TiXmlNode::FirstChild(), TiXmlElement::GetText(), TiXmlNode::InsertBeforeChild(), TiXmlNode::LinkEndChild(), ticpp::NodeImp< TiXmlElement >::m_tiXmlPointer, TiXmlNode::NoChildren(), TiXmlNode::SetValue(), and ticpp::Base::ToString().

Referenced by Element().

template<class T, class DefaulT>
void ticpp::Element::GetAttributeOrDefault ( const std::string &  name,
T *  value,
const DefaulT &  defaultValue 
) const [inline]

Gets an attribute of name from an element, if it doesn't exist it will return the defaultValue.

Uses FromString to convert the string to the type of choice.

Parameters:
name The name of the attribute you are querying.
value [OUT] The container for the returned value.
defaultValue What to put in value if there is no attribute in this element.
Exceptions:
Exception 
See also:
GetAttribute

References ticpp::Base::FromString().

std::string ticpp::Element::GetAttributeOrDefault ( const std::string &  name,
const std::string &  defaultValue 
) const

Gets an attribute of name from an element, if it doesn't exist it will return the defaultValue.

Parameters:
name The name of the attribute you are querying.
defaultValue What to put in value if there is no attribute in this element.
See also:
GetAttribute

template<class T>
T ticpp::Element::GetAttribute ( const std::string &  name,
bool  throwIfNotFound = true 
) const [inline]

Returns an attribute of name from an element.

Uses FromString to convert the string to the type of choice.

Parameters:
name The name of the attribute you are querying.
throwIfNotFound [DEF] If true, will throw an exception if the attribute doesn't exist
Exceptions:
Exception When the attribute doesn't exist and throwIfNotFound is true
See also:
GetAttributeOrDefault

References ticpp::Base::FromString().

template<class T>
void ticpp::Element::GetAttribute ( const std::string &  name,
T *  value,
bool  throwIfNotFound = true 
) const [inline]

Gets an attribute of name from an element.

Uses FromString to convert the string to the type of choice.

Parameters:
name The name of the attribute you are querying.
value [OUT] The container for the returned value
throwIfNotFound [DEF] If true, will throw an exception if the attribute doesn't exist
Exceptions:
Exception When the attribute doesn't exist and throwIfNotFound is true
See also:
GetAttributeOrDefault

References ticpp::Base::FromString().

std::string ticpp::Element::GetAttribute ( const std::string &  name  )  const

Gets an attribute of name from an element.

Returns an empty string if the attribute does not exist.

Parameters:
name The name of the attribute you are querying.
Returns:
The value of the attribute, or an empty string if it does not exist.
See also:
GetAttributeOrDefault

bool ticpp::Element::HasAttribute ( const std::string &  name  )  const

Returns true, if attribute exists.

Parameters:
name The name of the attribute you are checking.
Returns:
Existence of attribute

void ticpp::Element::RemoveAttribute ( const std::string &  name  ) 

Removes attribute from element.

Parameters:
name The name of the attribute to remove.


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

Generated on Sun Feb 15 23:12:14 2009 for TinyXml by  doxygen 1.5.6