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 "../../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_ bool senf::console::GenericNode::operator==(GenericNode & other)
90 return this == & other;
93 prefix_ bool senf::console::GenericNode::operator!=(GenericNode & other)
96 return this != & other;
99 prefix_ bool senf::console::GenericNode::isDirectory()
102 return dynamic_cast<DirectoryNode const *>(this);
105 prefix_ bool senf::console::GenericNode::isLink()
108 return dynamic_cast<LinkNode const *>(this);
111 prefix_ bool senf::console::GenericNode::isCommand()
114 return dynamic_cast<CommandNode const *>(this);
117 prefix_ senf::console::GenericNode const & senf::console::GenericNode::followLink()
121 ? dynamic_cast<LinkNode const *>(this)->follow()
125 prefix_ senf::console::GenericNode & senf::console::GenericNode::followLink()
128 ? dynamic_cast<LinkNode *>(this)->follow()
132 ///////////////////////////////////////////////////////////////////////////
133 // senf::console::LinkNode
135 prefix_ senf::console::GenericNode & senf::console::LinkNode::follow()
141 prefix_ senf::console::LinkNode::ptr senf::console::LinkNode::create(GenericNode & node)
143 GenericNode::ptr p (node.thisptr());
144 while ( p->isLink() )
145 p = dynamic_cast<LinkNode&>(*p).follow().thisptr();
146 return ptr(new LinkNode(*p));
149 prefix_ senf::console::LinkNode::LinkNode(GenericNode & node)
150 : node_ (node.thisptr())
153 ///////////////////////////////////////////////////////////////////////////
154 // senf::console::DirectoryNode
156 prefix_ senf::console::DirectoryNode::ptr senf::console::DirectoryNode::create()
158 return ptr(new DirectoryNode());
161 prefix_ bool senf::console::DirectoryNode::hasChild(std::string const & name)
164 ChildMap::const_iterator i (children_.find(name));
165 return i != children_.end();
168 prefix_ senf::console::GenericNode &
169 senf::console::DirectoryNode::get(std::string const & name)
172 return getLink(name).followLink();
175 prefix_ senf::console::DirectoryNode &
176 senf::console::DirectoryNode::getDirectory(std::string const & name)
180 return dynamic_cast<DirectoryNode&>(get(name));
182 SENF_WRAP_EXC(std::bad_cast)
185 prefix_ senf::console::DirectoryNode &
186 senf::console::DirectoryNode::operator[](std::string const & name)
189 return getDirectory(name);
192 prefix_ senf::console::CommandNode &
193 senf::console::DirectoryNode::getCommand(std::string const & name)
197 return dynamic_cast<CommandNode&>(get(name));
199 SENF_WRAP_EXC(std::bad_cast)
202 prefix_ senf::console::CommandNode &
203 senf::console::DirectoryNode::operator()(std::string const & name)
206 return getCommand(name);
209 prefix_ senf::console::DirectoryNode &
210 senf::console::DirectoryNode::mkdir(std::string const & name)
212 return add(name, create());
215 prefix_ senf::console::DirectoryNode &
216 senf::console::DirectoryNode::provideDirectory(std::string const & name)
218 return hasChild(name) ? getDirectory(name) : mkdir(name);
221 prefix_ senf::console::DirectoryNode::ChildrenRange senf::console::DirectoryNode::children()
224 return boost::make_iterator_range(children_.begin(), children_.end());
227 prefix_ senf::console::DirectoryNode::ChildrenRange
228 senf::console::DirectoryNode::completions(std::string const & s)
231 return boost::make_iterator_range(children_.lower_bound(s),
232 children_.lower_bound(s + "\xff"));
235 prefix_ void senf::console::DirectoryNode::link(std::string const & name, GenericNode & target)
237 add(name, LinkNode::create(target));
240 prefix_ senf::console::DirectoryNode::DirectoryNode()
243 prefix_ senf::console::DirectoryNode &
244 senf::console::DirectoryNode::doc(std::string const & doc)
250 prefix_ senf::console::DirectoryNode::ptr senf::console::DirectoryNode::thisptr()
252 return boost::static_pointer_cast<DirectoryNode>(shared_from_this());
255 prefix_ senf::console::DirectoryNode::cptr senf::console::DirectoryNode::thisptr()
258 return boost::static_pointer_cast<DirectoryNode const>(shared_from_this());
261 ///////////////////////////////////////////////////////////////////////////
262 // senf::console::detail::NodeTraverser
264 prefix_ senf::console::detail::NodeTraverser::NodeTraverser(DirectoryNode & root,
267 : root_ (root), dir_ (dir.thisptr()), autocomplete_ (autocomplete), init_ (false)
270 ///////////////////////////////////////////////////////////////////////////
271 // senf::console::CommandNode
273 prefix_ senf::console::CommandNode::ptr senf::console::CommandNode::thisptr()
275 return boost::static_pointer_cast<CommandNode>(shared_from_this());
278 prefix_ senf::console::CommandNode::cptr senf::console::CommandNode::thisptr()
281 return boost::static_pointer_cast<CommandNode const>(shared_from_this());
284 prefix_ senf::console::CommandNode::CommandNode()
287 prefix_ void senf::console::CommandNode::execute(std::ostream & output,
288 ParseCommandInfo const & command)
292 execute(rv, output, command);
295 prefix_ void senf::console::CommandNode::execute(boost::any & rv, std::ostream & output,
296 ParseCommandInfo const & command)
300 v_execute(rv, output, command);
303 prefix_ void senf::console::CommandNode::operator()(std::ostream & output,
304 ParseCommandInfo const & command)
307 execute(output, command);
310 prefix_ void senf::console::CommandNode::operator()(boost::any & rv, std::ostream & output,
311 ParseCommandInfo const & command)
314 execute(rv, output, command);
317 ///////////////////////////////////////////////////////////////////////////
318 // senf::console::SimpleCommandNode
320 prefix_ senf::console::SimpleCommandNode::SimpleCommandNode(Function const & fn)
324 prefix_ senf::console::SimpleCommandNode::ptr
325 senf::console::SimpleCommandNode::create(Function const & fn)
327 return ptr(new SimpleCommandNode(fn));
330 prefix_ senf::console::SimpleCommandNode &
331 senf::console::SimpleCommandNode::doc(std::string const & doc)
337 prefix_ senf::console::SimpleCommandNode::ptr senf::console::SimpleCommandNode::thisptr()
339 return boost::static_pointer_cast<SimpleCommandNode>(shared_from_this());
342 prefix_ senf::console::SimpleCommandNode::cptr senf::console::SimpleCommandNode::thisptr()
345 return boost::static_pointer_cast<SimpleCommandNode const>(shared_from_this());
350 prefix_ senf::console::SimpleCommandNode &
351 senf::console::senf_console_add_node(DirectoryNode & node, std::string const & name,
352 SimpleCommandNode::Function fn, int)
354 return node.add(name, SimpleCommandNode::create(fn));
357 prefix_ senf::console::DirectoryNode &
358 senf::console::senf_console_add_node(DirectoryNode & node, std::string const & name,
359 DirectoryNode & dir, int)
361 return node.add(name, dir.thisptr());
366 ///////////////////////////////cci.e///////////////////////////////////////
373 // comment-column: 40
374 // c-file-style: "senf"
375 // indent-tabs-mode: nil
376 // ispell-local-dictionary: "american"
377 // compile-command: "scons -u test"