Config/console tree directory node. More...
#include <senf/Utils/Console/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 Types inherited from senf::console::GenericNode | |
typedef boost::shared_ptr< GenericNode > | ptr |
typedef boost::shared_ptr< GenericNode const > | cptr |
typedef boost::weak_ptr< GenericNode > | weak_ptr |
Public Member Functions | |
DirectoryNode & | doc (std::string const &doc) |
Set node documentation. More... | |
DirectoryNode & | shortdoc (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< DirectoryNode > | parent () 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... | |
GenericNode & | followLink () |
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 | |
DirectoryNode & | root () |
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... | |
GenericNode & | get (std::string const &name) const |
Get child node automatically dereferencing links. More... | |
GenericNode & | getLink (std::string const &name) const |
Get child node without dereferencing links. More... | |
DirectoryNode & | getDirectory (std::string const &name) const |
Get directory child node (dereferencing links) More... | |
DirectoryNode & | operator[] (std::string const &name) const |
Get directory child node (dereferencing links) More... | |
CommandNode & | getCommand (std::string const &name) const |
Get command child node (dereferencing links) More... | |
CommandNode & | operator() (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... | |
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.
typedef boost::iterator_range<ChildMap::const_iterator> senf::console::DirectoryNode::ChildrenRange |
typedef boost::shared_ptr<DirectoryNode const> senf::console::DirectoryNode::cptr |
typedef boost::shared_ptr<DirectoryNode> senf::console::DirectoryNode::ptr |
typedef boost::weak_ptr<DirectoryNode> senf::console::DirectoryNode::weak_ptr |
|
protected |
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'.
NodeType& senf::console::DirectoryNode::add | ( | std::string const & | name, |
NodeType & | node, | ||
typename boost::enable_if< boost::is_convertible< NodeType &, GenericNode &> >::type * | = 0 |
||
) |
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.
ChildrenRange senf::console::DirectoryNode::children | ( | ) | const |
Return iterator range over all children.
The returned range is sorted by child name.
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.
|
static |
Create node object.
You should normally use either mkdir() or ScopedDirectory instead of create()
DirectoryNode& senf::console::DirectoryNode::doc | ( | std::string const & | doc | ) |
Set node documentation.
GenericNode& senf::console::DirectoryNode::get | ( | std::string const & | name | ) | const |
Get child node automatically dereferencing links.
UnknownNodeNameException | if a child name does not exist |
CommandNode& senf::console::DirectoryNode::getCommand | ( | std::string const & | name | ) | const |
Get command child node (dereferencing links)
Same as operator()
UnknownNodeNameException | if a child name does not exist |
std::bad_cast | if the child name is not a command node. |
DirectoryNode& senf::console::DirectoryNode::getDirectory | ( | std::string const & | name | ) | const |
Get directory child node (dereferencing links)
Same as operator[]
UnknownNodeNameException | if a child name does not exist. |
std::bad_cast | if the child name is not a directory node. |
senf::console::GenericNode & senf::console::DirectoryNode::getLink | ( | std::string const & | name | ) | const |
Get child node without dereferencing links.
UnknownNodeNameException | if a child name does not exist |
bool senf::console::DirectoryNode::hasChild | ( | std::string const & | name | ) | const |
true
, if there is a child with name name
CommandNode& senf::console::DirectoryNode::operator() | ( | std::string const & | name | ) | const |
Get command child node (dereferencing links)
Same as getCommand()
UnknownNodeNameException | if a child name does not exist |
std::bad_cast | if the child name is not a command node. |
DirectoryNode& senf::console::DirectoryNode::operator[] | ( | std::string const & | name | ) | const |
Get directory child node (dereferencing links)
Same as getDirectory
UnknownNodeNameException | if a child name does not exist. |
std::bad_cast | if the child name is not a directory node. |
senf::console::GenericNode::ptr senf::console::DirectoryNode::remove | ( | std::string const & | name | ) |
senf::console::GenericNode::ptr senf::console::DirectoryNode::remove | ( | std::string const & | name, |
NoThrow_t | |||
) |
DirectoryNode& senf::console::DirectoryNode::shortdoc | ( | std::string const & | doc | ) |
Set node short documentation.
ptr senf::console::DirectoryNode::thisptr | ( | ) |
cptr senf::console::DirectoryNode::thisptr | ( | ) | const |
|
friend |
Get console root node.