4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief Node inline non-template implementation */
30 #define prefix_ inline
31 ///////////////////////////////cci.p///////////////////////////////////////
33 ///////////////////////////////////////////////////////////////////////////
34 // senf::console::GenericNode
36 prefix_ senf::console::GenericNode::ptr senf::console::GenericNode::thisptr()
38 return shared_from_this();
41 prefix_ senf::console::GenericNode::cptr senf::console::GenericNode::thisptr()
44 return shared_from_this();
47 prefix_ senf::console::GenericNode::~GenericNode()
50 prefix_ std::string const & senf::console::GenericNode::name()
56 prefix_ senf::console::GenericNode::GenericNode()
60 prefix_ void senf::console::GenericNode::name(std::string const & name)
65 prefix_ boost::shared_ptr<senf::console::DirectoryNode> senf::console::GenericNode::parent()
68 return boost::static_pointer_cast<DirectoryNode>(
69 parent_ ? parent_->shared_from_this() : ptr() );
72 prefix_ senf::console::GenericNode::ptr senf::console::GenericNode::unlink()
75 return parent()->remove(name());
80 prefix_ void senf::console::GenericNode::help(std::ostream & output)
86 prefix_ std::string senf::console::GenericNode::shorthelp()
92 prefix_ bool senf::console::GenericNode::operator==(GenericNode & other)
95 return this == & other;
98 prefix_ bool senf::console::GenericNode::operator!=(GenericNode & other)
101 return this != & other;
104 prefix_ bool senf::console::GenericNode::isDirectory()
107 return dynamic_cast<DirectoryNode const *>(this);
110 prefix_ bool senf::console::GenericNode::isLink()
113 return dynamic_cast<LinkNode const *>(this);
116 prefix_ bool senf::console::GenericNode::isCommand()
119 return dynamic_cast<CommandNode const *>(this);
122 prefix_ senf::console::GenericNode const & senf::console::GenericNode::followLink()
126 ? dynamic_cast<LinkNode const *>(this)->follow()
130 prefix_ senf::console::GenericNode & senf::console::GenericNode::followLink()
133 ? dynamic_cast<LinkNode *>(this)->follow()
137 ///////////////////////////////////////////////////////////////////////////
138 // senf::console::LinkNode
140 prefix_ senf::console::GenericNode & senf::console::LinkNode::follow()
146 prefix_ senf::console::LinkNode::ptr senf::console::LinkNode::create(GenericNode & node)
148 GenericNode::ptr p (node.thisptr());
149 while ( p->isLink() )
150 p = dynamic_cast<LinkNode&>(*p).follow().thisptr();
151 return ptr(new LinkNode(*p));
154 prefix_ senf::console::LinkNode::LinkNode(GenericNode & node)
155 : node_ (node.thisptr())
158 ///////////////////////////////////////////////////////////////////////////
159 // senf::console::DirectoryNode
161 prefix_ senf::console::DirectoryNode::ptr senf::console::DirectoryNode::create()
163 return ptr(new DirectoryNode());
166 prefix_ bool senf::console::DirectoryNode::hasChild(std::string const & name)
169 ChildMap::const_iterator i (children_.find(name));
170 return i != children_.end();
173 prefix_ senf::console::GenericNode &
174 senf::console::DirectoryNode::get(std::string const & name)
177 return getLink(name).followLink();
180 prefix_ senf::console::DirectoryNode &
181 senf::console::DirectoryNode::getDirectory(std::string const & name)
185 return dynamic_cast<DirectoryNode&>(get(name));
187 SENF_WRAP_EXC(std::bad_cast)
190 prefix_ senf::console::DirectoryNode &
191 senf::console::DirectoryNode::operator[](std::string const & name)
194 return getDirectory(name);
197 prefix_ senf::console::CommandNode &
198 senf::console::DirectoryNode::getCommand(std::string const & name)
202 return dynamic_cast<CommandNode&>(get(name));
204 SENF_WRAP_EXC(std::bad_cast)
207 prefix_ senf::console::CommandNode &
208 senf::console::DirectoryNode::operator()(std::string const & name)
211 return getCommand(name);
214 prefix_ senf::console::DirectoryNode::ChildrenRange senf::console::DirectoryNode::children()
217 return boost::make_iterator_range(children_.begin(), children_.end());
220 prefix_ senf::console::DirectoryNode::ChildrenRange
221 senf::console::DirectoryNode::completions(std::string const & s)
224 return boost::make_iterator_range(children_.lower_bound(s),
225 children_.lower_bound(s + "\xff"));
228 prefix_ senf::console::DirectoryNode::DirectoryNode()
231 prefix_ senf::console::DirectoryNode &
232 senf::console::DirectoryNode::doc(std::string const & doc)
238 prefix_ senf::console::DirectoryNode &
239 senf::console::DirectoryNode::shortdoc(std::string const & doc)
245 prefix_ senf::console::DirectoryNode::ptr senf::console::DirectoryNode::thisptr()
247 return boost::static_pointer_cast<DirectoryNode>(shared_from_this());
250 prefix_ senf::console::DirectoryNode::cptr senf::console::DirectoryNode::thisptr()
253 return boost::static_pointer_cast<DirectoryNode const>(shared_from_this());
256 ///////////////////////////////////////////////////////////////////////////
257 // senf::console::detail::NodeTraverser
260 prefix_ senf::console::detail::NodeTraverser::NodeTraverser(DirectoryNode & root,
263 : root_ (root), dir_ (dir.thisptr()), autocomplete_ (autocomplete), init_ (false)
268 ///////////////////////////////////////////////////////////////////////////
269 // senf::console::CommandNode
271 prefix_ senf::console::CommandNode::ptr senf::console::CommandNode::thisptr()
273 return boost::static_pointer_cast<CommandNode>(shared_from_this());
276 prefix_ senf::console::CommandNode::cptr senf::console::CommandNode::thisptr()
279 return boost::static_pointer_cast<CommandNode const>(shared_from_this());
282 prefix_ senf::console::CommandNode::CommandNode()
285 prefix_ void senf::console::CommandNode::execute(std::ostream & output,
286 ParseCommandInfo const & command)
290 execute(rv, output, command);
293 prefix_ void senf::console::CommandNode::execute(boost::any & rv, std::ostream & output,
294 ParseCommandInfo const & command)
298 v_execute(rv, output, command);
301 prefix_ void senf::console::CommandNode::operator()(std::ostream & output,
302 ParseCommandInfo const & command)
305 execute(output, command);
308 prefix_ void senf::console::CommandNode::operator()(boost::any & rv, std::ostream & output,
309 ParseCommandInfo const & command)
312 execute(rv, output, command);
315 ///////////////////////////////////////////////////////////////////////////
316 // senf::console::SimpleCommandNode
318 prefix_ senf::console::SimpleCommandNode::SimpleCommandNode(Function const & fn)
322 prefix_ senf::console::SimpleCommandNode::ptr
323 senf::console::SimpleCommandNode::create(Function const & fn)
325 return ptr(new SimpleCommandNode(fn));
328 prefix_ senf::console::SimpleCommandNode &
329 senf::console::SimpleCommandNode::doc(std::string const & doc)
335 prefix_ senf::console::SimpleCommandNode &
336 senf::console::SimpleCommandNode::shortdoc(std::string const & doc)
342 prefix_ senf::console::SimpleCommandNode::ptr senf::console::SimpleCommandNode::thisptr()
344 return boost::static_pointer_cast<SimpleCommandNode>(shared_from_this());
347 prefix_ senf::console::SimpleCommandNode::cptr senf::console::SimpleCommandNode::thisptr()
350 return boost::static_pointer_cast<SimpleCommandNode const>(shared_from_this());
353 ///////////////////////////////////////////////////////////////////////////
355 prefix_ senf::console::DirectoryNode & senf::console::provideDirectory(DirectoryNode & dir,
356 std::string const & name)
358 return dir.hasChild(name) ? dir.getDirectory(name) : dir.add(name, factory::Directory());
362 ///////////////////////////////////////////////////////////////////////////
363 // senf::console::factory::SimpleCommand
365 prefix_ senf::console::factory::SimpleCommand::SimpleCommand(SimpleCommandNode::Function fn)
366 : node_ (SimpleCommandNode::create(fn))
369 prefix_ senf::console::SimpleCommandNode &
370 senf::console::factory::SimpleCommand::create(DirectoryNode & dir, std::string const & name)
373 return dir.add(name, node_);
376 prefix_ senf::console::factory::SimpleCommand const &
377 senf::console::factory::SimpleCommand::doc(std::string const & doc)
384 prefix_ senf::console::factory::SimpleCommand const &
385 senf::console::factory::SimpleCommand::shortdoc(std::string const & doc)
388 node_->shortdoc(doc);
392 ///////////////////////////////////////////////////////////////////////////
393 // senf::console::factory::Directory
395 prefix_ senf::console::factory::Directory::Directory()
396 : node_ (DirectoryNode::create())
399 prefix_ senf::console::DirectoryNode &
400 senf::console::factory::Directory::create(DirectoryNode & dir, std::string const & name)
403 return dir.add(name, node_);
406 prefix_ senf::console::factory::Directory const &
407 senf::console::factory::Directory::doc(std::string const & doc)
414 prefix_ senf::console::factory::Directory const &
415 senf::console::factory::Directory::shortdoc(std::string const & doc)
418 node_->shortdoc(doc);
422 ///////////////////////////////////////////////////////////////////////////
423 // senf::console::factory::Link
425 prefix_ senf::console::factory::Link::Link(GenericNode & target)
426 : node_ (LinkNode::create(target))
429 prefix_ senf::console::LinkNode & senf::console::factory::Link::create(DirectoryNode & dir,
430 std::string const & name)
433 return dir.add(name, node_);
436 ///////////////////////////////cci.e///////////////////////////////////////
443 // comment-column: 40
444 // c-file-style: "senf"
445 // indent-tabs-mode: nil
446 // ispell-local-dictionary: "american"
447 // compile-command: "scons -u test"