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::~GenericNode()
40 prefix_ std::string const & senf::console::GenericNode::name()
46 prefix_ senf::console::GenericNode::GenericNode()
50 prefix_ void senf::console::GenericNode::name(std::string const & name)
55 prefix_ boost::shared_ptr<senf::console::DirectoryNode> senf::console::GenericNode::parent()
58 return boost::static_pointer_cast<DirectoryNode>(
59 parent_ ? parent_->shared_from_this() : ptr() );
62 prefix_ senf::console::GenericNode::ptr senf::console::GenericNode::unlink()
65 return parent()->remove(name());
70 prefix_ void senf::console::GenericNode::help(std::ostream & output)
76 prefix_ senf::console::GenericNode::ptr senf::console::GenericNode::thisptr()
78 return shared_from_this();
81 prefix_ senf::console::GenericNode::cptr senf::console::GenericNode::thisptr()
84 return shared_from_this();
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 ///////////////////////////////////////////////////////////////////////////
100 // senf::console::DirectoryNode
102 prefix_ senf::console::DirectoryNode::ptr senf::console::DirectoryNode::create()
104 return ptr(new DirectoryNode());
107 prefix_ bool senf::console::DirectoryNode::hasChild(std::string const & name)
110 ChildMap::const_iterator i (children_.find(name));
111 return i != children_.end();
114 prefix_ senf::console::DirectoryNode &
115 senf::console::DirectoryNode::getDirectory(std::string const & name)
119 return dynamic_cast<DirectoryNode&>(get(name));
121 SENF_WRAP_EXC(std::bad_cast)
124 prefix_ senf::console::DirectoryNode &
125 senf::console::DirectoryNode::operator[](std::string const & name)
128 return getDirectory(name);
131 prefix_ senf::console::CommandNode &
132 senf::console::DirectoryNode::getCommand(std::string const & name)
136 return dynamic_cast<CommandNode&>(get(name));
138 SENF_WRAP_EXC(std::bad_cast)
141 prefix_ senf::console::CommandNode &
142 senf::console::DirectoryNode::operator()(std::string const & name)
145 return getCommand(name);
148 prefix_ senf::console::DirectoryNode &
149 senf::console::DirectoryNode::mkdir(std::string const & name)
151 return add(name, create());
154 prefix_ senf::console::DirectoryNode::ChildrenRange senf::console::DirectoryNode::children()
157 return boost::make_iterator_range(children_.begin(), children_.end());
160 prefix_ senf::console::DirectoryNode::ChildrenRange
161 senf::console::DirectoryNode::completions(std::string const & s)
164 return boost::make_iterator_range(children_.lower_bound(s),
165 children_.lower_bound(s + "\xff"));
168 prefix_ senf::console::DirectoryNode::DirectoryNode()
171 prefix_ senf::console::DirectoryNode &
172 senf::console::DirectoryNode::doc(std::string const & doc)
178 prefix_ senf::console::DirectoryNode::ptr senf::console::DirectoryNode::thisptr()
180 return boost::static_pointer_cast<DirectoryNode>(shared_from_this());
183 prefix_ senf::console::DirectoryNode::cptr senf::console::DirectoryNode::thisptr()
186 return boost::static_pointer_cast<DirectoryNode const>(shared_from_this());
189 ///////////////////////////////////////////////////////////////////////////
190 // senf::console::detail::NodeTraverser
192 prefix_ senf::console::detail::NodeTraverser::NodeTraverser(DirectoryNode & root,
195 : root_ (root), dir_ (dir.thisptr()), autocomplete_ (autocomplete), init_ (false)
198 ///////////////////////////////////////////////////////////////////////////
199 // senf::console::SyntaxErrorException
201 prefix_ senf::console::SyntaxErrorException::SyntaxErrorException(std::string const & msg)
205 prefix_ senf::console::SyntaxErrorException::~SyntaxErrorException()
209 prefix_ std::string const & senf::console::SyntaxErrorException::message()
215 ///////////////////////////////////////////////////////////////////////////
216 // senf::console::CommandNode
218 prefix_ senf::console::CommandNode::ptr senf::console::CommandNode::thisptr()
220 return boost::static_pointer_cast<CommandNode>(shared_from_this());
223 prefix_ senf::console::CommandNode::cptr senf::console::CommandNode::thisptr()
226 return boost::static_pointer_cast<CommandNode const>(shared_from_this());
229 prefix_ senf::console::CommandNode::CommandNode()
232 prefix_ void senf::console::CommandNode::execute(std::ostream & output,
233 ParseCommandInfo const & command)
236 v_execute(output, command);
239 prefix_ void senf::console::CommandNode::operator()(std::ostream & output,
240 ParseCommandInfo const & command)
243 execute(output, command);
246 ///////////////////////////////////////////////////////////////////////////
247 // senf::console::SimpleCommandNode
249 prefix_ senf::console::SimpleCommandNode::SimpleCommandNode(Function const & fn)
253 prefix_ senf::console::SimpleCommandNode::ptr
254 senf::console::SimpleCommandNode::create(Function const & fn)
256 return ptr(new SimpleCommandNode(fn));
259 prefix_ senf::console::SimpleCommandNode &
260 senf::console::SimpleCommandNode::doc(std::string const & doc)
266 prefix_ senf::console::SimpleCommandNode::ptr senf::console::SimpleCommandNode::thisptr()
268 return boost::static_pointer_cast<SimpleCommandNode>(shared_from_this());
271 prefix_ senf::console::SimpleCommandNode::cptr senf::console::SimpleCommandNode::thisptr()
274 return boost::static_pointer_cast<SimpleCommandNode const>(shared_from_this());
279 prefix_ senf::console::SimpleCommandNode &
280 senf::console::senf_console_add_node(DirectoryNode & node, std::string const & name,
281 SimpleCommandNode::Function fn, int)
283 return node.add(name, SimpleCommandNode::create(fn));
288 ///////////////////////////////cci.e///////////////////////////////////////
295 // comment-column: 40
296 // c-file-style: "senf"
297 // indent-tabs-mode: nil
298 // ispell-local-dictionary: "american"
299 // compile-command: "scons -u test"