Variables.hh
Go to the documentation of this file.
1 //
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
6 //
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
11 //
12 
13 
17 #ifndef HH_SENF_Utils_Console_Variables_
18 #define HH_SENF_Utils_Console_Variables_ 1
19 
20 // Custom includes
21 #include <boost/type_traits/is_convertible.hpp>
22 #include <boost/ref.hpp>
23 #include "Node.hh"
24 
25 #include "Variables.ih"
26 //#include "Variables.mpp"
27 //-/////////////////////////////////////////////////////////////////////////////////////////////////
28 
29 namespace senf {
30 namespace console {
31 
32  class ScopedDirectoryBase;
33  template <class Variable> class VariableAttributor;
34 
35 namespace factory {
36 
37 #ifndef DOXYGEN
38 
39  template <class Variable>
40  class ConstVariableFactory
41  : public detail::NodeFactory
42  {
43  public:
44  typedef typename detail::QueryVariable<Variable>::Traits::Overload QueryOverload;
45  typedef typename QueryOverload::Formatter Formatter;
46  typedef OverloadedCommandNode node_type;
47  typedef OverloadedCommandNode & result_type;
48 
49  ConstVariableFactory doc(std::string const & doc);
50  ConstVariableFactory shortdoc(std::string const & doc);
51  ConstVariableFactory formatter(Formatter formatter);
52 
53  OverloadedCommandNode & create(DirectoryNode & dir, std::string const & name) const;
54 
55  explicit ConstVariableFactory(Variable const & var);
56 
57  private:
58  typename QueryOverload::ptr queryOverload_;
59  boost::optional<std::string> doc_;
60  boost::optional<std::string> shortdoc_;
61  };
62 
63 #endif
64 
98 #ifdef DOXYGEN
99  class Variable
100 #else
101  template <class Variable>
102  class VariableFactory
103  : public ConstVariableFactory<Variable>
104 #endif
105  {
106  public:
107  typedef typename detail::SetVariable<Variable>::Traits::Overload SetOverload;
109  typedef typename detail::SetVariable<Variable>::OnChangeHandler OnChangeHandler;
110 
111  typedef typename ConstVariableFactory<Variable>::Formatter Formatter;
112  typedef typename ConstVariableFactory<Variable>::QueryOverload QueryOverload;
113 
114  VariableFactory doc(std::string const & doc);
115  VariableFactory shortdoc(std::string const & doc);
116  VariableFactory formatter(Formatter formatter);
117 
124  VariableFactory parser(Parser parser);
125 
136  VariableFactory typeName(std::string const & name);
137  VariableFactory onChange(OnChangeHandler handler);
138 
147  explicit VariableFactory(Variable & var);
148 
149  protected:
150 
151  private:
152  OverloadedCommandNode & create(DirectoryNode & dir, std::string const & name) const;
153 
154  typename SetOverload::ptr setOverload_;
155  Variable & var_;
156 
158  };
159 
160 #ifndef DOXYGEN
161 
162  template <class Var>
163  VariableFactory<Var> Variable(Var & var);
164 
165  template <class Var>
166  VariableFactory<Var> Variable(boost::reference_wrapper<Var> var);
167 
168  template <class Var>
169  ConstVariableFactory<Var> Variable(Var const & var);
170 
171  template <class Var>
172  ConstVariableFactory<Var> Variable(boost::reference_wrapper<Var const> var);
173 
174 #endif
175 
176 }}}
177 
178 //-/////////////////////////////////////////////////////////////////////////////////////////////////
179 //#include "Variables.cci"
180 //#include "Variables.ct"
181 #include "Variables.cti"
182 #endif
183 
184 
185 // Local Variables:
186 // mode: c++
187 // fill-column: 100
188 // comment-column: 40
189 // c-file-style: "senf"
190 // indent-tabs-mode: nil
191 // ispell-local-dictionary: "american"
192 // compile-command: "scons -u test"
193 // End:
unspecified_keyword_type parser
Argument parser.
Config/console tree directory node.
Definition: Node.hh:406
Node public header.
Command node which allows multiple registered callbacks.
Definition: Config.hh:28
ConstVariableFactory< Variable >::Formatter Formatter
Definition: Variables.hh:111
ConstVariableFactory< Variable >::QueryOverload QueryOverload
Definition: Variables.hh:112
detail::SetVariable< Variable >::Traits::Overload SetOverload
Definition: Variables.hh:107
unspecified_keyword_type name
Argument name.
detail::SetVariable< Variable >::OnChangeHandler OnChangeHandler
Definition: Variables.hh:109
Variable node factory.
Definition: Variables.hh:99
detail::ArgumentInfo< typename SetOverload::arg1_type >::Parser Parser
Definition: Variables.hh:108