Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members

s11n::io::data_node_tree_builder< NodeType > Class Template Reference

data_node_tree_builder is a helper class for building trees from deserialized data, designed particularly for use with lex/callback-based tree builders. More...

#include <data_node_format.h>

Inheritance diagram for s11n::io::data_node_tree_builder< NodeType >:

s11n::io::tree_builder List of all members.

Public Types

typedef NodeType node_type
typedef std::list< node_type * > child_list_type

Public Member Functions

 data_node_tree_builder ()
 Creates a default builder.

virtual ~data_node_tree_builder ()
 Deletes this object's children if auto_delete() returns true.

bool open_node (const std::string &classname, const std::string &nodename)
 Opens a new node, making that the current node.

virtual bool close_node ()
 Closes the most-recently-opened node, effectively popping the previous node off of the node stack (it is not destroyed).

virtual bool add_property (const std::string &key, const std::string &val)
 Adds the given key/value pair to the current node and returns true.

size_t node_count () const
 Returns the total number of nodes opened via open_node().

size_t node_depth () const
 Returns the current depth of opened nodes.

node_type * root_node () const
 Returns the most recent root node parsed out of the input object.

node_type * current_node () const
 Returns the current node.

virtual bool change_node_class (const std::string &newclassname)
 Changes class name of current node, if one is set.


Detailed Description

template<typename NodeType>
class s11n::io::data_node_tree_builder< NodeType >

data_node_tree_builder is a helper class for building trees from deserialized data, designed particularly for use with lex/callback-based tree builders.

It owns all objects which build up it's tree. If you want them you must manually remove them from the container. You normally do not want them, however - they're mostly throwaway nodes on their way to becoming fully deserialized objects.

This class only provides methods for building a tree, not for traversing it. Once you have built a tree, traverse it starting at the root_node().

Based on usage conventions this type supports only a single root node.

Definition at line 354 of file data_node_format.h.


Member Function Documentation

template<typename NodeType>
virtual bool s11n::io::data_node_tree_builder< NodeType >::add_property const std::string &  key,
const std::string &  val
[inline, virtual]
 

Adds the given key/value pair to the current node and returns true.

If no node is currently opened it returns false.

Implements s11n::io::tree_builder.

Definition at line 467 of file data_node_format.h.

References s11n::io::data_node_tree_builder< NodeType >::add_property().

Referenced by s11n::io::data_node_tree_builder< NodeType >::add_property().

template<typename NodeType>
virtual bool s11n::io::data_node_tree_builder< NodeType >::change_node_class const std::string &  newclassname  )  [inline, virtual]
 

Changes class name of current node, if one is set.

Returns false only if no node is currently opened, else it returns true.

Implements s11n::io::tree_builder.

Definition at line 524 of file data_node_format.h.

References s11n::io::data_node_tree_builder< NodeType >::change_node_class().

Referenced by s11n::io::data_node_tree_builder< NodeType >::change_node_class().

template<typename NodeType>
virtual bool s11n::io::data_node_tree_builder< NodeType >::close_node  )  [inline, virtual]
 

Closes the most-recently-opened node, effectively popping the previous node off of the node stack (it is not destroyed).

It is an error to call this more often than calling open_node().

It returns false on error (e.g., called with no opened node).

Implements s11n::io::tree_builder.

Definition at line 442 of file data_node_format.h.

template<typename NodeType>
node_type* s11n::io::data_node_tree_builder< NodeType >::current_node  )  const [inline]
 

Returns the current node.

Use auto_delete() to determine ownership of the returned pointer.

Definition at line 514 of file data_node_format.h.

template<typename NodeType>
size_t s11n::io::data_node_tree_builder< NodeType >::node_depth  )  const [inline, virtual]
 

Returns the current depth of opened nodes.

A return value of 1 means the current node is the root node, for example, and 0 means that no node has yet been opened.

Implements s11n::io::tree_builder.

Definition at line 489 of file data_node_format.h.

template<typename NodeType>
bool s11n::io::data_node_tree_builder< NodeType >::open_node const std::string &  classname,
const std::string &  nodename
[inline, virtual]
 

Opens a new node, making that the current node.

classname will be used for the node's impl_class() (see docs for node_type::impl_class()). name will be the object's name, which is important for de/serializing the node (see node_type::name()).

It returns false on error, else true. The default implementation has no error conditions, and therefor always returns true.

Node that classnames and node names need not be unique (nor make up unique combinations). Any number of nodes may have the same name or classname.

Implements s11n::io::tree_builder.

Definition at line 400 of file data_node_format.h.

References s11n::io::data_node_tree_builder< NodeType >::open_node().

Referenced by s11n::io::data_node_tree_builder< NodeType >::open_node().

template<typename NodeType>
node_type* s11n::io::data_node_tree_builder< NodeType >::root_node  )  const [inline]
 

Returns the most recent root node parsed out of the input object.

Use auto_delete() to determine ownership of the returned pointer.

Definition at line 502 of file data_node_format.h.


The documentation for this class was generated from the following file:
Generated on Tue Jul 20 10:46:50 2004 for s11n by doxygen 1.3.7