Utils: Fix intrusive_refcount for const objects
[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 <boost/utility.hpp>
36 #include "../config.hh"
37 #include "OverloadedCommand.hh"
38 #include "ParseParameter.hh"
39 #include "../Utils/type_traits.hh"
40
41 #include "ParsedCommand.ih"
42 #include "ParsedCommand.mpp"
43 ///////////////////////////////hh.p////////////////////////////////////////
44
45 namespace senf {
46 namespace console {
47
48     class ParsedCommandOverloadBase
49         : public CommandOverload
50     {
51     public:
52         typedef boost::intrusive_ptr<ParsedCommandOverloadBase> ptr;
53
54         detail::ParameterInfoBase & arg(unsigned n) const;
55         template <class Type> detail::ParameterInfo<Type> & arg(unsigned n) const;
56
57         void doc(std::string const & d);
58
59     protected:
60         ParsedCommandOverloadBase();
61
62         template <class Type>
63         void addParameter();
64
65     private:
66         virtual unsigned v_numArguments() const;
67         virtual void v_argumentDoc(unsigned index, ArgumentDoc & doc) const;
68         virtual std::string v_doc() const;
69
70         typedef std::vector<detail::ParameterInfoBase::ptr> Parameters;
71         Parameters parameters_;
72         std::string doc_;
73     };
74
75     template <class FunctionTraits, unsigned arity=FunctionTraits::arity>
76     class ParsedCommandOverload {};
77
78 #   define BOOST_PP_ITERATION_PARAMS_1 (4, (0, SENF_CONSOLE_MAX_COMMAND_ARITY,                     \
79                                             SENF_ABSOLUTE_INCLUDE_PATH(Console/ParsedCommand.mpp), \
80                                             1))
81 #   include BOOST_PP_ITERATE()
82
83 #ifndef DOXYGEN
84
85     template <class Function>
86     ParsedCommandOverload<typename detail::ParsedCommandTraits<Function>::traits> &
87     senf_console_add_node(DirectoryNode & node, std::string const & name, Function fn, int);
88
89     template <class Owner, class Function>
90     ParsedCommandOverload<typename detail::ParsedCommandTraits<Function>::traits> &
91     senf_console_add_node(DirectoryNode & node, Owner & owner, std::string const & name,
92                           Function fn, int,
93                           typename boost::enable_if_c<detail::ParsedCommandTraits<Function>::is_member>::type * = 0);
94
95 #endif
96
97 }}
98
99 #include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
100
101 BOOST_TYPEOF_REGISTER_TEMPLATE(senf::console::ParsedCommandOverload, (class,unsigned))
102 BOOST_TYPEOF_REGISTER_TEMPLATE(boost::function_traits, 1)
103
104 ///////////////////////////////hh.e////////////////////////////////////////
105 #include "ParsedCommand.cci"
106 #include "ParsedCommand.ct"
107 #include "ParsedCommand.cti"
108 #endif
109
110 \f
111 // Local Variables:
112 // mode: c++
113 // fill-column: 100
114 // comment-column: 40
115 // c-file-style: "senf"
116 // indent-tabs-mode: nil
117 // ispell-local-dictionary: "american"
118 // compile-command: "scons -u test"
119 // End: