2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
15 \brief Variables inline template implementation */
17 #include "Variables.ih"
21 #define prefix_ inline
22 //-/////////////////////////////////////////////////////////////////////////////////////////////////
24 //-/////////////////////////////////////////////////////////////////////////////////////////////////
25 // senf::console::detail::QueryVariable<Variable>
27 template <class Variable>
28 prefix_ senf::console::detail::QueryVariable<Variable>::QueryVariable(Variable const & var)
32 template <class Variable>
33 prefix_ typename senf::console::detail::QueryVariable<Variable>::Traits::Overload::ptr
34 senf::console::detail::QueryVariable<Variable>::create(Variable const & var)
36 return CreateOverload::create(Function(QueryVariable(var)));
39 template <class Variable>
40 prefix_ Variable const & senf::console::detail::QueryVariable<Variable>::operator()()
46 //-/////////////////////////////////////////////////////////////////////////////////////////////////
47 // senf::console::detail::SetVariable<Variable>
49 template <class Variable>
50 prefix_ senf::console::detail::SetVariable<Variable>::SetVariable(Variable & var,
51 OnChangeHandler handler)
52 : var_ (var), handler_ (handler)
55 template <class Variable>
56 prefix_ typename senf::console::detail::SetVariable<Variable>::Traits::Overload::ptr
57 senf::console::detail::SetVariable<Variable>::create(Variable & var)
59 typename Traits::Overload::ptr overload (CreateOverload::create(Function(SetVariable(var))));
60 overload->arg(0).name = "new_value";
64 template <class Variable>
65 prefix_ void senf::console::detail::SetVariable<Variable>::operator()(Variable const & value)
77 //-/////////////////////////////////////////////////////////////////////////////////////////////////
78 // senf::console::ConstVariableFactory<Variable>
80 template <class Variable>
81 prefix_ senf::console::factory::ConstVariableFactory<Variable>
82 senf::console::factory::ConstVariableFactory<Variable>::doc(std::string const & doc)
88 template <class Variable>
89 prefix_ senf::console::factory::ConstVariableFactory<Variable>
90 senf::console::factory::ConstVariableFactory<Variable>::shortdoc(std::string const & doc)
96 template <class Variable>
97 prefix_ senf::console::factory::ConstVariableFactory<Variable>
98 senf::console::factory::ConstVariableFactory<Variable>::formatter(Formatter formatter)
100 queryOverload_->formatter(formatter);
104 template <class Variable>
105 prefix_ senf::console::OverloadedCommandNode &
106 senf::console::factory::ConstVariableFactory<Variable>::create(DirectoryNode & dir,
107 std::string const & name)
110 OverloadedCommandNode & node (OverloadedCommandNode::insertOverload(dir, name, queryOverload_));
111 if (doc_) node.doc(*doc_);
112 if (shortdoc_) node.shortdoc(*shortdoc_);
116 template <class Variable>
117 prefix_ senf::console::factory::ConstVariableFactory<Variable>::
118 ConstVariableFactory(Variable const & var)
119 : queryOverload_ (detail::QueryVariable<Variable>::create(var))
122 //-/////////////////////////////////////////////////////////////////////////////////////////////////
123 // senf::console::VariableFactory<Variable>
125 template <class Variable>
126 prefix_ typename senf::console::factory::VariableFactory<Variable>
127 senf::console::factory::VariableFactory<Variable>::parser(Parser parser)
129 setOverload_->template arg<0>().parser = parser;
133 template <class Variable>
134 prefix_ typename senf::console::factory::VariableFactory<Variable>
135 senf::console::factory::VariableFactory<Variable>::typeName(std::string const & name)
137 setOverload_->arg(0).type = name;
141 template <class Variable>
142 prefix_ typename senf::console::factory::VariableFactory<Variable>
143 senf::console::factory::VariableFactory<Variable>::onChange(OnChangeHandler handler)
145 setOverload_->function(
146 boost::bind(detail::SetVariable<Variable>(var_, handler),_2));
150 template <class Variable>
151 prefix_ typename senf::console::factory::VariableFactory<Variable>
152 senf::console::factory::VariableFactory<Variable>::doc(std::string const & doc)
154 ConstVariableFactory<Variable>::doc(doc);
158 template <class Variable>
159 prefix_ typename senf::console::factory::VariableFactory<Variable>
160 senf::console::factory::VariableFactory<Variable>::shortdoc(std::string const & doc)
162 ConstVariableFactory<Variable>::shortdoc(doc);
166 template <class Variable>
167 prefix_ typename senf::console::factory::VariableFactory<Variable>
168 senf::console::factory::VariableFactory<Variable>::formatter(Formatter formatter)
170 ConstVariableFactory<Variable>::formatter(formatter);
174 template <class Variable>
175 prefix_ senf::console::OverloadedCommandNode &
176 senf::console::factory::VariableFactory<Variable>::create(DirectoryNode & dir,
177 std::string const & name)
180 OverloadedCommandNode & node (ConstVariableFactory<Variable>::create(dir,name));
181 node.add(setOverload_);
185 template <class Variable>
186 prefix_ senf::console::factory::VariableFactory<Variable>::VariableFactory(Variable & var)
187 : ConstVariableFactory<Variable> (var),
188 setOverload_ (detail::SetVariable<Variable>::create(var)),
192 //-/////////////////////////////////////////////////////////////////////////////////////////////////
195 prefix_ senf::console::factory::VariableFactory<Var>
196 senf::console::factory::Variable(Var & var)
198 return VariableFactory<Var>(var);
202 prefix_ senf::console::factory::VariableFactory<Var>
203 senf::console::factory::Variable(boost::reference_wrapper<Var> var)
205 return VariableFactory<Var>(var);
209 prefix_ senf::console::factory::ConstVariableFactory<Var>
210 senf::console::factory::Variable(Var const & var)
212 return ConstVariableFactory<Var>(var);
216 prefix_ senf::console::factory::ConstVariableFactory<Var>
217 senf::console::factory::Variable(boost::reference_wrapper<Var const> var)
219 return ConstVariableFactory<Var>(var);
222 //-/////////////////////////////////////////////////////////////////////////////////////////////////
229 // comment-column: 40
230 // c-file-style: "senf"
231 // indent-tabs-mode: nil
232 // ispell-local-dictionary: "american"
233 // compile-command: "scons -u test"