Fix SCons 1.2.0 build failure
[senf.git] / senf / Utils / 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>::shortdoc(std::string const & doc)
84 {
85     queryOverload_.node().shortdoc(doc);
86     return *this;
87 }
88
89 template <class Variable>
90 prefix_ senf::console::ConstVariableAttributor<Variable>
91 senf::console::ConstVariableAttributor<Variable>::formatter(Formatter formatter)
92 {
93     queryOverload_.formatter(formatter);
94     return *this;
95 }
96
97 template <class Variable>
98 prefix_ senf::console::ConstVariableAttributor<Variable>::
99 ConstVariableAttributor(QueryOverload & queryOverload)
100     : queryOverload_ (queryOverload)
101 {}
102
103 template <class Variable>
104 prefix_ senf::console::OverloadedCommandNode &
105 senf::console::ConstVariableAttributor<Variable>::node()
106     const
107 {
108     return queryOverload_.node();
109 }
110
111 template <class Variable>
112 prefix_ senf::console::ConstVariableAttributor<Variable>::
113 operator senf::console::OverloadedCommandNode &()
114     const
115 {
116     return node();
117 }
118
119 ///////////////////////////////////////////////////////////////////////////
120 // senf::console::VariableAttributor<Variable>
121
122 template <class Variable>
123 prefix_ senf::console::VariableAttributor<Variable>
124 senf::console::VariableAttributor<Variable>::parser(Parser parser)
125 {
126     setOverload_.template arg<0>().parser = parser;
127     return *this;
128 }
129
130 template <class Variable>
131 prefix_ senf::console::VariableAttributor<Variable>
132 senf::console::VariableAttributor<Variable>::typeName(std::string const & name)
133 {
134     setOverload_.arg(0).type = name;
135     return *this;
136 }
137
138 template <class Variable>
139 prefix_ typename senf::console::VariableAttributor<Variable>
140 senf::console::VariableAttributor<Variable>::onChange(OnChangeHandler handler)
141 {
142     setOverload_.function( 
143         boost::bind(detail::SetVariable<Variable>(var_, handler),_2));
144     return *this;
145 }
146
147 template <class Variable>
148 prefix_ typename senf::console::VariableAttributor<Variable>
149 senf::console::VariableAttributor<Variable>::doc(std::string const & doc)
150 {
151     ConstVariableAttributor<Variable>::doc(doc);
152     return *this;
153 }
154
155 template <class Variable>
156 prefix_ typename senf::console::VariableAttributor<Variable>
157 senf::console::VariableAttributor<Variable>::shortdoc(std::string const & doc)
158 {
159     ConstVariableAttributor<Variable>::shortdoc(doc);
160     return *this;
161 }
162
163 template <class Variable>
164 prefix_ typename senf::console::VariableAttributor<Variable>
165 senf::console::VariableAttributor<Variable>::formatter(Formatter formatter)
166 {
167     ConstVariableAttributor<Variable>::formatter(formatter);
168     return *this;
169 }
170
171 template <class Variable>
172 prefix_
173 senf::console::VariableAttributor<Variable>::VariableAttributor(QueryOverload & queryOverload,
174                                                                 SetOverload & setOverload,
175                                                                 Variable & var)
176     : ConstVariableAttributor<Variable> (queryOverload), setOverload_ (setOverload), var_ (var)
177 {}
178
179 ///////////////////////////////////////////////////////////////////////////
180
181 template <class Variable, bool isConst>
182 prefix_ senf::console::VariableAttributor<Variable>
183 senf::console::detail::VariableNodeCreator<Variable,isConst>::add(DirectoryNode & node,
184                                                                   std::string const & name,
185                                                                   Variable & var)
186 {
187     typename VariableAttributor<Variable>::SetOverload & setOverload ( 
188         node.add(name, typename detail::SetVariable<Variable>::Function(
189                      detail::SetVariable<Variable>(var)))
190             .arg("new_value")
191             .overload() );
192     typename VariableAttributor<Variable>::QueryOverload & queryOverload ( 
193         node.add(name, typename detail::QueryVariable<Variable>::Function(
194                      detail::QueryVariable<Variable>(var))).overload() );
195
196     return VariableAttributor<Variable>(queryOverload, setOverload, var);
197 }
198
199 template <class Variable>
200 prefix_ senf::console::ConstVariableAttributor<Variable>
201 senf::console::detail::VariableNodeCreator<Variable, true>::add(DirectoryNode & node,
202                                                                 std::string const & name,
203                                                                 Variable & var)
204 {
205     typename VariableAttributor<Variable>::QueryOverload & queryOverload ( 
206         node.add(name, typename detail::QueryVariable<Variable>::Function(
207                      detail::QueryVariable<Variable>(var))).overload() );
208
209     return ConstVariableAttributor<Variable>(queryOverload);
210 }
211
212 #ifndef DOXYGEN
213
214 template <class Variable>
215 prefix_ senf::console::VariableAttributor<Variable> senf::console::
216 senf_console_add_node(DirectoryNode & node, std::string const & name, Variable & var, int,
217                       typename boost::disable_if< boost::is_convertible<Variable*, ScopedDirectoryBase*> >::type *,
218                       typename boost::disable_if< boost::is_convertible<Variable*, GenericNode*> >::type *, 
219                       typename boost::disable_if_c<detail::ParsedCommandTraits<Variable>::is_callable>::type *)
220 {
221     return detail::VariableNodeCreator<Variable>::add(node, name, var);
222 }
223
224 template <class Variable>
225 prefix_ typename senf::console::detail::VariableNodeCreator<Variable>::result_type
226 senf::console::senf_console_add_node(DirectoryNode & node, std::string const & name,
227                                      boost::reference_wrapper<Variable> var, int)
228 {
229     return detail::VariableNodeCreator<Variable>::add(node, name, var.get());
230 }
231
232 template <class Variable, class Owner>
233 prefix_ senf::console::VariableAttributor<Variable> senf::console::
234 senf_console_add_node(DirectoryNode & node, Owner & owner, std::string const & name,
235                       Variable & var, int,
236                       typename boost::disable_if< boost::is_convertible<Variable*, ScopedDirectoryBase*> >::type *, 
237                       typename boost::disable_if< boost::is_convertible<Variable*, GenericNode*> >::type *, 
238                       typename boost::disable_if_c<detail::ParsedCommandTraits<Variable>::is_callable>::type *)
239 {
240     return detail::VariableNodeCreator<Variable>::add(node, name, var);
241 }
242
243 template <class Variable, class Owner>
244 prefix_ typename senf::console::detail::VariableNodeCreator<Variable>::result_type
245 senf::console::senf_console_add_node(DirectoryNode & node, Owner &,
246                                      std::string const & name,
247                                      boost::reference_wrapper<Variable> var, int)
248 {
249     return detail::VariableNodeCreator<Variable>::add(node, name, var.get());
250 }
251
252 #endif
253
254 ///////////////////////////////cti.e///////////////////////////////////////
255 #undef prefix_
256
257 \f
258 // Local Variables:
259 // mode: c++
260 // fill-column: 100
261 // comment-column: 40
262 // c-file-style: "senf"
263 // indent-tabs-mode: nil
264 // ispell-local-dictionary: "american"
265 // compile-command: "scons -u test"
266 // End: