Console: Remove senf_console_add_node() overloads from documentation
[senf.git] / Console / Variables.cti
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 inline template implementation */
25
26 #include "Variables.ih"
27
28 // Custom includes
29
30 #define prefix_ inline
31 ///////////////////////////////cti.p///////////////////////////////////////
32
33 ///////////////////////////////////////////////////////////////////////////
34 // senf::console::detail::QueryVariable<Variable>
35
36 template <class Variable>
37 prefix_ senf::console::detail::QueryVariable<Variable>::QueryVariable(Variable const & var)
38     : var_ (var)
39 {}
40
41 template <class Variable>
42 prefix_ Variable const & senf::console::detail::QueryVariable<Variable>::operator()()
43     const
44 {
45     return var_;
46 }
47
48 ///////////////////////////////////////////////////////////////////////////
49 // senf::console::detail::SetVariable<Variable>
50
51 template <class Variable>
52 prefix_ senf::console::detail::SetVariable<Variable>::SetVariable(Variable & var,
53                                                                   OnChangeHandler handler)
54     : var_ (var), handler_ (handler)
55 {}
56
57 template <class Variable>
58 prefix_ void senf::console::detail::SetVariable<Variable>::operator()(Variable const & value)
59     const
60 {
61     if (handler_) {
62         Variable old (var_);
63         var_ = value;
64         handler_(old);
65     }
66     else
67         var_ = value;
68 }
69
70 ///////////////////////////////////////////////////////////////////////////
71 // senf::console::ConstVariableAttributor<Variable>
72
73 template <class Variable>
74 prefix_ senf::console::ConstVariableAttributor<Variable>
75 senf::console::ConstVariableAttributor<Variable>::doc(std::string const & doc)
76 {
77     queryOverload_.node().doc(doc);
78     return *this;
79 }
80
81 template <class Variable>
82 prefix_ senf::console::ConstVariableAttributor<Variable>
83 senf::console::ConstVariableAttributor<Variable>::formatter(Formatter formatter)
84 {
85     queryOverload_.formatter(formatter);
86     return *this;
87 }
88
89 template <class Variable>
90 prefix_ senf::console::ConstVariableAttributor<Variable>::
91 ConstVariableAttributor(QueryOverload & queryOverload)
92     : queryOverload_ (queryOverload)
93 {}
94
95 ///////////////////////////////////////////////////////////////////////////
96 // senf::console::VariableAttributor<Variable>
97
98 template <class Variable>
99 prefix_ senf::console::VariableAttributor<Variable>
100 senf::console::VariableAttributor<Variable>::parser(Parser parser)
101 {
102     setOverload_.template arg<0>().parser = parser;
103     return *this;
104 }
105
106 template <class Variable>
107 prefix_ senf::console::VariableAttributor<Variable>
108 senf::console::VariableAttributor<Variable>::typeName(std::string const & name)
109 {
110     setOverload_.arg(0).type = name;
111     return *this;
112 }
113
114 template <class Variable>
115 prefix_ typename senf::console::VariableAttributor<Variable>
116 senf::console::VariableAttributor<Variable>::onChange(OnChangeHandler handler)
117 {
118     setOverload_.function( 
119         boost::bind(detail::SetVariable<Variable>(var_, handler),_2));
120     return *this;
121 }
122
123 template <class Variable>
124 prefix_ typename senf::console::VariableAttributor<Variable>
125 senf::console::VariableAttributor<Variable>::doc(std::string const & doc)
126 {
127     ConstVariableAttributor<Variable>::doc(doc);
128     return *this;
129 }
130
131 template <class Variable>
132 prefix_ typename senf::console::VariableAttributor<Variable>
133 senf::console::VariableAttributor<Variable>::formatter(Formatter formatter)
134 {
135     ConstVariableAttributor<Variable>::formatter(formatter);
136     return *this;
137 }
138
139 template <class Variable>
140 prefix_
141 senf::console::VariableAttributor<Variable>::VariableAttributor(QueryOverload & queryOverload,
142                                                                 SetOverload & setOverload,
143                                                                 Variable & var)
144     : ConstVariableAttributor<Variable> (queryOverload), setOverload_ (setOverload), var_ (var)
145 {}
146
147 ///////////////////////////////////////////////////////////////////////////
148
149 template <class Variable, bool isConst>
150 prefix_ senf::console::VariableAttributor<Variable>
151 senf::console::detail::VariableNodeCreator<Variable,isConst>::add(DirectoryNode & node,
152                                                                   std::string const & name,
153                                                                   Variable & var)
154 {
155     typename VariableAttributor<Variable>::SetOverload & setOverload ( 
156         node.add(name, typename detail::SetVariable<Variable>::Function(
157                      detail::SetVariable<Variable>(var)))
158             .arg("new_value")
159             .overload() );
160     typename VariableAttributor<Variable>::QueryOverload & queryOverload ( 
161         node.add(name, typename detail::QueryVariable<Variable>::Function(
162                      detail::QueryVariable<Variable>(var))).overload() );
163
164     return VariableAttributor<Variable>(queryOverload, setOverload, var);
165 }
166
167 template <class Variable>
168 prefix_ senf::console::ConstVariableAttributor<Variable>
169 senf::console::detail::VariableNodeCreator<Variable, true>::add(DirectoryNode & node,
170                                                                 std::string const & name,
171                                                                 Variable & var)
172 {
173     typename VariableAttributor<Variable>::QueryOverload & queryOverload ( 
174         node.add(name, typename detail::QueryVariable<Variable>::Function(
175                      detail::QueryVariable<Variable>(var))).overload() );
176
177     return ConstVariableAttributor<Variable>(queryOverload);
178 }
179
180 #ifndef DOXYGEN
181
182 template <class Variable>
183 prefix_ senf::console::VariableAttributor<Variable> senf::console::
184 senf_console_add_node(DirectoryNode & node, std::string const & name, Variable & var, int,
185                       typename boost::disable_if< boost::is_convertible<Variable*, ScopedDirectoryBase*> >::type *)
186 {
187     return detail::VariableNodeCreator<Variable>::add(node, name, var);
188 }
189
190 template <class Variable>
191 prefix_ typename senf::console::detail::VariableNodeCreator<Variable>::result_type
192 senf::console::senf_console_add_node(DirectoryNode & node, std::string const & name,
193                                      boost::reference_wrapper<Variable> var, int)
194 {
195     return detail::VariableNodeCreator<Variable>::add(node, name, var.get());
196 }
197
198 #endif
199
200 ///////////////////////////////cti.e///////////////////////////////////////
201 #undef prefix_
202
203 \f
204 // Local Variables:
205 // mode: c++
206 // fill-column: 100
207 // comment-column: 40
208 // c-file-style: "senf"
209 // indent-tabs-mode: nil
210 // ispell-local-dictionary: "american"
211 // compile-command: "scons -u test"
212 // End: