S3FC project page | S3FC home page |
#include <s3_config_node.h>
Collaboration diagram for s3_config_node:
Public Types | |
typedef std::map< std::string, std::string > | map_type |
Public Methods | |
s3_config_node (const std::string &n_name="", const std::string &n_value="", const s3_config_node *n_parent=&empty_node, const std::map< std::string, std::string > &n_attributes=map_type(), const std::vector< s3_config_node > &n_children=std::vector< s3_config_node >()) | |
Initialising constructor: create with supplied values. More... | |
s3_config_node (const s3_config_node &src) | |
Copy constructor: construct as a deep copy of the argument s3_config_node . More... | |
s3_config_node & | operator= (const s3_config_node &src) |
Copy assignment operator. More... | |
bool | empty () const |
Test whether this is an empty node. More... | |
bool | is_rootnode () const |
Return true if this node is a rootnode (a node with no parent). More... | |
s3_config_node *& | parent () |
Return a reference to the pointer to the parent node. More... | |
std::string & | name () |
Return a reference to the node name. More... | |
std::string & | value () |
Return a reference to the node value. More... | |
std::map< std::string, std::string > & | attributes () |
Return a reference to the attributes. More... | |
std::vector< s3_config_node > & | children () |
Return a reference to the list of children. More... | |
s3_config_node * | insert_child (const s3_config_node &child=empty_node, const s3_config_node &before=at_end) |
Add a child before the specified child. More... | |
void | remove_child (const s3_config_node &child) |
Remove the specified child from the list of children. More... | |
const s3_config_node & | get_parent () const |
Return a const reference to the parent node. More... | |
s3_config_node & | get_parent () |
Return a reference to the parent node. More... | |
void | set_parent (s3_config_node &n_parent) |
Set the parent of this node. More... | |
const std::string & | get_name () const |
Return the name of the node. More... | |
void | set_name (const std::string &n_name) |
Set the name of the node. More... | |
const std::string & | get_value () const |
Return raw character data stored in the node. More... | |
void | set_value (const std::string &n_value) |
Set the value of the node. More... | |
template<typename T> T | get_value () const |
Return a copy of the raw character data stored in the node, converted to type T . More... | |
template<typename T> void | set_value (const T &n_value) |
Set the value of the node. More... | |
const std::map< std::string, std::string > & | get_attributes () const |
Return a const reference to the map of all attribute name/value pairs, keyed on name. More... | |
std::map< std::string, std::string > & | get_attributes () |
Return a reference to the map of all attribute name/value pairs, keyed on name. More... | |
unsigned int | get_num_children () const |
Return the number of child nodes. More... | |
const s3_config_node & | get_child (unsigned int i) const |
Return a const reference to the i 'th child. More... | |
s3_config_node & | get_child (unsigned int i) |
Return a reference to the i 'th child. More... | |
const std::vector< const s3_config_node * > | get_children (const std::string &name_filter="") const |
Return a const list of pointers to const child nodes. More... | |
std::vector< s3_config_node * > | get_children (const std::string &name_filter="") |
Return a list of pointers to child nodes. More... | |
bool | node_exists (const std::string &path) const |
Return a flag indicating whether a specified node exists. More... | |
const s3_config_node & | get_node_at (const std::string &path) const |
Return a const reference to an s3_config_node which resides at a specified position in the tree hierarchy. More... | |
s3_config_node & | get_node_at (const std::string &path) |
Return a reference to an s3_config_node which resides at a specified position in the tree hierarchy. More... | |
template<typename T> T | get_value_at (const std::string &path) const |
Return a copy of the raw character data stored in the node which resides at a specified position in the tree hierarchy, converted to the specified type. More... | |
template<typename T> T | get_attribute_at (const std::string &attr_name) const |
Return a copy of the data stored in the attribute with the given name for the current node, converted to the specified type. More... | |
Static Public Attributes | |
s3_config_node | empty_node |
Static empty node used to return ref to empty node. More... | |
s3_config_node | at_end |
Static empty node used to indicate insertion of child at end. More... | |
Protected Methods | |
std::vector< s3_config_node >::iterator | find_child (const s3_config_node &child) |
Search through a_children for the specified child, child and return iterator pointing to it. More... | |
const s3_config_node * | gna_helper (const std::string &path) const |
Protected Attributes | |
std::string | a_name |
Name. More... | |
std::string | a_value |
Value. More... | |
s3_config_node * | a_parent |
Parent. More... | |
std::map< std::string, std::string > | a_attributes |
Attributes. More... | |
std::vector< s3_config_node > | a_children |
Children. More... |
Nodes are structured in a tree and each node has a name which need not be unique. Nodes can optionally contain one or more of the following:
The following tree operations are supported:
get_name()]
get_value()]
get_children()]
get_child_by_name()]
get_children_by_name()]
get_attributes()]
get_attribute_by_name()]
empty()]
. This allows a "not found" value to be returned by some calls.
A node can be (copy) constructed from another node, in which case the contents of the entire source node (name, value, attributes and children) is recursively deep copied into the new node. The source node is left unchanged by this maneuver. The new node is created as an orphaned node (one containing no parent).
A node can be copy assigned from another node. The behaviour is similar to copy construction in that the entire source node (name, value, attributes and children) is recursively deep copied into the existing node. The children that the destination node has at the invocation of the assignment are first removed (and therefore deallocated to disappear forever as a node owns its children), before the recusive deep copy takes place. The parent of the destination node is left unchanged and copy assignment therefore does not change the location of a node in a tree.
A node owns its children and they are therefore deallocated when they are removed from a node, using remove_child()
.
Definition at line 89 of file s3_config_node.h.
|
Definition at line 126 of file s3_config_node.h. |
|
Initialising constructor: create with supplied values.
Definition at line 53 of file s3_config_node.cc. References a_children. |
|
Copy constructor: construct as a deep copy of the argument
The new instance has NO parent and all the immediate children of it has itself as the parent. This is applied recursively. Therefore, copy constructing a node from another one, creates a completely independent copy of the tree rooted at Note that this affects the way that recursive calls to traverse the tree are made. You must pass a reference to a node in order not to orphan it and thus mess up you traverse. The following code fragment demonstrates a function that locates all nodes in the tree with a particular name void find(const s3_config_node& node, const string& pattern, s3_config_node_list& nl) { if (node.get_name() == pattern) // Found a match { nl.push_back(node); } for (unsigned int i = 0; i < node.get_num_children(); i++) { find(node.get_child(i), pattern, nl); } } Note that the s3_config_node is passed by reference to avoid the copy constructor being called when the function recurses, thus losing its parents.
Definition at line 74 of file s3_config_node.cc. References a_children. |
|
Return a reference to the attributes. Note: This is deprecated, don't use. Definition at line 137 of file s3_config_node.cc. References a_attributes. |
|
Return a reference to the list of children. Note: This is deprecated, don't use. Definition at line 143 of file s3_config_node.cc. References a_children. |
|
Test whether this is an empty node.
Definition at line 107 of file s3_config_node.cc. References empty_node. |
|
Search through If it is not found, the past-end iterator is returned.
Definition at line 192 of file s3_config_node.cc. References a_children. Referenced by insert_child, and remove_child. |
|
Return a copy of the data stored in the attribute with the given name for the current node, converted to the specified type.
Definition at line 55 of file s3_config_node.tcc. References a_attributes. |
|
Return a reference to the map of all attribute name/value pairs, keyed on name.
Definition at line 261 of file s3_config_node.cc. References a_attributes. |
|
Return a const reference to the map of all attribute name/value pairs, keyed on name.
Definition at line 255 of file s3_config_node.cc. References a_attributes. Referenced by s3_xml_config::write_node. |
|
Return a reference to the
Definition at line 285 of file s3_config_node.cc. |
|
Return a const reference to the
Definition at line 273 of file s3_config_node.cc. References a_children, and get_num_children. Referenced by s3_xml_config::write_node. |
|
Return a list of pointers to child nodes. An optional argument specifies a name filter to apply: only children with matching names are returned in the list.
Definition at line 311 of file s3_config_node.cc. |
|
Return a const list of pointers to const child nodes. An optional argument specifies a name filter to apply: only children with matching names are returned in the list.
Definition at line 293 of file s3_config_node.cc. References a_children. Referenced by gna_helper. |
|
Return the name of the node.
Definition at line 231 of file s3_config_node.cc. References a_name. Referenced by s3_xml_config::write_node. |
|
Return a reference to an
The path to the requested node is specified in the same way as for
Definition at line 341 of file s3_config_node.cc. |
|
Return a const reference to an
The path to the requested node is specified in the same way as for
Definition at line 327 of file s3_config_node.cc. References gna_helper. Referenced by get_value_at. |
|
Return the number of child nodes.
Definition at line 267 of file s3_config_node.cc. References a_children. Referenced by get_child, and s3_xml_config::write_node. |
|
Return a reference to the parent node.
Definition at line 219 of file s3_config_node.cc. References a_parent. |
|
Return a const reference to the parent node.
Definition at line 213 of file s3_config_node.cc. References a_parent. |
|
Return a copy of the raw character data stored in the node, converted to type
This call normally only makes sense if the node does not contain any children, as an implementation may return data representing child nodes with this call.
|
|
Return raw character data stored in the node. This normally only makes sense if the node does not contain any children, as an implementation may return data representing child nodes with this call. This is used to extract data from a node with no children, storing character data.
Definition at line 243 of file s3_config_node.cc. References a_value. Referenced by get_value_at, and s3_xml_config::write_node. |
|
Return a copy of the raw character data stored in the node which resides at a specified position in the tree hierarchy, converted to the specified type.
This is equivalent to calling
Definition at line 46 of file s3_config_node.tcc. References get_node_at, get_value, and value. |
|
Definition at line 348 of file s3_config_node.cc. References get_children, and name. Referenced by get_node_at, and node_exists. |
|
Add a child before the specified child.
Definition at line 149 of file s3_config_node.cc. References a_children, at_end, and find_child. |
|
Return
Definition at line 113 of file s3_config_node.cc. References a_parent, and empty_node. |
|
Return a reference to the node name.
Definition at line 125 of file s3_config_node.cc. References a_name. Referenced by gna_helper. |
|
Return a flag indicating whether a specified node exists.
The node is specified as a path string with format:
Definition at line 319 of file s3_config_node.cc. References gna_helper. |
|
Copy assignment operator. Recursively copy the contents of the source node (and all its children) into this node. The following steps are performed:
Definition at line 90 of file s3_config_node.cc. References a_attributes, a_children, a_name, a_parent, a_value, and empty_node. |
|
Return a reference to the pointer to the parent node.
Definition at line 119 of file s3_config_node.cc. References a_parent. |
|
Remove the specified child from the list of children.
Definition at line 179 of file s3_config_node.cc. References a_children, and find_child. |
|
Set the name of the node.
Definition at line 237 of file s3_config_node.cc. References a_name. |
|
Set the parent of this node.
Definition at line 225 of file s3_config_node.cc. References a_parent. |
|
Set the value of the node.
Definition at line 39 of file s3_config_node.tcc. References a_value. |
|
Set the value of the node.
Definition at line 249 of file s3_config_node.cc. References a_value. |
|
Return a reference to the node value.
Definition at line 131 of file s3_config_node.cc. References a_value. Referenced by get_value_at. |
|
Attributes.
Definition at line 119 of file s3_config_node.h. Referenced by attributes, get_attribute_at, get_attributes, and operator=. |
|
Children.
Definition at line 123 of file s3_config_node.h. Referenced by children, find_child, get_child, get_children, get_num_children, insert_child, operator=, remove_child, and s3_config_node. |
|
Name.
Definition at line 107 of file s3_config_node.h. |
|
Parent.
Definition at line 115 of file s3_config_node.h. Referenced by get_parent, is_rootnode, operator=, parent, and set_parent. |
|
Value.
Definition at line 111 of file s3_config_node.h. |
|
Static empty node used to indicate insertion of child at end.
Definition at line 36 of file s3_config_node.cc. Referenced by insert_child. |
|
Static empty node used to return ref to empty node.
Definition at line 35 of file s3_config_node.cc. Referenced by empty, is_rootnode, and operator=. |
Send comments to: s3fc@stonethree.com |
|