4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
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.
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.
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.
24 \brief Variables inline template implementation */
26 #include "Variables.ih"
30 #define prefix_ inline
31 ///////////////////////////////cti.p///////////////////////////////////////
33 ///////////////////////////////////////////////////////////////////////////
34 // senf::console::detail::QueryVariable<Variable>
36 template <class Variable>
37 prefix_ senf::console::detail::QueryVariable<Variable>::QueryVariable(Variable const & var)
41 template <class Variable>
42 prefix_ Variable const & senf::console::detail::QueryVariable<Variable>::operator()()
48 ///////////////////////////////////////////////////////////////////////////
49 // senf::console::detail::SetVariable<Variable>
51 template <class Variable>
52 prefix_ senf::console::detail::SetVariable<Variable>::SetVariable(Variable & var,
53 OnChangeHandler handler)
54 : var_ (var), handler_ (handler)
57 template <class Variable>
58 prefix_ void senf::console::detail::SetVariable<Variable>::operator()(Variable const & value)
70 ///////////////////////////////////////////////////////////////////////////
71 // senf::console::ConstVariableAttributor<Variable>
73 template <class Variable>
74 prefix_ senf::console::ConstVariableAttributor<Variable>
75 senf::console::ConstVariableAttributor<Variable>::doc(std::string const & doc)
77 queryOverload_.node().doc(doc);
81 template <class Variable>
82 prefix_ senf::console::ConstVariableAttributor<Variable>
83 senf::console::ConstVariableAttributor<Variable>::formatter(Formatter formatter)
85 queryOverload_.formatter(formatter);
89 template <class Variable>
90 prefix_ senf::console::ConstVariableAttributor<Variable>::
91 ConstVariableAttributor(QueryOverload & queryOverload)
92 : queryOverload_ (queryOverload)
95 template <class Variable>
96 prefix_ senf::console::OverloadedCommandNode &
97 senf::console::ConstVariableAttributor<Variable>::node()
100 return queryOverload_.node();
103 template <class Variable>
104 prefix_ senf::console::ConstVariableAttributor<Variable>::
105 operator senf::console::OverloadedCommandNode &()
111 ///////////////////////////////////////////////////////////////////////////
112 // senf::console::VariableAttributor<Variable>
114 template <class Variable>
115 prefix_ senf::console::VariableAttributor<Variable>
116 senf::console::VariableAttributor<Variable>::parser(Parser parser)
118 setOverload_.template arg<0>().parser = parser;
122 template <class Variable>
123 prefix_ senf::console::VariableAttributor<Variable>
124 senf::console::VariableAttributor<Variable>::typeName(std::string const & name)
126 setOverload_.arg(0).type = name;
130 template <class Variable>
131 prefix_ typename senf::console::VariableAttributor<Variable>
132 senf::console::VariableAttributor<Variable>::onChange(OnChangeHandler handler)
134 setOverload_.function(
135 boost::bind(detail::SetVariable<Variable>(var_, handler),_2));
139 template <class Variable>
140 prefix_ typename senf::console::VariableAttributor<Variable>
141 senf::console::VariableAttributor<Variable>::doc(std::string const & doc)
143 ConstVariableAttributor<Variable>::doc(doc);
147 template <class Variable>
148 prefix_ typename senf::console::VariableAttributor<Variable>
149 senf::console::VariableAttributor<Variable>::formatter(Formatter formatter)
151 ConstVariableAttributor<Variable>::formatter(formatter);
155 template <class Variable>
157 senf::console::VariableAttributor<Variable>::VariableAttributor(QueryOverload & queryOverload,
158 SetOverload & setOverload,
160 : ConstVariableAttributor<Variable> (queryOverload), setOverload_ (setOverload), var_ (var)
163 ///////////////////////////////////////////////////////////////////////////
165 template <class Variable, bool isConst>
166 prefix_ senf::console::VariableAttributor<Variable>
167 senf::console::detail::VariableNodeCreator<Variable,isConst>::add(DirectoryNode & node,
168 std::string const & name,
171 typename VariableAttributor<Variable>::SetOverload & setOverload (
172 node.add(name, typename detail::SetVariable<Variable>::Function(
173 detail::SetVariable<Variable>(var)))
176 typename VariableAttributor<Variable>::QueryOverload & queryOverload (
177 node.add(name, typename detail::QueryVariable<Variable>::Function(
178 detail::QueryVariable<Variable>(var))).overload() );
180 return VariableAttributor<Variable>(queryOverload, setOverload, var);
183 template <class Variable>
184 prefix_ senf::console::ConstVariableAttributor<Variable>
185 senf::console::detail::VariableNodeCreator<Variable, true>::add(DirectoryNode & node,
186 std::string const & name,
189 typename VariableAttributor<Variable>::QueryOverload & queryOverload (
190 node.add(name, typename detail::QueryVariable<Variable>::Function(
191 detail::QueryVariable<Variable>(var))).overload() );
193 return ConstVariableAttributor<Variable>(queryOverload);
198 template <class Variable>
199 prefix_ senf::console::VariableAttributor<Variable> senf::console::
200 senf_console_add_node(DirectoryNode & node, std::string const & name, Variable & var, int,
201 typename boost::disable_if< boost::is_convertible<Variable*, ScopedDirectoryBase*> >::type *,
202 typename boost::disable_if< boost::is_convertible<Variable*, GenericNode*> >::type *,
203 typename boost::disable_if_c<detail::ParsedCommandTraits<Variable>::is_callable>::type *)
205 return detail::VariableNodeCreator<Variable>::add(node, name, var);
208 template <class Variable>
209 prefix_ typename senf::console::detail::VariableNodeCreator<Variable>::result_type
210 senf::console::senf_console_add_node(DirectoryNode & node, std::string const & name,
211 boost::reference_wrapper<Variable> var, int)
213 return detail::VariableNodeCreator<Variable>::add(node, name, var.get());
216 template <class Variable, class Owner>
217 prefix_ senf::console::VariableAttributor<Variable> senf::console::
218 senf_console_add_node(DirectoryNode & node, Owner & owner, std::string const & name,
220 typename boost::disable_if< boost::is_convertible<Variable*, ScopedDirectoryBase*> >::type *,
221 typename boost::disable_if< boost::is_convertible<Variable*, GenericNode*> >::type *,
222 typename boost::disable_if_c<detail::ParsedCommandTraits<Variable>::is_callable>::type *)
224 return detail::VariableNodeCreator<Variable>::add(node, name, var);
227 template <class Variable, class Owner>
228 prefix_ typename senf::console::detail::VariableNodeCreator<Variable>::result_type
229 senf::console::senf_console_add_node(DirectoryNode & node, Owner &,
230 std::string const & name,
231 boost::reference_wrapper<Variable> var, int)
233 return detail::VariableNodeCreator<Variable>::add(node, name, var.get());
238 ///////////////////////////////cti.e///////////////////////////////////////
245 // comment-column: 40
246 // c-file-style: "senf"
247 // indent-tabs-mode: nil
248 // ispell-local-dictionary: "american"
249 // compile-command: "scons -u test"