445d05521c3d658ed813dc8f7749bdc7d7639141
[senf.git] / Console / ParsedCommand.ih
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 internal header */
25
26 #ifndef IH_ParsedCommand_
27 #define IH_ParsedCommand_ 1
28
29 // Custom includes
30
31 ///////////////////////////////ih.p////////////////////////////////////////
32
33 namespace senf {
34 namespace console {
35 namespace detail {
36
37     template <class Function, bool isFN=senf::is_any_function<Function>::value>
38     struct ParsedCommandTraits
39     {};
40
41     template <class Traits, bool flag=(Traits::arity>0)>
42     struct FirstArgType
43     {
44         typedef void type;
45     };
46
47     template <class Traits>
48     struct FirstArgType<Traits,true>
49     {
50         typedef typename Traits::arg1_type type;
51     };
52
53     template <class Function>
54     struct ParsedCommandTraits<Function, true>
55     {
56         typedef Function base_type;
57         typedef typename senf::remove_member_pointer<
58             typename boost::remove_pointer<base_type>::type>::type function_type;
59         typedef boost::function_traits<function_type> base_traits;
60
61         typedef typename FirstArgType<base_traits>::type first_arg_type;
62
63         static const bool has_ostream_arg = boost::is_same<first_arg_type, std::ostream &>::value;
64
65         typedef typename boost::mpl::if_c<
66             has_ostream_arg, 
67             typename function_traits_remove_arg<base_traits>::type, 
68             base_traits>
69         ::type traits;
70
71         static const bool is_member = boost::is_member_pointer<base_type>::value;
72         
73         typedef typename senf::member_class<base_type>::type class_type;
74     };
75
76 }}}
77
78 ///////////////////////////////ih.e////////////////////////////////////////
79 #endif
80
81 \f
82 // Local Variables:
83 // mode: c++
84 // fill-column: 100
85 // comment-column: 40
86 // c-file-style: "senf"
87 // indent-tabs-mode: nil
88 // ispell-local-dictionary: "american"
89 // compile-command: "scons -u test"
90 // End: