Utils: Add some type traits in type_traits.hh
[senf.git] / Console / ParsedCommand.hh
1 // $Id$
2 //
3 // Copyright (C) 2008 
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
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.
12 //
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.
17 //
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.
22
23 /** \file
24     \brief ParsedCommand public header */
25
26 #ifndef HH_ParsedCommand_
27 #define HH_ParsedCommand_ 1
28
29 // Custom includes
30 #include <vector>
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 "../config.hh"
36 #include "OverloadedCommand.hh"
37 #include "ParseParameter.hh"
38 #include "../Utils/type_traits.hh"
39
40 #include "ParsedCommand.ih"
41 #include "ParsedCommand.mpp"
42 ///////////////////////////////hh.p////////////////////////////////////////
43
44 namespace senf {
45 namespace console {
46
47     class ParsedCommandOverloadBase
48         : public CommandOverload
49     {
50     public:
51         typedef boost::intrusive_ptr<ParsedCommandOverloadBase> ptr;
52
53     protected:
54         ParsedCommandOverloadBase();
55
56         detail::ParameterInfoBase & arg(unsigned n) const;
57         template <class Type> detail::ParameterInfo<Type> & arg(unsigned n) const;
58
59         template <class Type>
60         void addParameter();
61
62     private:
63         virtual void v_help(std::ostream & os) const;
64
65         typedef std::vector<detail::ParameterInfoBase::ptr> Parameters;
66         Parameters parameters_;
67     };
68
69     template <class FunctionTraits, unsigned arity=FunctionTraits::arity>
70     class ParsedCommandOverload {};
71
72 #   define BOOST_PP_ITERATION_PARAMS_1 (4, (0, SENF_CONSOLE_MAX_COMMAND_ARITY,                     \
73                                             SENF_ABSOLUTE_INCLUDE_PATH(Console/ParsedCommand.mpp), \
74                                             1))
75 #   include BOOST_PP_ITERATE()
76
77     template <class Function>
78     ParsedCommandOverload<typename detail::ParsedCommandTraits<Function>::traits> &
79     senf_console_add_node(DirectoryNode & node, std::string const & name, Function fn, int);
80
81 }}
82
83 #include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
84
85 BOOST_TYPEOF_REGISTER_TEMPLATE(senf::console::ParsedCommandOverload, (class,unsigned))
86 BOOST_TYPEOF_REGISTER_TEMPLATE(boost::function_traits, 1)
87
88 ///////////////////////////////hh.e////////////////////////////////////////
89 #include "ParsedCommand.cci"
90 #include "ParsedCommand.ct"
91 #include "ParsedCommand.cti"
92 #endif
93
94 \f
95 // Local Variables:
96 // mode: c++
97 // fill-column: 100
98 // comment-column: 40
99 // c-file-style: "senf"
100 // indent-tabs-mode: nil
101 // ispell-local-dictionary: "american"
102 // compile-command: "scons -u test"
103 // End: