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 public header */
26 #ifndef HH_ParsedCommand_
27 #define HH_ParsedCommand_ 1
31 #include <boost/type_traits/function_traits.hpp>
32 #include <boost/type_traits/is_member_pointer.hpp>
33 #include <boost/type_traits/is_same.hpp>
34 #include <boost/mpl/if.hpp>
35 #include <boost/utility.hpp>
36 #include <boost/parameter/keyword.hpp>
37 #include <boost/parameter/parameters.hpp>
38 #include "../config.hh"
39 #include "OverloadedCommand.hh"
40 #include "ParseParameter.hh"
41 #include "../Utils/type_traits.hh"
43 #include "ParsedCommand.ih"
44 #include "ParsedCommand.mpp"
45 ///////////////////////////////hh.p////////////////////////////////////////
50 class ParsedCommandOverloadBase
51 : public CommandOverload
54 typedef boost::intrusive_ptr<ParsedCommandOverloadBase> ptr;
56 detail::ParameterInfoBase & arg(unsigned n) const;
57 template <class Type> detail::ParameterInfo<Type> & arg(unsigned n) const;
59 void doc(std::string const & d);
62 ParsedCommandOverloadBase();
68 virtual unsigned v_numArguments() const;
69 virtual void v_argumentDoc(unsigned index, ArgumentDoc & doc) const;
70 virtual std::string v_doc() const;
72 typedef std::vector<detail::ParameterInfoBase::ptr> Parameters;
73 Parameters parameters_;
77 template <class FunctionTraits, unsigned arity=FunctionTraits::arity>
78 class ParsedCommandOverload {};
80 # define BOOST_PP_ITERATION_PARAMS_1 (4, (0, SENF_CONSOLE_MAX_COMMAND_ARITY, \
81 SENF_ABSOLUTE_INCLUDE_PATH(Console/ParsedCommand.mpp), \
83 # include BOOST_PP_ITERATE()
85 class ParsedCommandAttributorBase
88 OverloadedCommandNode & node() const;
89 operator OverloadedCommandNode & () const;
92 ParsedCommandAttributorBase(ParsedCommandOverloadBase & overload, unsigned index);
94 void argName(std::string const & name) const;
95 void argDoc(std::string const & doc) const;
96 template <class Type> void defaultValue(Type const & value) const;
98 ParsedCommandOverloadBase & overload() const;
99 void overloadDoc(std::string const & doc) const;
101 void nodeDoc(std::string const & doc) const;
104 ParsedCommandOverloadBase & overload_;
108 template <class Overload>
109 class ParsedCommandAttributor
110 : public ParsedCommandAttributorBase
113 Overload & overload() const;
116 ParsedCommandAttributor(Overload & overload, unsigned index);
122 BOOST_PARAMETER_KEYWORD(detail, name_);
123 BOOST_PARAMETER_KEYWORD(detail, description_);
124 BOOST_PARAMETER_KEYWORD(detail, default_value_);
127 template <class Overload, class Self>
128 class ParsedAttributeAttributorBase
129 : public ParsedCommandAttributor<Overload>
132 Self doc(std::string const & doc) const;
133 Self overloadDoc(std::string const & doc) const;
136 ParsedAttributeAttributorBase(Overload & overload, unsigned index);
141 template < class Overload,
143 bool flag=(index < unsigned(Overload::traits::arity)) >
144 class ParsedAttributeAttributor
145 : public ParsedAttributeAttributorBase< Overload,
146 ParsedAttributeAttributor<Overload, index, flag> >
149 typedef typename senf::function_traits_arg_type<
150 typename Overload::traits, int(index) >::type arg_type;
151 typedef typename senf::remove_cvref< arg_type >::type value_type;
152 typedef ParsedAttributeAttributor<Overload, index+1> next_type;
154 typedef OverloadedCommandNode node_type;
155 typedef ParsedAttributeAttributor return_type;
157 typedef boost::parameter::parameters<
159 tag::detail::description_,
160 tag::detail::default_value_> arg_params;
162 next_type arg() const;
164 # define BOOST_PP_ITERATION_PARAMS_1 \
165 (4, (1, 3, SENF_ABSOLUTE_INCLUDE_PATH(Console/ParsedCommand.mpp), 5))
166 # include BOOST_PP_ITERATE()
169 explicit ParsedAttributeAttributor(Overload & overload);
171 template <class ArgumentPack>
172 next_type argInfo(ArgumentPack const & args) const;
174 template <class ArgumentPack>
175 next_type argInfo(ArgumentPack const & args, boost::mpl::true_) const;
176 template <class ArgumentPack>
177 next_type argInfo(ArgumentPack const & args, boost::mpl::false_) const;
179 next_type argInfo(std::string const & name, std::string const & doc) const;
180 next_type argInfo(std::string const & name, std::string const & doc,
181 value_type const & value) const;
183 ParsedAttributeAttributor<Overload, index+1> next() const;
185 void defaultValue(value_type const & value) const;
187 template <class O, unsigned i, bool f>
188 friend class ParsedAttributeAttributor;
190 template <class Function>
191 friend ParsedAttributeAttributor<
192 ParsedCommandOverload<typename detail::ParsedCommandTraits<Function>::traits> >
193 senf_console_add_node(DirectoryNode & node, std::string const & name, Function fn, int);
195 template <class Owner, class Function>
196 friend ParsedAttributeAttributor<
197 ParsedCommandOverload<typename detail::ParsedCommandTraits<Function>::traits> >
198 senf_console_add_node(DirectoryNode & node, Owner & owner, std::string const & name,
200 typename boost::enable_if_c<
201 detail::ParsedCommandTraits<Function>::is_member>::type * = 0);
204 template <class Overload, unsigned index>
205 class ParsedAttributeAttributor<Overload, index, false>
206 : public ParsedCommandAttributor< Overload >
209 typedef OverloadedCommandNode node_type;
210 typedef ParsedAttributeAttributor return_type;
213 explicit ParsedAttributeAttributor(Overload & overload);
215 template <class O, unsigned i, bool f>
216 friend class ParsedAttributeAttributor;
218 template <class Function>
219 friend ParsedAttributeAttributor<
220 ParsedCommandOverload<typename detail::ParsedCommandTraits<Function>::traits> >
221 senf_console_add_node(DirectoryNode & node, std::string const & name, Function fn, int);
223 template <class Owner, class Function>
224 friend ParsedAttributeAttributor<
225 ParsedCommandOverload<typename detail::ParsedCommandTraits<Function>::traits> >
226 senf_console_add_node(DirectoryNode & node, Owner & owner, std::string const & name,
228 typename boost::enable_if_c<
229 detail::ParsedCommandTraits<Function>::is_member>::type * = 0);
234 template <class Function>
235 ParsedAttributeAttributor<
236 ParsedCommandOverload<typename detail::ParsedCommandTraits<Function>::traits> >
237 senf_console_add_node(DirectoryNode & node, std::string const & name, Function fn, int);
239 template <class Owner, class Function>
240 ParsedAttributeAttributor<
241 ParsedCommandOverload<typename detail::ParsedCommandTraits<Function>::traits> >
242 senf_console_add_node(DirectoryNode & node, Owner & owner, std::string const & name,
244 typename boost::enable_if_c<
245 detail::ParsedCommandTraits<Function>::is_member>::type * = 0);
251 #include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
253 BOOST_TYPEOF_REGISTER_TEMPLATE(senf::console::ParsedCommandOverload, (class,unsigned))
254 BOOST_TYPEOF_REGISTER_TEMPLATE(senf::console::ParsedAttributeAttributor, (class, unsigned, bool))
255 BOOST_TYPEOF_REGISTER_TEMPLATE(boost::function_traits, 1)
257 ///////////////////////////////hh.e////////////////////////////////////////
258 #include "ParsedCommand.cci"
259 #include "ParsedCommand.ct"
260 #include "ParsedCommand.cti"
267 // comment-column: 40
268 // c-file-style: "senf"
269 // indent-tabs-mode: nil
270 // ispell-local-dictionary: "american"
271 // compile-command: "scons -u test"