/** \file
\brief Node non-inline template implementation */
-//#include "Node.ih"
+#include "Node.ih"
// Custom includes
#include <boost/range.hpp>
template <class ForwardRange>
prefix_ senf::console::GenericNode &
-senf::console::DirectoryNode::traverse(ForwardRange const & range, bool autocomplete)
+senf::console::DirectoryNode::traverse(ForwardRange const & range, bool autocomplete,
+ DirectoryNode & root)
{
typedef typename boost::range_const_iterator<ForwardRange>::type const_iterator;
- DirectoryNode::ptr dir (thisptr());
+ detail::NodeTraverser traverser (root, *this, autocomplete);
const_iterator i (boost::begin(range));
const_iterator const i_end (boost::end(range));
- if (i != i_end && *i == std::string("")) {
- dir = root().thisptr();
- ++ i;
- }
- while (i != i_end) {
- const_iterator next_i (i);
- ++ next_i;
- if (*i == std::string("..")) {
- dir = dir->parent();
- if (! dir)
- dir = root().thisptr();
- }
- else if (*i != std::string("") && *i != std::string(".")) {
- std::string name (*i);
- if (! dir->hasChild(name) && autocomplete) {
- ChildrenRange completions (dir->completions(name));
- if (completions.size() == 1)
- name = completions.begin()->first;
- }
- if (next_i == i_end)
- return dir->get(name);
- else {
- // Why does g++ give an error on this line ???? :
- // dir = dynamic_cast<DirectoryNode&>( dir->get(name) ).thisptr();
- DirectoryNode & d (dynamic_cast<DirectoryNode&>( dir->get(name) ));
- dir = d.thisptr();
- }
- }
- i = next_i;
- }
- return *dir;
+ for (; i != i_end; ++i)
+ traverser( *i );
+ return traverser.node();
}
///////////////////////////////ct.e////////////////////////////////////////