Simbody
|
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>
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. | |
Attribute & | operator= (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 String & | getName () const |
If this is a valid attribute handle, get the name of the attribute. | |
const String & | getValue () const |
If this is a valid attribute handle, get the value of the attribute as a String, not including the quotes. | |
Attribute & | setName (const String &name) |
If this is a valid attribute handle, change its name. | |
Attribute & | setValue (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. |
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.
SimTK::Xml::Attribute::Attribute | ( | ) | [inline] |
Default constructor creates a null Attribute handle.
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().
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.
bool SimTK::Xml::Attribute::isValid | ( | ) | const [inline] |
Is this handle currently holding an attribute?
bool SimTK::Xml::Attribute::isOrphan | ( | ) | const |
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.
If this is a valid attribute handle, change its name.
If this is a valid attribute handle, change its value to the given String which should not be quoted.
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] |
friend class Xml::attribute_iterator [friend] |
friend class Xml::Element [friend] |
std::ostream & operator<< | ( | std::ostream & | o, |
const Xml::Attribute & | attr | ||
) | [related] |