Simbody
Public Member Functions | Friends | Related Functions

SimTK::Xml::Attribute Class Reference

Elements can have attributes, which are name="value" pairs that appear within the element start tag in an XML document; this class represents the in-memory representation of one of those attributes and can be used to examine or modify the name or value. More...

#include <Xml.h>

List of all members.

Public Member Functions

 Attribute ()
 Default constructor creates a null Attribute handle.
 Attribute (const String &name, const String &value)
 Create a new orphan Attribute, that is, an Attribute that is not owned by any Xml Element.
 Attribute (const Attribute &src)
 Copy constructor is shallow; that is, this handle will refer to the same attribute as the source.
Attributeoperator= (const Attribute &src)
 Copy assignment is shallow; the handle is first cleared and then will refer to the same attribute as the source.
 ~Attribute ()
 The Attribute handle destructor does not recover heap space so if you create orphan attributes and then don't put them in a document there will be a memory leak unless you explicitly destruct them first with clearOrphan().
bool isValid () const
 Is this handle currently holding an attribute?
bool isOrphan () const
 Return true if this Attribute is an orphan, meaning that it is not empty, but is not owned by any element or top-level document.
const StringgetName () const
 If this is a valid attribute handle, get the name of the attribute.
const StringgetValue () const
 If this is a valid attribute handle, get the value of the attribute as a String, not including the quotes.
AttributesetName (const String &name)
 If this is a valid attribute handle, change its name.
AttributesetValue (const String &value)
 If this is a valid attribute handle, change its value to the given String which should not be quoted.
void clear ()
 This method restores the Attribute handle to its default-constructed state but does not recover any heap space; use clearOrphan() if you know this attribute was never put into a document.
void clearOrphan ()
 This method explictly frees the heap space for an orphan attribute that was created but never inserted into a document.
void writeToString (String &out) const
 Serialize this attribute to the given String.
bool operator== (const Attribute &attr) const
 Comparison operators return true if the same attribute is being referenced or both handles are empty.
bool operator!= (const Attribute &attr) const

Friends

class Xml::attribute_iterator
class Xml::Element

Related Functions

(Note that these are not member functions.)
std::ostream & operator<< (std::ostream &o, const Xml::Attribute &attr)
 Output a textual representation of the given Attribute to an std::ostream.

Detailed Description

Elements can have attributes, which are name="value" pairs that appear within the element start tag in an XML document; this class represents the in-memory representation of one of those attributes and can be used to examine or modify the name or value.

Attribute names within an element tag are unique.


Constructor & Destructor Documentation

SimTK::Xml::Attribute::Attribute ( ) [inline]

Default constructor creates a null Attribute handle.

SimTK::Xml::Attribute::Attribute ( const String name,
const String value 
)

Create a new orphan Attribute, that is, an Attribute that is not owned by any Xml Element.

SimTK::Xml::Attribute::Attribute ( const Attribute src) [inline]

Copy constructor is shallow; that is, this handle will refer to the same attribute as the source.

Note that this handle will provide write access to the underlying attribute, even if the source was const.

SimTK::Xml::Attribute::~Attribute ( ) [inline]

The Attribute handle destructor does not recover heap space so if you create orphan attributes and then don't put them in a document there will be a memory leak unless you explicitly destruct them first with clearOrphan().


Member Function Documentation

Attribute& SimTK::Xml::Attribute::operator= ( const Attribute src) [inline]

Copy assignment is shallow; the handle is first cleared and then will refer to the same attribute as the source.

Note that this handle will provide write access to the underlying attribute even if the source handle was const.

See also:
clear()
bool SimTK::Xml::Attribute::isValid ( ) const [inline]

Is this handle currently holding an attribute?

bool SimTK::Xml::Attribute::isOrphan ( ) const

Return true if this Attribute is an orphan, meaning that it is not empty, but is not owned by any element or top-level document.

This is typically an Attribute object that has just been constructed, or one that has been cloned from another Attribute.

const String& SimTK::Xml::Attribute::getName ( ) const

If this is a valid attribute handle, get the name of the attribute.

const String& SimTK::Xml::Attribute::getValue ( ) const

If this is a valid attribute handle, get the value of the attribute as a String, not including the quotes.

Attribute& SimTK::Xml::Attribute::setName ( const String name)

If this is a valid attribute handle, change its name.

Returns:
A reference to this attribute that now has the new name.
Attribute& SimTK::Xml::Attribute::setValue ( const String value)

If this is a valid attribute handle, change its value to the given String which should not be quoted.

Returns:
A reference to this attribute that now has the new value.
void SimTK::Xml::Attribute::clear ( )

This method restores the Attribute handle to its default-constructed state but does not recover any heap space; use clearOrphan() if you know this attribute was never put into a document.

void SimTK::Xml::Attribute::clearOrphan ( )

This method explictly frees the heap space for an orphan attribute that was created but never inserted into a document.

It is an error to call this if the attribute is in a document.

void SimTK::Xml::Attribute::writeToString ( String out) const

Serialize this attribute to the given String.

The output will be as it would appear in an XML file, i.e. name="value" or name='value' with special characters output as suitable entities. If you don't want it that way, use getName() and getValue() instead which return the raw strings.

bool SimTK::Xml::Attribute::operator== ( const Attribute attr) const [inline]

Comparison operators return true if the same attribute is being referenced or both handles are empty.

Note that two different attributes with the same properties will not test equal by this criterion.

bool SimTK::Xml::Attribute::operator!= ( const Attribute attr) const [inline]

Friends And Related Function Documentation

friend class Xml::attribute_iterator [friend]
friend class Xml::Element [friend]
std::ostream & operator<< ( std::ostream &  o,
const Xml::Attribute attr 
) [related]

Output a textual representation of the given Attribute to an std::ostream.

This will be in the form the Attribute would appear in an XML file; that is, name="value" or name='value' with entity substituion for odd characters, without surrounding blanks.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines