X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Console%2FNode.cc;h=1cd8d40bf7d71bb9ec7fc88a29413dff187035f9;hb=d2459b6c8249291588fd3d0d125ed3d38e003b55;hp=382804fefcde2eea0cdeb7753de059533b90b75b;hpb=70905bebad1f8c394fceb3a5d2a493eeecf3bd13;p=senf.git diff --git a/Console/Node.cc b/Console/Node.cc index 382804f..1cd8d40 100644 --- a/Console/Node.cc +++ b/Console/Node.cc @@ -34,7 +34,7 @@ prefix_ senf::console::DirectoryNode & senf::console::root() { - static DirectoryNode::ptr rootNode(new DirectoryNode("")); + static DirectoryNode::ptr rootNode(new DirectoryNode()); return *rootNode; } @@ -53,22 +53,48 @@ prefix_ std::string senf::console::GenericNode::path() return path.empty() ? "/" : path; } +prefix_ bool senf::console::GenericNode::active() + const +{ + cptr node (thisptr()); + while (node->parent()) + node = node->parent(); + return node == root().thisptr(); +} + /////////////////////////////////////////////////////////////////////////// //senf::console::DirectoryNode -prefix_ void senf::console::DirectoryNode::add(GenericNode::ptr node, bool uniquify) +prefix_ senf::console::GenericNode::ptr +senf::console::DirectoryNode::remove(std::string const & name) +{ + ChildMap::iterator i (children_.find(name)); + if (i == children_.end()) + throw UnknownNodeNameException() << ": '" << name << "'"; + GenericNode::ptr node (i->second); + children_.erase(i); + node->parent_ = 0; + node->name_.clear(); + return node; +} + +prefix_ void senf::console::DirectoryNode::add(GenericNode::ptr node) { BOOST_ASSERT( ! node->parent() ); + if (node->name().empty()) { + node->name("unnamed"); + SENF_LOG((senf::log::MESSAGE)("Adding 'unnamed' node")); + } if (children_.find(node->name()) != children_.end()) { - if (! uniquify) - throw DuplicateNodeNameException() << ": '" << node->name() << "'"; unsigned suffix (0); std::string newName; do { ++suffix; - newName = node->name() + boost::lexical_cast(suffix); + newName = node->name() + "-" + boost::lexical_cast(suffix); } while (children_.find(newName) != children_.end()); - name(*node, newName); + SENF_LOG((senf::log::MESSAGE)("Uniquifying node '" << node->name() << "' to '" + << newName << "'")); + node->name(newName); } children_.insert(std::make_pair(node->name(),node)); node->parent_ = this; @@ -84,6 +110,37 @@ senf::console::DirectoryNode::get(std::string const & name) return *(i->second); } +prefix_ void senf::console::DirectoryNode::v_help(std::ostream & output) + const +{ + output << doc_ << "\n"; +} + +/////////////////////////////////////////////////////////////////////////// +// senf::console::SyntaxErrorException + +prefix_ char const * senf::console::SyntaxErrorException::what() + const throw() +{ + return message().empty() ? "syntax error" : message().c_str(); +} + +/////////////////////////////////////////////////////////////////////////// +// senf::console::SimpleCommandNode + +prefix_ void senf::console::SimpleCommandNode::v_help(std::ostream & output) + const +{ + output << doc_ << "\n"; +} + +prefix_ void senf::console::SimpleCommandNode::v_execute(std::ostream & output, + Arguments const & arguments) + const +{ + fn_(output, arguments); +} + ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_ //#include "Node.mpp"