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 */
29 #include <senf/Utils/senfassert.hh>
31 #define prefix_ inline
32 ///////////////////////////////cci.p///////////////////////////////////////
34 ///////////////////////////////////////////////////////////////////////////
35 // senf::console::GenericNode
37 prefix_ senf::console::GenericNode::ptr senf::console::GenericNode::thisptr()
39 return shared_from_this();
42 prefix_ senf::console::GenericNode::cptr senf::console::GenericNode::thisptr()
45 return shared_from_this();
48 prefix_ senf::console::GenericNode::~GenericNode()
51 prefix_ std::string const & senf::console::GenericNode::name()
57 prefix_ senf::console::GenericNode::GenericNode()
61 prefix_ void senf::console::GenericNode::name(std::string const & name)
66 prefix_ boost::shared_ptr<senf::console::DirectoryNode> senf::console::GenericNode::parent()
69 return boost::static_pointer_cast<DirectoryNode>(
70 parent_ ? parent_->shared_from_this() : ptr() );
73 prefix_ senf::console::GenericNode::ptr senf::console::GenericNode::unlink()
76 return parent()->remove(name());
81 prefix_ void senf::console::GenericNode::help(std::ostream & output)
87 prefix_ std::string senf::console::GenericNode::shorthelp()
93 prefix_ bool senf::console::GenericNode::operator==(GenericNode & other)
96 return this == & other;
99 prefix_ bool senf::console::GenericNode::operator!=(GenericNode & other)
102 return this != & other;
105 prefix_ bool senf::console::GenericNode::isDirectory()
108 return dynamic_cast<DirectoryNode const *>(this);
111 prefix_ bool senf::console::GenericNode::isLink()
114 return dynamic_cast<LinkNode const *>(this);
117 prefix_ bool senf::console::GenericNode::isCommand()
120 return dynamic_cast<CommandNode const *>(this);
123 prefix_ senf::console::GenericNode const & senf::console::GenericNode::followLink()
127 ? dynamic_cast<LinkNode const *>(this)->follow()
131 prefix_ senf::console::GenericNode & senf::console::GenericNode::followLink()
134 ? dynamic_cast<LinkNode *>(this)->follow()
138 ///////////////////////////////////////////////////////////////////////////
139 // senf::console::LinkNode
141 prefix_ senf::console::GenericNode & senf::console::LinkNode::follow()
147 prefix_ senf::console::LinkNode::ptr senf::console::LinkNode::create(GenericNode & node)
149 GenericNode::ptr p (node.thisptr());
150 while ( p->isLink() )
151 p = dynamic_cast<LinkNode&>(*p).follow().thisptr();
152 return ptr(new LinkNode(*p));
155 prefix_ senf::console::LinkNode::LinkNode(GenericNode & node)
156 : node_ (node.thisptr())
159 ///////////////////////////////////////////////////////////////////////////
160 // senf::console::DirectoryNode
162 prefix_ senf::console::DirectoryNode::ptr senf::console::DirectoryNode::create()
164 return ptr(new DirectoryNode());
167 prefix_ bool senf::console::DirectoryNode::hasChild(std::string const & name)
170 ChildMap::const_iterator i (children_.find(name));
171 return i != children_.end();
174 prefix_ senf::console::GenericNode &
175 senf::console::DirectoryNode::get(std::string const & name)
178 return getLink(name).followLink();
181 prefix_ senf::console::DirectoryNode &
182 senf::console::DirectoryNode::getDirectory(std::string const & name)
186 return dynamic_cast<DirectoryNode&>(get(name));
188 SENF_WRAP_EXC(std::bad_cast)
191 prefix_ senf::console::DirectoryNode &
192 senf::console::DirectoryNode::operator[](std::string const & name)
195 return getDirectory(name);
198 prefix_ senf::console::CommandNode &
199 senf::console::DirectoryNode::getCommand(std::string const & name)
203 return dynamic_cast<CommandNode&>(get(name));
205 SENF_WRAP_EXC(std::bad_cast)
208 prefix_ senf::console::CommandNode &
209 senf::console::DirectoryNode::operator()(std::string const & name)
212 return getCommand(name);
215 prefix_ senf::console::DirectoryNode &
216 senf::console::DirectoryNode::mkdir(std::string const & name)
218 return add(name, create());
221 prefix_ senf::console::DirectoryNode &
222 senf::console::DirectoryNode::provideDirectory(std::string const & name)
224 return hasChild(name) ? getDirectory(name) : mkdir(name);
227 prefix_ senf::console::DirectoryNode::ChildrenRange senf::console::DirectoryNode::children()
230 return boost::make_iterator_range(children_.begin(), children_.end());
233 prefix_ senf::console::DirectoryNode::ChildrenRange
234 senf::console::DirectoryNode::completions(std::string const & s)
237 return boost::make_iterator_range(children_.lower_bound(s),
238 children_.lower_bound(s + "\xff"));
241 prefix_ void senf::console::DirectoryNode::link(std::string const & name, GenericNode & target)
243 add(name, LinkNode::create(target));
246 prefix_ senf::console::DirectoryNode::DirectoryNode()
249 prefix_ senf::console::DirectoryNode &
250 senf::console::DirectoryNode::doc(std::string const & doc)
256 prefix_ senf::console::DirectoryNode &
257 senf::console::DirectoryNode::shortdoc(std::string const & doc)
263 prefix_ senf::console::DirectoryNode::ptr senf::console::DirectoryNode::thisptr()
265 return boost::static_pointer_cast<DirectoryNode>(shared_from_this());
268 prefix_ senf::console::DirectoryNode::cptr senf::console::DirectoryNode::thisptr()
271 return boost::static_pointer_cast<DirectoryNode const>(shared_from_this());
274 ///////////////////////////////////////////////////////////////////////////
275 // senf::console::detail::NodeTraverser
278 prefix_ senf::console::detail::NodeTraverser::NodeTraverser(DirectoryNode & root,
281 : root_ (root), dir_ (dir.thisptr()), autocomplete_ (autocomplete), init_ (false)
285 ///////////////////////////////////////////////////////////////////////////
286 // senf::console::CommandNode
288 prefix_ senf::console::CommandNode::ptr senf::console::CommandNode::thisptr()
290 return boost::static_pointer_cast<CommandNode>(shared_from_this());
293 prefix_ senf::console::CommandNode::cptr senf::console::CommandNode::thisptr()
296 return boost::static_pointer_cast<CommandNode const>(shared_from_this());
299 prefix_ senf::console::CommandNode::CommandNode()
302 prefix_ void senf::console::CommandNode::execute(std::ostream & output,
303 ParseCommandInfo const & command)
307 execute(rv, output, command);
310 prefix_ void senf::console::CommandNode::execute(boost::any & rv, std::ostream & output,
311 ParseCommandInfo const & command)
315 v_execute(rv, output, command);
318 prefix_ void senf::console::CommandNode::operator()(std::ostream & output,
319 ParseCommandInfo const & command)
322 execute(output, command);
325 prefix_ void senf::console::CommandNode::operator()(boost::any & rv, std::ostream & output,
326 ParseCommandInfo const & command)
329 execute(rv, output, command);
332 ///////////////////////////////////////////////////////////////////////////
333 // senf::console::SimpleCommandNode
335 prefix_ senf::console::SimpleCommandNode::SimpleCommandNode(Function const & fn)
339 prefix_ senf::console::SimpleCommandNode::ptr
340 senf::console::SimpleCommandNode::create(Function const & fn)
342 return ptr(new SimpleCommandNode(fn));
345 prefix_ senf::console::SimpleCommandNode &
346 senf::console::SimpleCommandNode::doc(std::string const & doc)
352 prefix_ senf::console::SimpleCommandNode &
353 senf::console::SimpleCommandNode::shortdoc(std::string const & doc)
359 prefix_ senf::console::SimpleCommandNode::ptr senf::console::SimpleCommandNode::thisptr()
361 return boost::static_pointer_cast<SimpleCommandNode>(shared_from_this());
364 prefix_ senf::console::SimpleCommandNode::cptr senf::console::SimpleCommandNode::thisptr()
367 return boost::static_pointer_cast<SimpleCommandNode const>(shared_from_this());
372 prefix_ senf::console::SimpleCommandNode &
373 senf::console::senf_console_add_node(DirectoryNode & node, std::string const & name,
374 SimpleCommandNode::Function fn, int)
376 return node.add(name, SimpleCommandNode::create(fn));
379 prefix_ senf::console::DirectoryNode &
380 senf::console::senf_console_add_node(DirectoryNode & node, std::string const & name,
381 DirectoryNode & dir, int)
383 return node.add(name, dir.thisptr());
388 ///////////////////////////////cci.e///////////////////////////////////////
395 // comment-column: 40
396 // c-file-style: "senf"
397 // indent-tabs-mode: nil
398 // ispell-local-dictionary: "american"
399 // compile-command: "scons -u test"