2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
15 \brief Node inline non-template implementation */
19 #define prefix_ inline
20 //-/////////////////////////////////////////////////////////////////////////////////////////////////
22 //-/////////////////////////////////////////////////////////////////////////////////////////////////
23 // senf::console::GenericNode
25 prefix_ senf::console::GenericNode::ptr senf::console::GenericNode::thisptr()
27 return shared_from_this();
30 prefix_ senf::console::GenericNode::cptr senf::console::GenericNode::thisptr()
33 return shared_from_this();
36 prefix_ senf::console::GenericNode::~GenericNode()
39 prefix_ std::string const & senf::console::GenericNode::name()
45 prefix_ senf::console::GenericNode::GenericNode()
49 prefix_ void senf::console::GenericNode::name(std::string const & name)
54 prefix_ boost::shared_ptr<senf::console::DirectoryNode> senf::console::GenericNode::parent()
57 return boost::static_pointer_cast<DirectoryNode>(
58 parent_ ? parent_->shared_from_this() : ptr() );
61 prefix_ senf::console::GenericNode::ptr senf::console::GenericNode::unlink()
64 return parent()->remove(name());
69 prefix_ void senf::console::GenericNode::help(std::ostream & output)
75 prefix_ std::string senf::console::GenericNode::shorthelp()
81 prefix_ bool senf::console::GenericNode::operator==(GenericNode & other)
84 return this == & other;
87 prefix_ bool senf::console::GenericNode::operator!=(GenericNode & other)
90 return this != & other;
93 prefix_ bool senf::console::GenericNode::isDirectory()
96 return dynamic_cast<DirectoryNode const *>(this);
99 prefix_ bool senf::console::GenericNode::isLink()
102 return dynamic_cast<LinkNode const *>(this);
105 prefix_ bool senf::console::GenericNode::isCommand()
108 return dynamic_cast<CommandNode const *>(this);
111 prefix_ senf::console::GenericNode const & senf::console::GenericNode::followLink()
115 ? dynamic_cast<LinkNode const *>(this)->follow()
119 prefix_ senf::console::GenericNode & senf::console::GenericNode::followLink()
122 ? dynamic_cast<LinkNode *>(this)->follow()
126 //-/////////////////////////////////////////////////////////////////////////////////////////////////
127 // senf::console::LinkNode
129 prefix_ senf::console::GenericNode & senf::console::LinkNode::follow()
135 prefix_ senf::console::LinkNode::ptr senf::console::LinkNode::create(GenericNode & node)
137 GenericNode::ptr p (node.thisptr());
138 while ( p->isLink() )
139 p = dynamic_cast<LinkNode&>(*p).follow().thisptr();
140 return ptr(new LinkNode(*p));
143 prefix_ senf::console::LinkNode::LinkNode(GenericNode & node)
144 : node_ (node.thisptr())
147 //-/////////////////////////////////////////////////////////////////////////////////////////////////
148 // senf::console::DirectoryNode
150 prefix_ senf::console::DirectoryNode::ptr senf::console::DirectoryNode::create()
152 return ptr(new DirectoryNode());
155 prefix_ bool senf::console::DirectoryNode::hasChild(std::string const & name)
158 return children_.find(name) != children_.end();
161 prefix_ senf::console::GenericNode &
162 senf::console::DirectoryNode::get(std::string const & name)
165 return getLink(name).followLink();
168 prefix_ senf::console::DirectoryNode &
169 senf::console::DirectoryNode::getDirectory(std::string const & name)
173 return dynamic_cast<DirectoryNode&>(get(name));
175 SENF_WRAP_EXC(std::bad_cast)
178 prefix_ senf::console::DirectoryNode &
179 senf::console::DirectoryNode::operator[](std::string const & name)
182 return getDirectory(name);
185 prefix_ senf::console::CommandNode &
186 senf::console::DirectoryNode::getCommand(std::string const & name)
190 return dynamic_cast<CommandNode&>(get(name));
192 SENF_WRAP_EXC(std::bad_cast)
195 prefix_ senf::console::CommandNode &
196 senf::console::DirectoryNode::operator()(std::string const & name)
199 return getCommand(name);
202 prefix_ senf::console::DirectoryNode::ChildrenRange senf::console::DirectoryNode::children()
205 return boost::make_iterator_range(children_.begin(), children_.end());
208 prefix_ senf::console::DirectoryNode::ChildrenRange
209 senf::console::DirectoryNode::completions(std::string const & s)
212 return boost::make_iterator_range(children_.lower_bound(s),
213 children_.lower_bound(s + "\xff"));
216 prefix_ senf::console::DirectoryNode::DirectoryNode()
219 prefix_ senf::console::DirectoryNode &
220 senf::console::DirectoryNode::doc(std::string const & doc)
226 prefix_ senf::console::DirectoryNode &
227 senf::console::DirectoryNode::shortdoc(std::string const & doc)
233 prefix_ senf::console::DirectoryNode::ptr senf::console::DirectoryNode::thisptr()
235 return boost::static_pointer_cast<DirectoryNode>(shared_from_this());
238 prefix_ senf::console::DirectoryNode::cptr senf::console::DirectoryNode::thisptr()
241 return boost::static_pointer_cast<DirectoryNode const>(shared_from_this());
244 //-/////////////////////////////////////////////////////////////////////////////////////////////////
245 // senf::console::CommandNode
247 prefix_ senf::console::CommandNode::ptr senf::console::CommandNode::thisptr()
249 return boost::static_pointer_cast<CommandNode>(shared_from_this());
252 prefix_ senf::console::CommandNode::cptr senf::console::CommandNode::thisptr()
255 return boost::static_pointer_cast<CommandNode const>(shared_from_this());
258 prefix_ senf::console::CommandNode::CommandNode()
261 prefix_ void senf::console::CommandNode::execute(std::ostream & output,
262 ParseCommandInfo const & command)
266 execute(rv, output, command);
269 prefix_ void senf::console::CommandNode::execute(boost::any & rv, std::ostream & output,
270 ParseCommandInfo const & command)
274 v_execute(rv, output, command);
277 prefix_ void senf::console::CommandNode::operator()(std::ostream & output,
278 ParseCommandInfo const & command)
281 execute(output, command);
284 prefix_ void senf::console::CommandNode::operator()(boost::any & rv, std::ostream & output,
285 ParseCommandInfo const & command)
288 execute(rv, output, command);
291 //-/////////////////////////////////////////////////////////////////////////////////////////////////
292 // senf::console::SimpleCommandNode
294 prefix_ senf::console::SimpleCommandNode::SimpleCommandNode(Function const & fn)
298 prefix_ senf::console::SimpleCommandNode::ptr
299 senf::console::SimpleCommandNode::create(Function const & fn)
301 return ptr(new SimpleCommandNode(fn));
304 prefix_ senf::console::SimpleCommandNode &
305 senf::console::SimpleCommandNode::doc(std::string const & doc)
311 prefix_ senf::console::SimpleCommandNode &
312 senf::console::SimpleCommandNode::shortdoc(std::string const & doc)
318 prefix_ senf::console::SimpleCommandNode::ptr senf::console::SimpleCommandNode::thisptr()
320 return boost::static_pointer_cast<SimpleCommandNode>(shared_from_this());
323 prefix_ senf::console::SimpleCommandNode::cptr senf::console::SimpleCommandNode::thisptr()
326 return boost::static_pointer_cast<SimpleCommandNode const>(shared_from_this());
329 //-/////////////////////////////////////////////////////////////////////////////////////////////////
331 prefix_ senf::console::DirectoryNode & senf::console::provideDirectory(DirectoryNode & dir,
332 std::string const & name)
334 return dir.hasChild(name) ? dir.getDirectory(name) : dir.add(name, factory::Directory());
338 //-/////////////////////////////////////////////////////////////////////////////////////////////////
339 // senf::console::factory::SimpleCommand
341 prefix_ senf::console::factory::SimpleCommand::SimpleCommand(SimpleCommandNode::Function fn)
342 : node_ (SimpleCommandNode::create(fn))
345 prefix_ senf::console::SimpleCommandNode &
346 senf::console::factory::SimpleCommand::create(DirectoryNode & dir, std::string const & name)
349 return dir.add(name, node_);
352 prefix_ senf::console::factory::SimpleCommand const &
353 senf::console::factory::SimpleCommand::doc(std::string const & doc)
360 prefix_ senf::console::factory::SimpleCommand const &
361 senf::console::factory::SimpleCommand::shortdoc(std::string const & doc)
364 node_->shortdoc(doc);
368 //-/////////////////////////////////////////////////////////////////////////////////////////////////
369 // senf::console::factory::Directory
371 prefix_ senf::console::factory::Directory::Directory()
372 : node_ (DirectoryNode::create())
375 prefix_ senf::console::DirectoryNode &
376 senf::console::factory::Directory::create(DirectoryNode & dir, std::string const & name)
379 return dir.add(name, node_);
382 prefix_ senf::console::factory::Directory const &
383 senf::console::factory::Directory::doc(std::string const & doc)
390 prefix_ senf::console::factory::Directory const &
391 senf::console::factory::Directory::shortdoc(std::string const & doc)
394 node_->shortdoc(doc);
398 //-/////////////////////////////////////////////////////////////////////////////////////////////////
399 // senf::console::factory::Link
401 prefix_ senf::console::factory::Link::Link(GenericNode & target)
402 : node_ (LinkNode::create(target))
405 prefix_ senf::console::LinkNode & senf::console::factory::Link::create(DirectoryNode & dir,
406 std::string const & name)
409 return dir.add(name, node_);
412 //-/////////////////////////////////////////////////////////////////////////////////////////////////
419 // comment-column: 40
420 // c-file-style: "senf"
421 // indent-tabs-mode: nil
422 // ispell-local-dictionary: "american"
423 // compile-command: "scons -u test"