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 OverloadedCommand public header */
26 #ifndef HH_OverloadedCommand_
27 #define HH_OverloadedCommand_ 1
31 #include <boost/intrusive_ptr.hpp>
32 #include "../Utils/intrusive_refcount.hh"
34 //#include "OverloadedCommand.mpp"
35 ///////////////////////////////hh.p////////////////////////////////////////
40 class OverloadedCommandNode;
45 : public senf::intrusive_refcount
48 ///////////////////////////////////////////////////////////////////////////
51 typedef boost::intrusive_ptr<CommandOverload> ptr;
52 typedef CommandNode::Arguments Arguments;
54 ///////////////////////////////////////////////////////////////////////////
56 virtual ~CommandOverload();
58 void operator()(std::ostream & os, Arguments const & arguments);
59 void help(std::ostream & os);
61 OverloadedCommandNode & node();
69 virtual void v_help(std::ostream & os) const = 0;
70 virtual void v_execute(std::ostream & os, Arguments const & arguments) const = 0;
73 OverloadedCommandNode * node_;
75 friend class OverloadedCommandNode;
78 /** \brief Command node which allows multiple registered callbacks
80 OverloadedCommand is like SimpleCommand but allows to register multiple commands to a single
81 node. This works by calling each command in the list consecutively until no 'SyntaxError'
84 \warning For this to work, the commands <b>must</b> do all syntax checking before doing any
89 class OverloadedCommandNode
93 ///////////////////////////////////////////////////////////////////////////
96 typedef boost::shared_ptr<OverloadedCommandNode> ptr;
97 typedef boost::shared_ptr<OverloadedCommandNode const> cptr;
98 typedef boost::weak_ptr<OverloadedCommandNode> weak_ptr;
100 ///////////////////////////////////////////////////////////////////////////
101 ///\name Structors and default members
107 ///////////////////////////////////////////////////////////////////////////
109 void add(CommandOverload::ptr overload);
112 cptr thisptr() const;
114 OverloadedCommandNode & doc(std::string const & doc);
119 OverloadedCommandNode();
121 virtual void v_help(std::ostream & output) const;
122 virtual void v_execute(std::ostream & output, Arguments const & arguments) const;
124 typedef std::vector<CommandOverload::ptr> Overloads;
126 Overloads overloads_;
132 class SimpleCommandOverload
133 : public CommandOverload
136 ///////////////////////////////////////////////////////////////////////////
139 typedef boost::intrusive_ptr<SimpleCommandOverload> ptr;
140 typedef boost::function<void (std::ostream &, Arguments const &)> Function;
142 ///////////////////////////////////////////////////////////////////////////
143 ///\name Structors and default members
146 static SimpleCommandOverload::ptr create(Function fn);
149 ///////////////////////////////////////////////////////////////////////////
151 SimpleCommandOverload & doc(std::string const & doc);
156 SimpleCommandOverload(Function fn);
158 virtual void v_help(std::ostream & os) const;
159 virtual void v_execute(std::ostream & os, Arguments const & arguments) const;
167 ///////////////////////////////hh.e////////////////////////////////////////
168 #include "OverloadedCommand.cci"
169 //#include "OverloadedCommand.ct"
170 //#include "OverloadedCommand.cti"
177 // comment-column: 40
178 // c-file-style: "senf"
179 // indent-tabs-mode: nil
180 // ispell-local-dictionary: "american"
181 // compile-command: "scons -u test"