Bayeux  3.4.1
Core Foundation library for SuperNEMO
builder.h
Go to the documentation of this file.
1 //
4 // Copyright (c) 2016 by François Mauger <mauger@lpccaen.in2p3.fr>
5 //
6 // This file is part of datatools.
7 //
8 // datatools 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 3 of the License, or
11 // (at your option) any later version.
12 //
13 // datatools 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 datatools. If not, see <http://www.gnu.org/licenses/>.
20 
21 #ifndef DATATOOLS_INTROSPECTION_BUILDER_H
22 #define DATATOOLS_INTROSPECTION_BUILDER_H
23 
24 // Standard library:
25 #include <string>
26 #include <iostream>
27 
28 // Third Party:
29 // - Boost:
30 #include <boost/lexical_cast.hpp>
31 #include <boost/program_options/options_description.hpp>
32 // - Camp:
33 #include <camp/function.hpp>
34 
35 // This project:
37 #include <datatools/ioutils.h>
38 
39 namespace datatools {
40 
42  namespace introspection {
43 
44  // Function flags
45  std::string function_builder_flag();
46  std::string function_constness_flag();
47  std::string function_description_tag();
48 
49  // General tags:
50  std::string name_tag();
51  std::string description_tag();
52  std::string type_tag();
53  std::string layout_tag();
54  std::string vector_fixed_size_tag();
55  std::string implicit_unit_tag();
56  std::string explicit_unit_dimension_tag();
57  std::string preferred_unit_tag();
58  std::string default_value_tag();
59 
60  // Composed tag (format : "PREFIX.WHAT");
61  std::string composed_tag(const std::string & prefix_, const std::string & what_);
62 
63  // Tag builders for function arguments:
64  std::string function_arg_prefix(std::size_t iarg_);
65  std::string function_arg_tag(std::size_t iarg_, const std::string & what_);
66 
67  // Tag builders for function returned parameter:
68  std::string function_returned_prefix();
69  std::string function_returned_tag(const std::string & what_);
70 
71  /*
72 
73  .DR_CLASS_TAG("arg[0].name", "x")
74  .DR_CLASS_TAG("arg[0].description", "The length")
75  .DR_CLASS_TAG("arg[0].type", "double")
76  .DR_CLASS_TAG("arg[0].layout", "scalar")
77  .DR_CLASS_TAG("arg[0].vector_fixed_size", 3)
78  .DR_CLASS_TAG("arg[0].implicit_unit", "mm")
79  .DR_CLASS_TAG("arg[0].explicit_unit_dimension", "length")
80  .DR_CLASS_TAG("arg[0].preferred_unit", "cm")
81 
82  */
83 
93  {
94  public:
95 
98 
100  method_builder(const std::string & funcname_);
101 
103  method_builder(const std::string & classname_, const std::string & funcname_);
104 
106  void reset();
107 
109  void set_classname(const std::string & classname_);
110 
113  void set_funcname(const std::string & funcname_);
114 
116  void set_function(const camp::Function & func_);
117 
119  void build_parameter_data_description(camp::Type param_type_,
120  std::size_t param_index_,
121  data_description & param_dd_);
122 
124  void build_argument(std::size_t arg_index_, argument & arg_);
125 
127  void build_returned(argument & returned_);
128 
130  void build(method & method_);
131 
132  static void dump_func(const camp::Function & func_, std::ostream & out_ = std::clog);
133 
134  public:
135 
137 
138  private:
139  std::string _classname_;
140  std::string _funcname_;
141 
142  // Work:
143  std::string _func_what_;
144  std::string _func_full_name_;
145  const camp::Function * _func_ = nullptr;
146 
147  };
148 
153  {
154  public:
155 
157  method_args_builder(method & method_, const boost::program_options::variables_map & vmap_);
158 
160  void build(camp::Args & args_);
161 
162  public:
163 
165 
166  private:
167 
168  method * _method_ = nullptr;
169  const boost::program_options::variables_map * _vmap_ = nullptr;
170  };
171 
172  } // namespace introspection
173 
174 } // namespace datatools
175 
176 #endif // DATATOOLS_INTROSPECTION_BUILDER_H
177 
178 // Local Variables: --
179 // mode: c++ --
180 // c-file-style: "gnu" --
181 // tab-width: 2 --
182 // End: --
std::string function_returned_tag(const std::string &what_)
void set_classname(const std::string &classname_)
Set the class name.
Description of a method.
Definition: method.h:45
Description of a method argument.
Definition: argument.h:46
Data description.
Definition: data_description.h:40
priority
Priority levels for logging from most to least critical.
Definition: logger.h:82
void build_parameter_data_description(camp::Type param_type_, std::size_t param_index_, data_description &param_dd_)
Build a data description for a parameter.
void set_funcname(const std::string &funcname_)
void build(camp::Args &args_)
Build the list of function arguments for the reflection API.
Description of a method or function.
void set_function(const camp::Function &func_)
Set the function.
datatools::logger::priority logging
Definition: builder.h:164
A fatal error. The application will most likely terminate. This is the highest priority.
Definition: logger.h:85
std::string layout_tag()
std::string vector_fixed_size_tag()
method_args_builder(method &method_, const boost::program_options::variables_map &vmap_)
Default constructor.
std::string description_tag()
std::string default_value_tag()
void build_argument(std::size_t arg_index_, argument &arg_)
Build an input argument at given index.
This class uses a variable map from the command line to build a list of arguments for calling a funct...
Definition: builder.h:152
datatools::logger::priority logging
Definition: builder.h:136
std::string function_arg_tag(std::size_t iarg_, const std::string &what_)
std::string implicit_unit_tag()
std::string preferred_unit_tag()
std::string function_builder_flag()
std::string function_description_tag()
The Bayeux/datatools library top-level namespace.
Definition: algo.h:13
void build_returned(argument &returned_)
Build the returned parameter.
std::string composed_tag(const std::string &prefix_, const std::string &what_)
std::string explicit_unit_dimension_tag()
std::string function_constness_flag()
std::string function_returned_prefix()
static void dump_func(const camp::Function &func_, std::ostream &out_=std::clog)
void build(method &method_)
Build the description of the method from the reflection function object.
This class uses the reflection API to build the description of a function or a class method....
Definition: builder.h:92
std::string function_arg_prefix(std::size_t iarg_)