Console: Complete 'Variable' command implementation
[senf.git] / Console / Variables.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 Variables public header */
25
26 #ifndef HH_Variables_
27 #define HH_Variables_ 1
28
29 // Custom includes
30 #include <boost/utility.hpp>
31 #include <boost/type_traits/is_convertible.hpp>
32 #include <boost/ref.hpp>
33 #include "ParsedCommand.hh"
34
35 #include "Variables.ih"
36 //#include "Variables.mpp"
37 ///////////////////////////////hh.p////////////////////////////////////////
38
39 namespace senf {
40 namespace console {
41
42     class ScopedDirectoryBase;
43     template <class Variable> class VariableAttributor;
44
45     template <class Variable>
46     VariableAttributor<Variable> senf_console_add_node(
47         DirectoryNode & node, std::string const & name, Variable & var, int,
48         typename boost::disable_if< boost::is_convertible<Variable*, ScopedDirectoryBase*> >::type * = 0);
49
50     template <class Variable>
51     typename detail::VariableNodeCreator<Variable>::result_type
52     senf_console_add_node(DirectoryNode & node, std::string const & name, 
53                           boost::reference_wrapper<Variable> var, int);
54
55     template <class Variable>
56     class ConstVariableAttributor
57     {
58     public:
59         typedef typename detail::QueryVariable<Variable>::Traits::Overload QueryOverload;
60         typedef typename QueryOverload::Formatter Formatter;
61         typedef OverloadedCommandNode node_type;
62         typedef ConstVariableAttributor return_type;
63
64         ConstVariableAttributor doc(std::string const & doc);
65         ConstVariableAttributor formatter(Formatter formatter);
66
67     protected:
68         explicit ConstVariableAttributor(QueryOverload & queryOverload);
69
70     private:
71         QueryOverload & queryOverload_;
72
73         friend class detail::VariableNodeCreator<Variable const>;
74     };
75
76     template <class Variable>
77     class VariableAttributor
78         : public ConstVariableAttributor<Variable>
79     {
80     public:
81         typedef typename detail::SetVariable<Variable>::Traits::Overload SetOverload;
82         typedef typename detail::ArgumentInfo<typename SetOverload::arg1_type>::Parser Parser;
83         typedef OverloadedCommandNode node_type;
84         typedef VariableAttributor return_type;
85
86         typedef typename ConstVariableAttributor<Variable>::Formatter Formatter;
87         typedef typename ConstVariableAttributor<Variable>::QueryOverload QueryOverload;
88
89         VariableAttributor parser(Parser parser);
90         VariableAttributor typeName(std::string const & name);
91  
92         VariableAttributor doc(std::string const & doc);
93         VariableAttributor formatter(Formatter formatter);
94        
95     protected:
96
97     private:
98         VariableAttributor(QueryOverload & queryOverload, SetOverload & setOverload);
99
100         SetOverload & setOverload_;
101
102         friend class detail::VariableNodeCreator<Variable>;
103     };
104 }}
105
106 ///////////////////////////////hh.e////////////////////////////////////////
107 //#include "Variables.cci"
108 //#include "Variables.ct"
109 #include "Variables.cti"
110 #endif
111
112 \f
113 // Local Variables:
114 // mode: c++
115 // fill-column: 100
116 // comment-column: 40
117 // c-file-style: "senf"
118 // indent-tabs-mode: nil
119 // ispell-local-dictionary: "american"
120 // compile-command: "scons -u test"
121 // End: