#include <node.h>
Inheritance diagram for Dv::Xml::Node::Ref:
Public Member Functions | ||||
Ref (xml::node &node) | ||||
Construct a Dv::Xml::Node::Ref out of a (copy of a) xml::node object. | ||||
std::string | name () const throw (Dv::Xml::Exception) | |||
| ||||
Node::Ref & | name (const std::string &nm) throw (Exception) | |||
Set name of underlying xml::node. | ||||
bool | nil () const | |||
Is this a "non-null" Dv::Xml::Node::Ref, i.e. | ||||
bool | operator! () const | |||
Is this not a valid Dv::Xml::Node::Ref, i.e. | ||||
bool | equals (const Node::Ref &m) const | |||
Equality test. | ||||
operator const xml::node * () const | ||||
Retrieve underlying xml::node for this Dv::Xml::Node::Ref. | ||||
operator xml::node * () | ||||
Node::Ref | find (const std::string &name) const throw (Exception) | |||
Retrieve child node (of this node) with matching name. | ||||
Ref | end () const throw (Exception) | |||
Return Ref that points past the last child of this node. | ||||
Ref | operator++ () throw (Exception) | |||
Return next child of parent with same name. | ||||
const Node::Ref & | operator * () const | |||
Dummy dereference operator, const version. | ||||
Node::Ref & | operator * () | |||
Dummy dereference operator, non-const version. | ||||
Node::Ref | add (const std::string &name, const std::string &contents) throw (Dv::Xml::Exception) | |||
Append a new text node to the list of children of this node. | ||||
Node::Ref | add (const char *name) throw (Exception) | |||
Append a new node to the list of children of this node. | ||||
Node::Ref | add (const std::string &name) throw (Exception) | |||
Append a new node to the list of children of this node. | ||||
Node::Ref | add (const Node::Ref &child) throw (Exception) | |||
Append copy of node to children of this node. | ||||
bool | defined (const std::string &name) const throw (Exception) | |||
Check whether this node has an attribute value for given key. | ||||
const std::string | operator() (const std::string &name) const throw (Exception) | |||
Retrieve attribute value. | ||||
AttributeReference | operator[] (const std::string &name) throw (Exception) | |||
Set attribute value. | ||||
operator std::string () const throw (Exception) | ||||
Retrieve text content. | ||||
template<typename T> | ||||
operator T () const | ||||
Template user-defined conversion function. | ||||
std::string | str (bool trim=true) const throw (Exception) | |||
Retrieve text content. | ||||
Ref & | operator= (const std::string &text) throw (Exception) | |||
Set text content. | ||||
template<typename T> | ||||
const std::string | operator= (const T &t) | |||
Set content of node referred to by this reference, after converting the parameter object to a std::string. | ||||
Ref & | replace (const Ref &ref) | |||
Replace this node by another one. | ||||
Protected Member Functions | ||||
Ref (xml::node::iterator it, bool nil=false) | ||||
Constructor. | ||||
Ref (xml::node::const_iterator it, bool nil=false) | ||||
Constructor. | ||||
void | assert_valid (const std::string &message) const throw (Dv::Xml::Exception) | |||
Throw an exception if this Dv::Xml::Node::Ref object does not refer to a valid xml::node. | ||||
Private Attributes | ||||
xml::node::iterator | it_ | |||
Refers to xml::node, if valid. | ||||
bool | nil_ | |||
False iff it_ refers to a valid xml::node. | ||||
Friends | ||||
class | Node | |||
class | Document |
Definition at line 181 of file node.h.
Dv::Xml::Node::Ref::Ref | ( | xml::node & | node | ) |
Construct a Dv::Xml::Node::Ref out of a (copy of a) xml::node object.
node | xml::node which will be reference by the new Dv::Xml::Node::Ref object. |
Dv::Xml::Node::Ref::Ref | ( | xml::node::iterator | it, | |
bool | nil = false | |||
) | [explicit, protected] |
Constructor.
it | iterator, possibly referring to xml::node | |
nil | true iff it does not refer to a valid xml::node. |
Dv::Xml::Node::Ref::Ref | ( | xml::node::const_iterator | it, | |
bool | nil = false | |||
) | [explicit, protected] |
Constructor.
it | const_iterator, possibly referring to xml::node | |
nil | true iff it does not refer to a valid xml::node. |
std::string Dv::Xml::Node::Ref::name | ( | ) | const throw (Dv::Xml::Exception) |
Dv::Xml::Exception | if this Dv::Xml::Node::Ref does not refer to a valid xml::node. |
Referenced by add().
Set name of underlying xml::node.
nm | new name of node |
Dv::Xml::Exception | if this Dv::Xml::Node::Ref does not refer to a valid xml::node. |
bool Dv::Xml::Node::Ref::nil | ( | ) | const [inline] |
Is this a "non-null" Dv::Xml::Node::Ref, i.e.
does it refer to a valid xml::node?
bool Dv::Xml::Node::Ref::operator! | ( | ) | const [inline] |
Is this not a valid Dv::Xml::Node::Ref, i.e.
does it not refer to a valid xml::node?
bool Dv::Xml::Node::Ref::equals | ( | const Node::Ref & | m | ) | const |
Equality test.
m | Dv::Xml::Node::Ref to compare this reference with. |
Referenced by Dv::Xml::operator!=(), and Dv::Xml::operator==().
Dv::Xml::Node::Ref::operator const xml::node * | ( | ) | const |
Retrieve underlying xml::node for this Dv::Xml::Node::Ref.
This function can also be used to check whether this is a nil node.
Dv::Xml::Node::Ref n(root/"child"/"grandchild"); if (n) { .. }
Dv::Xml::Node::Ref::operator xml::node * | ( | ) |
Retrieve child node (of this node) with matching name.
name | to match in returned child node |
Dv::Xml::Exception | if this Dv::Xml::Node::Ref does not refer to a valid xml::node. |
Referenced by Dv::Xml::operator/().
Return Ref that points past the last child of this node.
Dv::Xml::Exception | if this Dv::Xml::Node::Ref does not refer to a valid xml::node. |
Referenced by Dv::Xml::Node::end().
Return next child of parent with same name.
Dv::Xml::Exception | if this Dv::Xml::Node::Ref does not refer to a valid xml::node. |
const Node::Ref& Dv::Xml::Node::Ref::operator * | ( | ) | const [inline] |
Node::Ref& Dv::Xml::Node::Ref::operator * | ( | ) | [inline] |
Node::Ref Dv::Xml::Node::Ref::add | ( | const std::string & | name, | |
const std::string & | contents | |||
) | throw (Dv::Xml::Exception) |
Append a new text node to the list of children of this node.
name | of the new node | |
contents | of the new node |
Dv::Xml::Exception | if the target does not refer to a valid xml::node. |
Referenced by Dv::Xml::operator>>().
Append a new node to the list of children of this node.
name | of the new node |
Dv::Xml::Exception | if the target does not refer to a valid xml::node. |
Append a new node to the list of children of this node.
name | of the new node |
Dv::Xml::Exception | if the target does not refer to a valid xml::node. |
Definition at line 302 of file node.h.
References name().
Append copy of node to children of this node.
child | a copy of which will be added to the children of this node. |
Dv::Xml::Exception | if either of the parameters does not refer to a valid xml::node. |
bool Dv::Xml::Node::Ref::defined | ( | const std::string & | name | ) | const throw (Exception) |
Check whether this node has an attribute value for given key.
name | key of attribute |
Dv::Xml::Exception | if this Dv::Xml::Node::Ref does not refer to a valid xml::node. |
const std::string Dv::Xml::Node::Ref::operator() | ( | const std::string & | name | ) | const throw (Exception) |
Retrieve attribute value.
name | key of attribute |
Dv::Xml::Exception | if this node has no attribute for key "name" or this node does not refer to a valid xml::node. |
AttributeReference Dv::Xml::Node::Ref::operator[] | ( | const std::string & | name | ) | throw (Exception) |
Set attribute value.
name | key of attribute |
Dv::Xml::Exception | if this Dv::Xml::Node::Ref does not refer to a valid xml::node. |
Dv::Xml::Node::Ref n; .. n["name"] = "fred"; std::cout << n["name"] << std::endl;
Dv::Xml::Node::Ref::operator std::string | ( | ) | const throw (Exception) |
Retrieve text content.
Note that the resulting string is trimmed, i.e. leading and trailing white space is removed. To prevent trimming: use Dv::Xml::Node::Ref::str(false).
Dv::Xml::Exception | if this Dv::Xml::Node::Ref does not refer to a valid xml::node. |
Dv::Xml::Node::Ref::operator T | ( | ) | const [inline] |
Template user-defined conversion function.
Dv::Xml::Node::Ref n; std::string s1(n["a"]); // error std::string s2 = n["a"]; // OK
Definition at line 376 of file node.h.
References Dv::Util::fromstring().
std::string Dv::Xml::Node::Ref::str | ( | bool | trim = true |
) | const throw (Exception) |
Retrieve text content.
trim | if true, remove leading and trailing white space from result. |
Dv::Xml::Exception | if this Dv::Xml::Node::Ref does not refer to a valid xml::node. |
Set text content.
text | to be used as content for this node. |
Dv::Xml::Exception | if this Dv::Xml::Node::Ref does not refer to a valid xml::node. |
const std::string Dv::Xml::Node::Ref::operator= | ( | const T & | t | ) | [inline] |
Set content of node referred to by this reference, after converting the parameter object to a std::string.
The conversion is done using Dv::Util::tostring<T>.
t | value to assign, after conversion, to attribute. |
Replace this node by another one.
The replacement will take place in the tree of which this Ref is a part.
ref | reference to xml::node of which a copy will replace this node. |
void Dv::Xml::Node::Ref::assert_valid | ( | const std::string & | message | ) | const throw (Dv::Xml::Exception) [protected] |
Throw an exception if this Dv::Xml::Node::Ref object does not refer to a valid xml::node.
message | to be used in the generated exception. |
xml::node::iterator Dv::Xml::Node::Ref::it_ [private] |
bool Dv::Xml::Node::Ref::nil_ [private] |
dvxml-0.1.7 | [ 7 January, 2008] |