Simbody  3.5
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...

Public Member Functions

 Attribute ()
 Default constructor creates a null Attribute handle. More...
 
 Attribute (const String &name, const String &value)
 Create a new orphan Attribute, that is, an Attribute that is not owned by any Xml Element. More...
 
 Attribute (const Attribute &src)
 Copy constructor is shallow; that is, this handle will refer to the same attribute as the source. More...
 
Attributeoperator= (const Attribute &src)
 Copy assignment is shallow; the handle is first cleared and then will refer to the same attribute as the source. More...
 
 ~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(). More...
 
bool isValid () const
 Is this handle currently holding an attribute? More...
 
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. More...
 
const StringgetName () const
 If this is a valid attribute handle, get the name of the attribute. More...
 
const StringgetValue () const
 If this is a valid attribute handle, get the value of the attribute as a String, not including the quotes. More...
 
AttributesetName (const String &name)
 If this is a valid attribute handle, change its name. More...
 
AttributesetValue (const String &value)
 If this is a valid attribute handle, change its value to the given String which should not be quoted. More...
 
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. More...
 
void clearOrphan ()
 This method explictly frees the heap space for an orphan attribute that was created but never inserted into a document. More...
 
void writeToString (String &out) const
 Serialize this attribute to the given String. More...
 
bool operator== (const Attribute &attr) const
 Comparison operators return true if the same attribute is being referenced or both handles are empty. More...
 
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. More...
 

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: