Config/console tree directory node. More...

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

Inheritance diagram for senf::console::DirectoryNode:

Public Types

typedef boost::shared_ptr< DirectoryNodeptr
 
typedef boost::shared_ptr< DirectoryNode const > cptr
 
typedef boost::weak_ptr< DirectoryNodeweak_ptr
 
typedef boost::iterator_range< ChildMap::const_iteratorChildrenRange
 
typedef ChildMap::const_iterator child_iterator
 
typedef DirectoryNode node_type
 
typedef DirectoryNodereturn_type
 
- Public Types inherited from senf::console::GenericNode
typedef boost::shared_ptr< GenericNodeptr
 
typedef boost::shared_ptr< GenericNode const > cptr
 
typedef boost::weak_ptr< GenericNodeweak_ptr
 

Public Member Functions

DirectoryNodedoc (std::string const &doc)
 Set node documentation. More...
 
DirectoryNodeshortdoc (std::string const &doc)
 Set node short documentation. More...
 
ptr thisptr ()
 
cptr thisptr () const
 
- Public Member Functions inherited from senf::console::GenericNode
virtual ~GenericNode ()
 
std::string const & name () const
 Node name. More...
 
boost::shared_ptr< DirectoryNodeparent () const
 Parent node. More...
 
std::string path () const
 Node path. More...
 
std::string path (DirectoryNode const &root) const
 Node path up to root. More...
 
ptr unlink ()
 Remove node from it's parent directory. More...
 
void rename (std::string const &newName)
 Rename node name in it's parent directory. More...
 
bool active () const
 true, if node is attached to the root() node More...
 
void help (std::ostream &output) const
 Write help info to output. More...
 
std::string shorthelp () const
 Get short (one-line) documentation. More...
 
ptr thisptr ()
 Get smart pointer to node. More...
 
cptr thisptr () const
 Get smart pointer to node (const) More...
 
bool isChildOf (DirectoryNode &parent) const
 true, if node is a child of parent More...
 
bool operator== (GenericNode &other) const
 true, if this and other are the same node More...
 
bool operator!= (GenericNode &other) const
 true, if this and other are different nodes More...
 
bool isDirectory () const
 true, if this is a directory node More...
 
bool isLink () const
 true, if this is a link node More...
 
bool isCommand () const
 true, if this is a command node More...
 
GenericNode const & followLink () const
 Follow link if this node is a link node. More...
 
GenericNodefollowLink ()
 Follow link if this node is a link node. More...
 

Protected Member Functions

 DirectoryNode ()
 
- Protected Member Functions inherited from senf::console::GenericNode
 GenericNode ()
 
void name (std::string const &name)
 

Friends

DirectoryNoderoot ()
 Get console root node. More...
 

Structors and default members

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

Children

template<class NodeType >
NodeType & add (std::string const &name, boost::shared_ptr< NodeType > node)
 Add node to tree. More...
 
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. More...
 
GenericNode::ptr remove (std::string const &name)
 Remove node name from the tree. More...
 
GenericNode::ptr remove (std::string const &name, NoThrow_t)
 Remove node name from the tree. More...
 
bool hasChild (std::string const &name) const
 true, if there is a child with name name More...
 
GenericNodeget (std::string const &name) const
 Get child node automatically dereferencing links. More...
 
GenericNodegetLink (std::string const &name) const
 Get child node without dereferencing links. More...
 
DirectoryNodegetDirectory (std::string const &name) const
 Get directory child node (dereferencing links) More...
 
DirectoryNodeoperator[] (std::string const &name) const
 Get directory child node (dereferencing links) More...
 
CommandNodegetCommand (std::string const &name) const
 Get command child node (dereferencing links) More...
 
CommandNodeoperator() (std::string const &name) const
 Get command child node (dereferencing links) More...
 
ChildrenRange children () const
 Return iterator range over all children. More...
 
ChildrenRange completions (std::string const &s) const
 Return iterator range of completions for s. More...
 

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.

Member Typedef Documentation

◆ child_iterator

◆ ChildrenRange

Definition at line 418 of file Node.hh.

◆ cptr

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

Definition at line 415 of file Node.hh.

◆ node_type

◆ ptr

Definition at line 414 of file Node.hh.

◆ return_type

◆ weak_ptr

Definition at line 416 of file Node.hh.

Constructor & Destructor Documentation

◆ ~DirectoryNode()

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

Definition at line 142 of file Node.cc.

◆ DirectoryNode()

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

Member Function Documentation

◆ add() [1/3]

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'.

◆ add() [2/3]

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 
)

◆ add() [3/3]

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.

◆ children()

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

Return iterator range over all children.

The returned range is sorted by child name.

◆ completions()

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

Return iterator range of completions for s.

The returned range is sorted by child name.

◆ create()

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

Create node object.

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

◆ doc()

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

Set node documentation.

◆ get()

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

Get child node automatically dereferencing links.

Exceptions
UnknownNodeNameExceptionif a child name does not exist

◆ getCommand()

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

Get command child node (dereferencing links)

Same as operator()

Exceptions
UnknownNodeNameExceptionif a child name does not exist
std::bad_castif the child name is not a command node.

◆ getDirectory()

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

Get directory child node (dereferencing links)

Same as operator[]

Exceptions
UnknownNodeNameExceptionif a child name does not exist.
std::bad_castif the child name is not a directory node.

◆ getLink()

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

Get child node without dereferencing links.

Exceptions
UnknownNodeNameExceptionif a child name does not exist

Definition at line 195 of file Node.cc.

◆ hasChild()

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

true, if there is a child with name name

◆ operator()()

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

Get command child node (dereferencing links)

Same as getCommand()

Exceptions
UnknownNodeNameExceptionif a child name does not exist
std::bad_castif the child name is not a command node.

◆ operator[]()

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

Get directory child node (dereferencing links)

Same as getDirectory

Exceptions
UnknownNodeNameExceptionif a child name does not exist.
std::bad_castif the child name is not a directory node.

◆ remove() [1/2]

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 160 of file Node.cc.

◆ remove() [2/2]

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

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 151 of file Node.cc.

◆ shortdoc()

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

Set node short documentation.

◆ thisptr() [1/2]

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

◆ thisptr() [2/2]

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

Friends And Related Function Documentation

◆ root

DirectoryNode& root ( )
friend

Get console root node.


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