s11n::node_traits< NodeT > Struct Template Reference

node_traits encapsulates information relevant to Data Nodes, much in the same way that std::char_traits encapsulates character type information. More...

#include <traits.hpp>

List of all members.

Public Types

typedef NodeT node_type
 The same as NodeT.
typedef
node_type::map_type 
property_map_type
 The type uses to store properties for node_type objects.
typedef
node_type::child_list_type 
child_list_type
 The type used to store children of node_type objects.

Static Public Member Functions

static node_typecreate ()
 Returns a new node_type.
static node_typecreate (const std::string &nodename)
 Returns a new node_type with the given name.
template<typename ValueT>
static void set (node_type &node, const std::string &key, const ValueT &value)
 Sets the property key to the given value in the given node.
static void unset (node_type &node, const std::string &key)
 Unsets (removes) the given property from node.
static bool is_set (const node_type &node, const std::string &key)
 Returns true if node contains a property named key, else returns false.
static const
property_map_type
properties (const node_type &node)
 Returns an immutable reference to the node's map of properties.
static
property_map_type
properties (node_type &node)
 Returns a mutable reference to the node's map of properties.
template<typename ValueT>
static ValueT get (const node_type &node, const std::string &key, const ValueT &default_value)
 Returns the value of the property with the given key, or default_value if that property does not exist or cannot be lexically cast to type ValueT.
static child_list_typechildren (node_type &node)
 Returns a mutable list of children belonging to node.
static const
child_list_type
children (const node_type &node)
 Returns an immutable list of children belonging to node.
static void class_name (node_type &node, const std::string &classname)
 Sets the class name of the type for which node holds serialized data.
static std::string class_name (const node_type &node)
 Returns the class name of the type for which node holds serialized data.
static void name (node_type &node, const std::string &name)
 Sets node's name.
static std::string name (const node_type &node)
 Returns node's name.
static void clear (node_type &node)
 Removes all children and properties from node, freeing up their resources.
static bool empty (const node_type &node)
 Returns true if this object has no properties and no children.
static void swap (node_type &lhs, node_type &rhs)
 Swaps all publically-visible internal state of lhs with that of rhs.


Detailed Description

template<typename NodeT>
struct s11n::node_traits< NodeT >

node_traits encapsulates information relevant to Data Nodes, much in the same way that std::char_traits encapsulates character type information.

The default implementation works with s11n::s11n_node or API-compatible types. Specializations may be defined to work with other node types.

By using node_traits, instead of directly accessing a Node's API, client code may remain blissfully ignorant of the underlying node type.

All API docs for this class which do not explicitely say "this implementation" (or similar) apply to all specializations of this type. They act as the "requirements document" for implementors of specializations.

Changes from 1.0.x to 1.1.x:

Definition at line 46 of file traits.hpp.


Member Typedef Documentation

template<typename NodeT>
typedef NodeT s11n::node_traits< NodeT >::node_type

The same as NodeT.

Definition at line 52 of file traits.hpp.

template<typename NodeT>
typedef node_type::map_type s11n::node_traits< NodeT >::property_map_type

The type uses to store properties for node_type objects.

Definition at line 58 of file traits.hpp.

template<typename NodeT>
typedef node_type::child_list_type s11n::node_traits< NodeT >::child_list_type

The type used to store children of node_type objects.

Definition at line 65 of file traits.hpp.


Member Function Documentation

template<typename NodeT>
static node_type* s11n::node_traits< NodeT >::create (  )  [inline, static]

Returns a new node_type.

The caller owns the returned pointer.

It is illegal for this function to return 0. If it cannot create a node for some reason, it must throw an exception.

Definition at line 78 of file traits.hpp.

Referenced by s11nlite::client_api< NodeType >::serialize_subnode().

template<typename NodeT>
static node_type* s11n::node_traits< NodeT >::create ( const std::string &  nodename  )  [inline, static]

Returns a new node_type with the given name.

The caller owns the returned pointer.

See create() for the no-null-return rule.

Definition at line 89 of file traits.hpp.

References s11n::fac::create().

template<typename NodeT>
template<typename ValueT>
static void s11n::node_traits< NodeT >::set ( node_type node,
const std::string &  key,
const ValueT &  value 
) [inline, static]

Sets the property key to the given value in the given node.

ValueT must support complementary ostream<< and istream>> operators.

Definition at line 105 of file traits.hpp.

template<typename NodeT>
static void s11n::node_traits< NodeT >::unset ( node_type node,
const std::string &  key 
) [inline, static]

Unsets (removes) the given property from node.

It is not an error to unset an non-existing key.

Definition at line 116 of file traits.hpp.

template<typename NodeT>
static bool s11n::node_traits< NodeT >::is_set ( const node_type node,
const std::string &  key 
) [inline, static]

Returns true if node contains a property named key, else returns false.

Definition at line 126 of file traits.hpp.

template<typename NodeT>
static const property_map_type& s11n::node_traits< NodeT >::properties ( const node_type node  )  [inline, static]

Returns an immutable reference to the node's map of properties.

Definition at line 136 of file traits.hpp.

template<typename NodeT>
static property_map_type& s11n::node_traits< NodeT >::properties ( node_type node  )  [inline, static]

Returns a mutable reference to the node's map of properties.

Definition at line 144 of file traits.hpp.

template<typename NodeT>
template<typename ValueT>
static ValueT s11n::node_traits< NodeT >::get ( const node_type node,
const std::string &  key,
const ValueT &  default_value 
) [inline, static]

Returns the value of the property with the given key, or default_value if that property does not exist or cannot be lexically cast to type ValueT.

ValueT must support complementary ostream<< and istream>> operators.

Definition at line 159 of file traits.hpp.

template<typename NodeT>
static child_list_type& s11n::node_traits< NodeT >::children ( node_type node  )  [inline, static]

Returns a mutable list of children belonging to node.

Definition at line 170 of file traits.hpp.

Referenced by s11n::util::node_tree< NodeT >::children_of(), s11n::util::node_tree< NodeT >::climb_tree(), s11n::util::node_tree< NodeT >::reparent(), s11nlite::client_api< NodeType >::serialize_subnode(), and s11n::util::node_tree< NodeT >::take_node().

template<typename NodeT>
static const child_list_type& s11n::node_traits< NodeT >::children ( const node_type node  )  [inline, static]

Returns an immutable list of children belonging to node.

Definition at line 179 of file traits.hpp.

template<typename NodeT>
static void s11n::node_traits< NodeT >::class_name ( node_type node,
const std::string &  classname 
) [inline, static]

Sets the class name of the type for which node holds serialized data.

Definition at line 188 of file traits.hpp.

template<typename NodeT>
static std::string s11n::node_traits< NodeT >::class_name ( const node_type node  )  [inline, static]

Returns the class name of the type for which node holds serialized data.

Definition at line 198 of file traits.hpp.

template<typename NodeT>
static void s11n::node_traits< NodeT >::name ( node_type node,
const std::string &  name 
) [inline, static]

Sets node's name.

See the s11n lib manual for what conventions to follow. In short: the "variable name" rules from most programming languages are a good guideline.

Definition at line 209 of file traits.hpp.

Referenced by s11n::Detail::same_name< NodeT >::operator()().

template<typename NodeT>
static std::string s11n::node_traits< NodeT >::name ( const node_type node  )  [inline, static]

Returns node's name.

Definition at line 218 of file traits.hpp.

template<typename NodeT>
static void s11n::node_traits< NodeT >::clear ( node_type node  )  [inline, static]

Removes all children and properties from node, freeing up their resources.

Whether the node's name() and class_name() are cleared is implementation-defined. In practice, those are overwritten by algos as needed, so it has not been a concern.

Definition at line 231 of file traits.hpp.

template<typename NodeT>
static bool s11n::node_traits< NodeT >::empty ( const node_type node  )  [inline, static]

Returns true if this object has no properties and no children.

The name() and class_name() are *not* considered.

Added in version 1.1.3.

Definition at line 243 of file traits.hpp.

template<typename NodeT>
static void s11n::node_traits< NodeT >::swap ( node_type lhs,
node_type rhs 
) [inline, static]

Swaps all publically-visible internal state of lhs with that of rhs.

This includes:

Added in version 1.1.3.

Definition at line 262 of file traits.hpp.


The documentation for this struct was generated from the following file:
Generated on Sun Apr 27 11:46:50 2008 for libs11n-1.2.6 by  doxygen 1.5.3