senf::console::DirectoryNode Class Reference
[The node tree]

Config/console tree directory node. More...

#include <senf/Utils/Console/Node.hh>

Inheritance diagram for senf::console::DirectoryNode:
Inheritance graph
[legend]

List of all members.


Detailed Description

Config/console tree directory node.

This node type provides the internal and root nodes of the tree. It allows to add arbitrary children and supports directory traversal.

Nodes are normally not instantiated manually but are created using factory calls. Special add() members however allow externally allocated node objects.

Nodes may be added to the tree only once, otherwise chaos will ensue. Since nodes are always managed dynamically, there is a special ScopedDirectory proxy template which provides a DirectoryNode facade. ScopedDirectory is used if a class wants to manage it's own directory as a data member.

Every node is assigned a (new) name when it is added to a directory. If the directory already has an entry of that name, the name is made unique by appending a suffix of the form '-n' where n is a number starting at 1. If the name is empty, int is set to 'unnamed' and then uniquified as above. Automatically providing unique names simplifies adding configuration/console support to generic components.

Definition at line 406 of file Node.hh.


Public Types

typedef boost::shared_ptr
< DirectoryNode
ptr
typedef boost::shared_ptr
< DirectoryNode const > 
cptr
typedef boost::weak_ptr
< DirectoryNode
weak_ptr
typedef boost::iterator_range
< ChildMap::const_iterator > 
ChildrenRange
typedef ChildMap::const_iterator  child_iterator
typedef DirectoryNode  node_type
typedef DirectoryNode return_type

Public Member Functions

DirectoryNode doc (std::string const &doc)
  Set node documentation.
DirectoryNode shortdoc (std::string const &doc)
  Set node short documentation.
ptr  thisptr ()
  Get smart pointer to node.
cptr  thisptr () const
  Get smart pointer to node (const).

Structors and default members

static ptr  create ()
  Create node object.
  ~DirectoryNode ()

Children

template<class NodeType >
NodeType &  add (std::string const &name, boost::shared_ptr< NodeType > node)
  Add node to tree.
template<class NodeType >
NodeType &  add (std::string const &name, NodeType &node, typename boost::enable_if< boost::is_convertible< NodeType &, GenericNode & > >::type *=0)
template<class Factory >
Factory::result_type  add (std::string const &name, Factory const &factory, typename boost::enable_if< boost::is_convertible< Factory const &, detail::NodeFactory const & > >::type *=0)
  Generic child node factory.
GenericNode::ptr  remove (std::string const &name)
  Remove node name from the tree.
bool  hasChild (std::string const &name) const
  true, if there is a child with name name
GenericNode get (std::string const &name) const
  Get child node automatically dereferencing links.
GenericNode getLink (std::string const &name) const
  Get child node without dereferencing links.
DirectoryNode getDirectory (std::string const &name) const
  Get directory child node (dereferencing links).
DirectoryNode operator[] (std::string const &name) const
  Get directory child node (dereferencing links).
CommandNode getCommand (std::string const &name) const
  Get command child node (dereferencing links).
CommandNode operator() (std::string const &name) const
  Get command child node (dereferencing links).
ChildrenRange  children () const
  Return iterator range over all children.
ChildrenRange  completions (std::string const &s) const
  Return iterator range of completions for s.

Protected Member Functions

  DirectoryNode ()

Friends

DirectoryNode root ()
  Get console root node.

Member Typedef Documentation

typedef ChildMap::const_iterator senf::console::DirectoryNode::
child_iterator

Definition at line 419 of file Node.hh.

typedef boost::iterator_range<ChildMap::const_iterator> senf::console::DirectoryNode::
ChildrenRange

Definition at line 418 of file Node.hh.

typedef boost::shared_ptr<DirectoryNode const> senf::console::DirectoryNode::
cptr

Reimplemented from senf::console::GenericNode.

Definition at line 415 of file Node.hh.

typedef DirectoryNode senf::console::DirectoryNode::
node_type

Definition at line 421 of file Node.hh.

typedef boost::shared_ptr<DirectoryNode> senf::console::DirectoryNode::
ptr

Reimplemented from senf::console::GenericNode.

Definition at line 414 of file Node.hh.

typedef DirectoryNode& senf::console::DirectoryNode::
return_type

Definition at line 422 of file Node.hh.

typedef boost::weak_ptr<DirectoryNode> senf::console::DirectoryNode::
weak_ptr

Reimplemented from senf::console::GenericNode.

Definition at line 416 of file Node.hh.


Constructor & Destructor Documentation

senf::console::DirectoryNode::
~DirectoryNode ()

Definition at line 135 of file Node.cc.

senf::console::DirectoryNode::
DirectoryNode ()

Definition at line 228 of file Node.cci.


Member Function Documentation

template<class Factory >
Factory::result_type senf::console::DirectoryNode::
add ( std::string const &  name,
Factory const &  factory,
typename boost::enable_if< boost::is_convertible< Factory const &, detail::NodeFactory const & > >::type = 0 )

Generic child node factory.

This member is used to create a new child node of the current directory. The type of node created depends on the type of argument passed.

Definition at line 58 of file Node.cti.

template<class NodeType >
NodeType & senf::console::DirectoryNode::
add ( std::string const &  name,
NodeType &  node,
typename boost::enable_if< boost::is_convertible< NodeType &, GenericNode & > >::type = 0 )

Definition at line 48 of file Node.cti.

template<class NodeType >
NodeType & senf::console::DirectoryNode::
add ( std::string const &  name,
boost::shared_ptr< NodeType >  node )

Add node to tree.

Adds the node to the tree as a child of this node. The node is given the name name. If a node of that name already exists, a numeric suffix of the form '-n' is added to the name until the name is unique. If name is empty, it is set to 'unnamed'.

Definition at line 37 of file Node.cti.

senf::console::DirectoryNode::ChildrenRange senf::console::DirectoryNode::
children ()

Return iterator range over all children.

The returned range is sorted by child name.

Definition at line 214 of file Node.cci.

senf::console::DirectoryNode::ChildrenRange senf::console::DirectoryNode::
completions ( std::string const &  s )

Return iterator range of completions for s.

The returned range is sorted by child name.

Definition at line 221 of file Node.cci.

senf::console::DirectoryNode::ptr senf::console::DirectoryNode::
create ()

Create node object.

You should normally use either mkdir() or ScopedDirectory instead of create()

Definition at line 161 of file Node.cci.

senf::console::DirectoryNode & senf::console::DirectoryNode::
doc ( std::string const &  doc )

Set node documentation.

Definition at line 232 of file Node.cci.

senf::console::GenericNode & senf::console::DirectoryNode::
get ( std::string const &  name )

Get child node automatically dereferencing links.

Exceptions:
UnknownNodeNameException  if a child name does not exist

Definition at line 174 of file Node.cci.

senf::console::CommandNode & senf::console::DirectoryNode::
getCommand ( std::string const &  name )

Get command child node (dereferencing links).

Same as operator()

Exceptions:
UnknownNodeNameException  if a child name does not exist
std::bad_cast  if the child name is not a command node.

Definition at line 198 of file Node.cci.

senf::console::DirectoryNode & senf::console::DirectoryNode::
getDirectory ( std::string const &  name )

Get directory child node (dereferencing links).

Same as operator[]

Exceptions:
UnknownNodeNameException  if a child name does not exist.
std::bad_cast  if the child name is not a directory node.

Definition at line 181 of file Node.cci.

senf::console::GenericNode & senf::console::DirectoryNode::
getLink ( std::string const &  name )

Get child node without dereferencing links.

Exceptions:
UnknownNodeNameException  if a child name does not exist

Definition at line 179 of file Node.cc.

bool senf::console::DirectoryNode::
hasChild ( std::string const &  name )

true, if there is a child with name name

Definition at line 166 of file Node.cci.

senf::console::CommandNode & senf::console::DirectoryNode::
operator() ( std::string const &  name )

Get command child node (dereferencing links).

Same as getCommand()

Exceptions:
UnknownNodeNameException  if a child name does not exist
std::bad_cast  if the child name is not a command node.

Definition at line 208 of file Node.cci.

senf::console::DirectoryNode & senf::console::DirectoryNode::
operator[] ( std::string const &  name )

Get directory child node (dereferencing links).

Same as getDirectory

Exceptions:
UnknownNodeNameException  if a child name does not exist.
std::bad_cast  if the child name is not a directory node.

Definition at line 191 of file Node.cci.

senf::console::GenericNode::ptr senf::console::DirectoryNode::
remove ( std::string const &  name )

Remove node name from the tree.

The returned pointer may either be discarded, which will automatically dispose the removed node, or it may be saved and/or re-attached at some other place in the tree.

Definition at line 144 of file Node.cc.

senf::console::DirectoryNode & senf::console::DirectoryNode::
shortdoc ( std::string const &  doc )

Set node short documentation.

Definition at line 239 of file Node.cci.

senf::console::DirectoryNode::cptr senf::console::DirectoryNode::
thisptr ()

Get smart pointer to node (const).

Reimplemented from senf::console::GenericNode.

Definition at line 250 of file Node.cci.

senf::console::DirectoryNode::ptr senf::console::DirectoryNode::
thisptr ()

Get smart pointer to node.

Reimplemented from senf::console::GenericNode.

Definition at line 245 of file Node.cci.


Friends And Related Function Documentation

DirectoryNode&
root ()

Get console root node.


The documentation for this class was generated from the following files: