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 ParsedCommand inline template implementation */
26 #include "ParsedCommand.ih"
29 #include "../Utils/membind.hh"
30 #include <boost/format.hpp>
32 #define prefix_ inline
33 ///////////////////////////////cti.p///////////////////////////////////////
35 ///////////////////////////////////////////////////////////////////////////
36 // senf::console::ParsedCommandOverloadBase
39 prefix_ senf::console::detail::ParameterInfo<Type> &
40 senf::console::ParsedCommandOverloadBase::arg(unsigned n)
43 return dynamic_cast<detail::ParameterInfo<Type> &>(arg(n));
47 prefix_ void senf::console::ParsedCommandOverloadBase::addParameter()
49 parameters_.push_back(detail::ParameterInfo<Type>::create());
52 ///////////////////////////////////////////////////////////////////////////
53 // senf::console::ParsedCommandOverload<FunctionTraits,n>
55 #define BOOST_PP_ITERATION_PARAMS_1 (4, (0, SENF_CONSOLE_MAX_COMMAND_ARITY, \
56 SENF_ABSOLUTE_INCLUDE_PATH(Console/ParsedCommand.mpp), \
58 #include BOOST_PP_ITERATE()
60 ///////////////////////////////////////////////////////////////////////////
65 // What is THIS about ??
67 // Ok, here's the dope: parsed commands may optionally have an std::ostream & first argument. If
68 // this argument is given, then the function will be called with the console output stream as
69 // it's first argument.
71 // This is implemented in the following way: ParsedCommandOverload (the class responsible for
72 // calling the callback) will ALWAYS pass the stream as first argument. If the user callback
73 // expects os as it's first argument, 'ignoreOneArg' will be false and the user supplied
74 // function will be directly passed to ParsedCommandOverload.
76 // If however, it does NOT take an std::ostream first argument, 'ignoreOneArg' will be true and
77 // the create member will use boost::bind to DROP the first argument.
79 template <class Traits, bool ignoreOneArg, unsigned arity=Traits::arity>
80 struct CreateParsedCommandOverload
83 template <class Traits, unsigned arity>
84 struct CreateParsedCommandOverload<Traits, false, arity>
86 typedef Traits traits;
88 template <class Function>
89 static typename senf::console::ParsedCommandOverload<traits>::ptr create(Function fn)
90 { return senf::console::ParsedCommandOverload<traits>::create(fn); };
93 # define BOOST_PP_ITERATION_PARAMS_1 (4, (0, SENF_CONSOLE_MAX_COMMAND_ARITY, \
94 SENF_ABSOLUTE_INCLUDE_PATH(Console/ParsedCommand.mpp), \
96 # include BOOST_PP_ITERATE()
100 template <class Function>
101 prefix_ senf::console::ParsedCommandOverload<
102 typename senf::console::detail::ParsedCommandTraits<Function>::traits> &
103 senf::console::senf_console_add_node(DirectoryNode & node, std::string const & name,
106 OverloadedCommandNode & cmdNode (
108 ? dynamic_cast<OverloadedCommandNode &>(node(name))
109 : node.add(name, OverloadedCommandNode::create()) );
111 typedef senf::console::detail::ParsedCommandTraits<Function> CmdTraits;
113 return cmdNode.add( CreateParsedCommandOverload<
114 typename CmdTraits::traits, ! CmdTraits::has_ostream_arg>::create(fn) );
117 template <class Owner, class Function>
118 prefix_ senf::console::ParsedCommandOverload<
119 typename senf::console::detail::ParsedCommandTraits<Function>::traits> &
121 senf_console_add_node(DirectoryNode & node, Owner & owner, std::string const & name,
123 typename boost::enable_if_c<detail::ParsedCommandTraits<Function>::is_member>::type *)
125 OverloadedCommandNode & cmdNode (
127 ? dynamic_cast<OverloadedCommandNode &>(node(name))
128 : node.add(name, OverloadedCommandNode::create()) );
130 typedef senf::console::detail::ParsedCommandTraits<Function> CmdTraits;
132 return cmdNode.add( CreateParsedCommandOverload<
133 typename CmdTraits::traits, ! CmdTraits::has_ostream_arg>::create(
134 senf::membind(fn,&owner)) );
137 ///////////////////////////////cti.e///////////////////////////////////////
144 // comment-column: 40
145 // c-file-style: "senf"
146 // indent-tabs-mode: nil
147 // ispell-local-dictionary: "american"
148 // compile-command: "scons -u test"