Simbody  3.7
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 explicitly 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 attribute_iterator
 
class Element
 

Related Functions

(Note that these are not member functions.)

std::ostream & operator<< (std::ostream &o, const Attribute &attr)
 Output a textual representation of the given Xml::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

◆ Attribute() [1/3]

SimTK::Xml::Attribute::Attribute ( )
inline

Default constructor creates a null Attribute handle.

◆ Attribute() [2/3]

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.

◆ Attribute() [3/3]

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.

◆ ~Attribute()

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

◆ operator=()

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()

◆ isValid()

bool SimTK::Xml::Attribute::isValid ( ) const
inline

Is this handle currently holding an attribute?

◆ isOrphan()

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.

◆ getName()

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

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

◆ getValue()

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.

◆ setName()

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.

◆ setValue()

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.

◆ clear()

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.

◆ clearOrphan()

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

This method explicitly 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.

◆ writeToString()

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.

◆ operator==()

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.

◆ operator!=()

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

Friends And Related Function Documentation

◆ attribute_iterator

friend class attribute_iterator
friend

◆ Element

friend class Element
friend

◆ operator<<()

std::ostream & operator<< ( std::ostream &  o,
const Attribute attr 
)
related

Output a textual representation of the given Xml::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: