Spinning Topp Logo BlackTopp Studios
inc
Public Member Functions | Friends | List of all members
Mezzanine::XML::Attribute Class Reference

A light-weight handle for manipulating attributes in DOM tree. More...

#include <attribute.h>

Public Member Functions

 Attribute ()
 Constructs an empty Attribute.
 
 Attribute (AttributeStruct *attr)
 Constructs attribute from internal pointer. More...
 
bool AsBool (bool def=false) const
 Attempts to convert the value of the attribute to a float and returns the results. More...
 
double AsDouble (double def=0) const
 Attempts to convert the value of the attribute to a double and returns the results. More...
 
float AsFloat (float def=0) const
 Attempts to convert the value of the attribute to a float and returns the results. More...
 
int AsInt (int def=0) const
 Attempts to convert the value of the attribute to an int and returns the results. More...
 
Integer AsInteger (Integer def=0) const
 Attempts to convert the value of the attribute to a Integer and returns the results. More...
 
Real AsReal (Real def=0) const
 Attempts to convert the value of the attribute to a Real and returns the results. More...
 
const Char8AsString (const Char8 *def="") const
 Attempts to convert the value of the attribute to a String and returns the results. More...
 
unsigned int AsUint (unsigned int def=0) const
 Attempts to convert the value of the attribute to an unsigned int and returns the results. More...
 
Whole AsWhole (Whole def=0) const
 Attempts to convert the value of the attribute to a Whole and returns the results. More...
 
bool Empty () const
 Is this storing anything at all? More...
 
Attribute GetNextAttribute () const
 Get the next attribute. More...
 
Attribute GetPreviousAttribute () const
 Get the previous attribute. More...
 
size_t HashValue () const
 Get a unique identifying value for the Attribute this represents. More...
 
AttributeStruct * InternalObject () const
 Retrieve a pointer to the internal data. More...
 
const Char8Name () const
 Get the name of this Attribute. More...
 
 operator unspecified_bool_type () const
 Used to convert this to a boolean value in a safe way. More...
 
bool operator! () const
 Used to convert this attribute the opposite of it's normal boolean value. More...
 
bool operator!= (const Attribute &r) const
 Compares the internal values to check inequality. More...
 
bool operator< (const Attribute &r) const
 Compares the internal values to check for inequality. More...
 
bool operator<= (const Attribute &r) const
 Compares the internal values to check for inequality. More...
 
Attributeoperator= (const Char8 *rhs)
 The same as Attribute::SetValue(); without the error return. More...
 
Attributeoperator= (int rhs)
 The same as Attribute::SetValue(); without the error return. More...
 
Attributeoperator= (unsigned int rhs)
 The same as Attribute::SetValue(); without the error return. More...
 
Attributeoperator= (double rhs)
 The same as Attribute::SetValue(); without the error return. More...
 
Attributeoperator= (bool rhs)
 The same as Attribute::SetValue(); without the error return. More...
 
bool operator== (const Attribute &r) const
 Compares the internal values to check equality. More...
 
bool operator> (const Attribute &r) const
 Compares the internal values to check for inequality. More...
 
bool operator>= (const Attribute &r) const
 Compares the internal values to check for inequality. More...
 
bool SetName (const Char8 *rhs)
 Set the name of . More...
 
bool SetName (const String &rhs)
 Set the name of this object. More...
 
bool SetValue (const Char8 *rhs)
 Set the value of this. More...
 
bool SetValue (int rhs)
 Convert rhs to a character array that contains rhs, then use that as the new value. More...
 
bool SetValue (unsigned int rhs)
 Convert rhs to a character array that contains rhs, then use that as the new value. More...
 
bool SetValue (double rhs)
 Convert rhs to a character array that contains rhs, then use that as the new value. More...
 
bool SetValue (bool rhs)
 Convert rhs to a character array that contains the meaning of rhs, then use that as the new value. More...
 
template<class T >
bool SetValue (T rhs)
 Convert rhs to a character array that contains the meaning of rhs, then use that as the new value. More...
 
bool SetValue (const String &rhs)
 Set the value of this. More...
 
const Char8Value () const
 Get the Value of this Attribute. More...
 

Friends

class AttributeIterator
 
class Node
 

Detailed Description

A light-weight handle for manipulating attributes in DOM tree.

Definition at line 74 of file attribute.h.

Constructor & Destructor Documentation

Mezzanine::XML::Attribute::Attribute ( AttributeStruct *  attr)
explicit

Constructs attribute from internal pointer.

Parameters
attrAn internal AttributeStruct pointer containing all the data to create an attribute.

Member Function Documentation

bool Mezzanine::XML::Attribute::AsBool ( bool  def = false) const

Attempts to convert the value of the attribute to a float and returns the results.

Returns
Value as bool (returns true if first character is in '1tTyY' set), or def if attribute is empty
Parameters
defIs returned if the attribute is empty
double Mezzanine::XML::Attribute::AsDouble ( double  def = 0) const

Attempts to convert the value of the attribute to a double and returns the results.

Returns
If the value of this attribute can be convert to a double by reading the character and interpretting them a number, that numberis returned. Returns parameter def on failure.
Parameters
defIs returned if the attribute is empty
Todo:
Update Attribute::AsDouble() to check errno and throw exceptions were appropriate, and throw a exception on failure instead of producing a valid return value.
Warning
This may silently fail if the value of the attribute exceeds the maximum value that can be stored in and double. Check "errno" and see if it is set to "ERANGE" to test for this condition.
float Mezzanine::XML::Attribute::AsFloat ( float  def = 0) const

Attempts to convert the value of the attribute to a float and returns the results.

Returns
If the value of this attribute can be convert to a float by reading the character and interpretting them a number, that numberis returned. Returns def on failure.
Parameters
defIs returned if the attribute is empty
Todo:
Update Attribute::AsFloat() to check errno and throw exceptions were appropriate, and throw a exception on failure instead of producing a valid return value.
Warning
This may silently fail if the value of the attribute exceeds the maximum value that can be stored in and float. Check "errno" and see if it is set to "ERANGE" to test for this condition.
int Mezzanine::XML::Attribute::AsInt ( int  def = 0) const

Attempts to convert the value of the attribute to an int and returns the results.

Returns
If the value of this attribute can be convert to an int by reading the character and interpretting them a number, that numberis returned. Returns passed parameter on failure.
Todo:
Update Attribute::AsInt() to check errno and throw exceptions were appropriate, and throw a exception on failure instead of producing a valid return value.
Parameters
defIs returned if the attribute is empty.
Warning
This may silently fail if the value of the attribute exceeds the maximum value that can be stored in and int. Check "errno" and see if it is set to "ERANGE" to test for this condition.
Integer Mezzanine::XML::Attribute::AsInteger ( Integer  def = 0) const

Attempts to convert the value of the attribute to a Integer and returns the results.

Returns
If the value of this attribute can be converted to a Integer by reading the character and interpretting them a number, that number is returned. Returns 0 (def defaults to 0) on failure.
Parameters
defIs returned if the attribute is empty
Exceptions
Thiscan throw exception in certain overflow conditions
Real Mezzanine::XML::Attribute::AsReal ( Real  def = 0) const

Attempts to convert the value of the attribute to a Real and returns the results.

Returns
If the value of this attribute can be converted to a Real by reading the character and interpretting them a number, that number is returned. Returns argument def on failure.
Parameters
defIs returned if the attribute is empty
Exceptions
Thiscan throw exception in certain overflow conditions
const Char8* Mezzanine::XML::Attribute::AsString ( const Char8 def = "") const

Attempts to convert the value of the attribute to a String and returns the results.

Returns
If the value of this attribute can be converted to a Real by reading the character and interpretting them a number, that number is returned. Returns def on failure.
Parameters
defIs returned if the attribute is empty
Exceptions
Thiscan throw exception in certain overflow conditions
unsigned int Mezzanine::XML::Attribute::AsUint ( unsigned int  def = 0) const

Attempts to convert the value of the attribute to an unsigned int and returns the results.

Returns
If the value of this attribute can be convert to an unsigned int by reading the character and interpretting them a number, that numberis returned. Returns 0 on failure.
Parameters
defIs returned if the attribute is empty
Todo:
Update Attribute::AsUint() to check errno and throw exceptions were appropriate, and throw a exception on failure instead of producing a valid return value.
Warning
This may silently fail if the value of the attribute exceeds the maximum value that can be stored in and int. Check "errno" and see if it is set to "ERANGE" to test for this condition.
Whole Mezzanine::XML::Attribute::AsWhole ( Whole  def = 0) const

Attempts to convert the value of the attribute to a Whole and returns the results.

Returns
If the value of this attribute can be converted to a Whole by reading the character and interpretting them a number, that number is returned. Returns passed parameter on failure.
Parameters
defIs returned if the attribute is empty
Exceptions
Thiscan throw exception in certain overflow conditions
bool Mezzanine::XML::Attribute::Empty ( ) const

Is this storing anything at all?

Returns
Returns True if this Attribute is storing nothing. False if it is storing anything.
Attribute Mezzanine::XML::Attribute::GetNextAttribute ( ) const

Get the next attribute.

This will get the next sibling attribute. That is, another Attribute on the same node as this attribute. This is internally a circular linked list, so once you reach the end, you simply be given the first node. If this attribute is empty this will return a empty attribute.

Returns
Either the next attribute or if this attribute is empty an empty attribute.
Attribute Mezzanine::XML::Attribute::GetPreviousAttribute ( ) const

Get the previous attribute.

This will get the previous sibling attribute. That is, another Attribute on the same node as this attribute. This is internally a circular linked list, so once you reach the beginning, you simply be given the last node. If this attribute is empty this will return a empty attribute.

Returns
Either the previous attribute or if this attribute is empty an empty attribute.
size_t Mezzanine::XML::Attribute::HashValue ( ) const

Get a unique identifying value for the Attribute this represents.

Returns
A size_t that is unique per Attribute that an attribute could represent.
AttributeStruct* Mezzanine::XML::Attribute::InternalObject ( ) const

Retrieve a pointer to the internal data.

Returns
A void pointer to the internal data.
const Char8* Mezzanine::XML::Attribute::Name ( ) const

Get the name of this Attribute.

Returns
Returns A pointer to a const c-style array of the the character type (usually char or wchar_t) containing the name.
Warning
returns "" if attribute is empty.
Mezzanine::XML::Attribute::operator unspecified_bool_type ( ) const

Used to convert this to a boolean value in a safe way.

Returns
Returns true if the internal data is set and false otherwise.
Note
Not available in scripting languages because conversion is handled on a per langauge basis
bool Mezzanine::XML::Attribute::operator! ( ) const

Used to convert this attribute the opposite of it's normal boolean value.

This is described in the PugiXML source a a workaround for a borland c++ issue.

Returns
Returns false if the internal pointer AttributeStruct is set and true otherwise.
bool Mezzanine::XML::Attribute::operator!= ( const Attribute r) const

Compares the internal values to check inequality.

Parameters
rThe other Attribute this is being compared to.

Many of the internal values are pointers, and it is the addresses of these that are being compared.

Returns
Returns true if any of the internal values don't match between this and the other Attribute.
bool Mezzanine::XML::Attribute::operator< ( const Attribute r) const

Compares the internal values to check for inequality.

Parameters
rThe other Attribute this is being compared to.

Many of the internal values are pointers, and it is the addresses of these that are being compared.

Returns
Returns True if the other Attribute is greater than this one as per sequential comparison of internal pointers.
bool Mezzanine::XML::Attribute::operator<= ( const Attribute r) const

Compares the internal values to check for inequality.

Parameters
rThe other Attribute this is being compared to.

Many of the internal values are pointers, and it is the addresses of these that are being compared.

Returns
Returns True if the other Attribute is greater than or equal to this one as per sequential comparison of internal pointers.
Attribute& Mezzanine::XML::Attribute::operator= ( const Char8 rhs)

The same as Attribute::SetValue(); without the error return.

Parameters
rhsThe new value as an c-style string.
Returns
An reference to this attribute.
Attribute& Mezzanine::XML::Attribute::operator= ( int  rhs)

The same as Attribute::SetValue(); without the error return.

Parameters
rhsThe new value as an int.
Returns
An reference to this attribute.
Attribute& Mezzanine::XML::Attribute::operator= ( unsigned int  rhs)

The same as Attribute::SetValue(); without the error return.

Parameters
rhsThe new value as an unsigned int.
Returns
An reference to this attribute.
Attribute& Mezzanine::XML::Attribute::operator= ( double  rhs)

The same as Attribute::SetValue(); without the error return.

Parameters
rhsThe new value as a double.
Returns
An reference to this attribute.
Attribute& Mezzanine::XML::Attribute::operator= ( bool  rhs)

The same as Attribute::SetValue(); without the error return.

Parameters
rhsThis with be interpretted, then converted to "true" or "false" and used as the new value.
Returns
An reference to this attribute.
bool Mezzanine::XML::Attribute::operator== ( const Attribute r) const

Compares the internal values to check equality.

Parameters
rThe other Attribute this is being compared to.

Many of the internal values are pointers, and it is the addresses of these that are being compared.

Returns
Returns true if all the internal values match between this and the other Attribute.
bool Mezzanine::XML::Attribute::operator> ( const Attribute r) const

Compares the internal values to check for inequality.

Parameters
rThe other Attribute this is being compared to.

Many of the internal values are pointers, and it is the addresses of these that are being compared.

Returns
Returns True if the other Attribute is less than this one as per sequential comparison of internal pointers.
bool Mezzanine::XML::Attribute::operator>= ( const Attribute r) const

Compares the internal values to check for inequality.

Parameters
rThe other Attribute this is being compared to.

Many of the internal values are pointers, and it is the addresses of these that are being compared.

Returns
Returns True if the other Attribute is less than or equal to this one as per sequential comparison of internal pointers.
bool Mezzanine::XML::Attribute::SetName ( const Char8 rhs)

Set the name of .

Parameters
rhsThe desired name.
Returns
True if successful, returns false if the name cannot be stored or there is not enough memory.
Note
Not available in scripting languages the Overload which accepts a Mezzanine::String is used instead, for enhanced robustness in the event corrupt String are created.
bool Mezzanine::XML::Attribute::SetName ( const String rhs)
inline

Set the name of this object.

Parameters
rhsThe desired name .
Returns
True if successful, returns false if the name cannot be stored or there is not enough memory.
Note
This overload is used in scripting languages.

Definition at line 235 of file attribute.h.

bool Mezzanine::XML::Attribute::SetValue ( const Char8 rhs)

Set the value of this.

Parameters
rhsThe new Value.
Returns
True if successful, returns false if this is empty or there is not enough memory.
Todo:

update this to make the error return code redundant and use an exception instead.

Review for possiblity of buffer overflow.

Note
Not available in scripting languages the Overload which accepts a Mezzanine::String is used instead, for enhanced robustness in the event corrupt String are created.
bool Mezzanine::XML::Attribute::SetValue ( int  rhs)

Convert rhs to a character array that contains rhs, then use that as the new value.

Parameters
rhsThe new value as an int.
Returns
True if successful, returns false if Attribute is empty or there is not enough memory.
Todo:

update this to make the error return code redundant and use an exception instead.

Review for possiblity of buffer overflow.

Note
Not available in scripting languages the Overload which accepts a Mezzanine::String is used instead.
bool Mezzanine::XML::Attribute::SetValue ( unsigned int  rhs)

Convert rhs to a character array that contains rhs, then use that as the new value.

Parameters
rhsThe new value as an unsigned int.
Returns
True if successful, returns false if Attribute is empty or there is not enough memory.
Todo:

update this to make the error return code redundant and use an exception instead.

Review for possiblity of buffer overflow.

Note
Not available in scripting languages the Overload which accepts a Mezzanine::String is used instead.
bool Mezzanine::XML::Attribute::SetValue ( double  rhs)

Convert rhs to a character array that contains rhs, then use that as the new value.

Parameters
rhsThe new value as a double.
Returns
True if successful, returns false if Attribute is empty or there is not enough memory.
Todo:

update this to make the error return code redundant and use an exception instead.

Review for possiblity of buffer overflow.

Note
Not available in scripting languages the Overload which accepts a Mezzanine::String.
bool Mezzanine::XML::Attribute::SetValue ( bool  rhs)

Convert rhs to a character array that contains the meaning of rhs, then use that as the new value.

Parameters
rhsThis with be interpretted, then converted to "true" or "false" and used as the new value.
Returns
True if successful, returns false if Attribute is empty or there is not enough memory.
Todo:

update this to make the error return code redundant and use an exception instead.

Review for possiblity of buffer overflow.

Note
Not available in scripting languages the Overload which accepts a Mezzanine::String is used instead.
template<class T >
bool Mezzanine::XML::Attribute::SetValue ( rhs)
inline

Convert rhs to a character array that contains the meaning of rhs, then use that as the new value.

Parameters
rhsThis with be converted to a character array using the appropriate streaming operator <<, then used as the new value.
Returns
True if successful, returns false if Attribute is empty or there is not enough memory.
Warning
You should not pass classes that stream/serialize to xml into this function, the result will be invalid XML. If you must, find a way to strip out the ">" character, then you can reinsert it later
Todo:
Strip ">" automatically and provide a method to reconsitute it.

Definition at line 285 of file attribute.h.

bool Mezzanine::XML::Attribute::SetValue ( const String rhs)
inline

Set the value of this.

Parameters
rhsThe new Value.
Returns
True if successful, returns false if this is empty or there is not enough memory.
Todo:
update this to make the error return code redundant and use an exception instead.
Note
This overload is used in scripting languages.

Definition at line 294 of file attribute.h.

const Char8* Mezzanine::XML::Attribute::Value ( ) const

Get the Value of this Attribute.

Returns
Returns A pointer to a const c-style array of the the character type (usually char or wchar_t) containing the value.
Warning
Returns "" if attribute is empty.

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