Dv::Xml::Node::AttributeReference Class Reference

Auxiliary class for attribute access. More...

#include <node.h>

List of all members.

Public Member Functions

const std::string & operator= (const std::string &value)
 Set attribute referred to by this reference.
template<typename T>
const std::string & operator= (const T &t)
 Set attribute referred to by this reference, after converting the parameter object to a std::string.
std::string str () const
 Retrieve value of attribute referred to by this reference.
 operator std::string () const
 Retrieve value of attribute referred to by this reference.
template<typename T>
T & conv (T &t) const
 Explicit conversion to any type that can be converted by Dv::Util::fromstring.
template<typename T>
 operator T () const
 Template user-defined conversion function.

Private Member Functions

 AttributeReference (const xml::node::iterator n, const std::string &name)
 Constructor.

Private Attributes

const std::string name
xml::node::iterator node

Friends

class Ref


Detailed Description

Auxiliary class for attribute access.

Dv::Xml::Node::Ref::operator[](const std::string) returns an AttributeReference object.

Definition at line 97 of file node.h.


Constructor & Destructor Documentation

Dv::Xml::Node::AttributeReference::AttributeReference ( const xml::node::iterator  n,
const std::string &  name 
) [private]

Constructor.

Parameters:
n reference to xml::node for which the attribute is considered
name of the attribute


Member Function Documentation

const std::string& Dv::Xml::Node::AttributeReference::operator= ( const std::string &  value  ) 

Set attribute referred to by this reference.

Warning:
The value will be automatically converted to legal XML text (i.e. '&' will become '&').
Parameters:
value to assign to attribute.
Returns:
value

Referenced by operator=().

template<typename T>
const std::string& Dv::Xml::Node::AttributeReference::operator= ( const T &  t  )  [inline]

Set attribute referred to by this reference, after converting the parameter object to a std::string.

The conversion is done using Dv::Util::tostring<T>.

Parameters:
t value to assign, after conversion, to attribute.
Returns:
value

Definition at line 115 of file node.h.

References operator=().

std::string Dv::Xml::Node::AttributeReference::str (  )  const

Retrieve value of attribute referred to by this reference.

Returns:
value of attribute referred to by this reference, or empty string if there is no attribute value associated with this reference.

Referenced by operator std::string(), and Dv::Xml::operator<<().

Dv::Xml::Node::AttributeReference::operator std::string (  )  const [inline]

Retrieve value of attribute referred to by this reference.

Returns:
value of attribute referred to by this reference, or empty string if there is no attribute value associated with this reference.

Definition at line 131 of file node.h.

References str().

template<typename T>
T& Dv::Xml::Node::AttributeReference::conv ( T &  t  )  const [inline]

Explicit conversion to any type that can be converted by Dv::Util::fromstring.

Parameters:
t lvalue referring to object resulting from the conversion
Returns:
reference to first parameter (t).

Definition at line 139 of file node.h.

References Dv::Util::fromstring().

template<typename T>
Dv::Xml::Node::AttributeReference::operator T (  )  const [inline]

Template user-defined conversion function.

Warning:
This will not work for std::string (and others), unless the "assignment" syntax is used for explicit initializtion, as illustrated by the following example.
 Dv::Xml::Node::Ref n;
 std::string s1(n["a"]); // error
 std::string s2 = n["a"]; // OK
The initialization of s1 is ambiguous: n["a"] may be converted to a (single) paramater for a std::string ctor using at least two instantiations of the user-defined conversion template below:
  • std::string(const char*)
  • std::string(const std::string&)

Definition at line 161 of file node.h.


Friends And Related Function Documentation

friend class Ref [friend]

Definition at line 98 of file node.h.


Member Data Documentation

const std::string Dv::Xml::Node::AttributeReference::name [private]

Definition at line 176 of file node.h.

xml::node::iterator Dv::Xml::Node::AttributeReference::node [private]

Definition at line 177 of file node.h.


The documentation for this class was generated from the following file:
dvxml-0.1.7 [ 7 January, 2008]