Bayeux  3.4.1
Core Foundation library for SuperNEMO
method.h
Go to the documentation of this file.
1 //
4 // Copyright (c) 2015 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_METHOD_H
22 #define DATATOOLS_INTROSPECTION_METHOD_H
23 
24 // Standard library:
25 #include <string>
26 #include <iostream>
27 #include <vector>
28 
29 // Third party:
30 // - Boost:
31 #include <boost/optional.hpp>
32 #include <boost/scoped_ptr.hpp>
33 #include <boost/program_options.hpp>
34 // - Bayeux/datatools:
36 
37 // This project:
39 
40 namespace datatools {
41 
42  namespace introspection {
43 
45  class method
47  {
48  public:
49 
51  method();
52 
54  virtual ~method();
55 
57  bool has_constness() const;
58 
60  bool is_constness() const;
61 
63  void set_constness(bool);
64 
66  void reset_constness();
67 
69  bool has_type_id() const;
70 
72  void set_type_id(const std::string &);
73 
75  void reset_type_id();
76 
78  const std::string & get_type_id() const;
79 
81  bool has_arguments() const;
82 
84  bool has_input_arguments() const;
85 
87  bool has_output_arguments() const;
88 
90  bool has_unique_returned() const;
91 
93  const argument & get_unique_returned() const;
94 
96  void add_argument(const argument & arg_, const std::string & arg_name_ = "");
97 
99  bool has_argument_by_rank(std::size_t rank_) const;
100 
102  bool has_argument_by_name(const std::string & name_) const;
103 
105  const argument & get_argument_by_name(const std::string & name_) const;
106 
108  const argument & get_argument_by_rank(std::size_t rank_) const;
109 
111  void build_list_of_input_argument_names(std::vector<std::string> &) const;
112 
114  void build_list_of_output_argument_names(std::vector<std::string> &) const;
115 
117  bool is_valid() const;
118 
120  void initialize();
121 
123  void initialize(const datatools::properties &);
124 
126  void reset();
127 
139  };
140 
143  uint32_t flags_ = METHOD_XC_DEFAULT,
144  const std::string & prefix_ = "") const;
145 
147  virtual void tree_dump(std::ostream & out_ = std::clog,
148  const std::string & title_ = "",
149  const std::string & indent_ = "",
150  bool inherit_ = false) const;
151 
153  void make_scalar_setter(const std::string & arg_name_,
154  data_type arg_type_,
155  const std::string & arg_info_ = "",
156  const std::string & arg_info2_ = "",
157  const std::string & method_desc_ = "",
158  const std::string & method_name_ = "set");
159 
161  void make_scalar_getter(const std::string & arg_name_,
162  data_type arg_type_,
163  const std::string & arg_info_ = "",
164  const std::string & arg_info2_ = "",
165  const std::string & method_desc_ = "",
166  const std::string & method_name_ = "get");
167 
168  private:
169 
170  boost::optional<bool> _constness_;
171  boost::optional<std::string> _type_id_;
172 
173  // Working data:
174  // PIMPL-ized data structure:
175  struct pimpl_type;
176  boost::scoped_ptr<pimpl_type> _priv_;
177 
178  };
179 
180  } // namespace introspection
181 
182 } // namespace datatools
183 
184 #endif // DATATOOLS_INTROSPECTION_METHOD_H
185 
186 // Local Variables: --
187 // mode: c++ --
188 // c-file-style: "gnu" --
189 // tab-width: 2 --
190 // End: --
const argument & get_argument_by_name(const std::string &name_) const
Return argument by name.
Description of a method.
Definition: method.h:45
Description of a method argument.
Definition: argument.h:46
bool has_arguments() const
Check if the method has arguments.
bool is_valid() const
Check validity.
bool has_input_arguments() const
Check if the method has input arguments.
bool has_unique_returned() const
Check if the method has a single returned value/argument.
virtual void tree_dump(std::ostream &out_=std::clog, const std::string &title_="", const std::string &indent_="", bool inherit_=false) const
Smart print.
Definition: enriched_base.h:177
void set_constness(bool)
Set the method constness.
void reset_constness()
Reset the method constness.
void make_scalar_getter(const std::string &arg_name_, data_type arg_type_, const std::string &arg_info_="", const std::string &arg_info2_="", const std::string &method_desc_="", const std::string &method_name_="get")
Make a getter method with one unique output scalar argument.
void build_list_of_input_argument_names(std::vector< std::string > &) const
Build the list of input arguments' names.
bool has_type_id() const
Check if type identifier is set.
void set_type_id(const std::string &)
Set the type identifier.
void make_scalar_setter(const std::string &arg_name_, data_type arg_type_, const std::string &arg_info_="", const std::string &arg_info2_="", const std::string &method_desc_="", const std::string &method_name_="set")
Make a setter method with one unique input scalar argument.
bool has_constness() const
Check if constness is set.
const argument & get_argument_by_rank(std::size_t rank_) const
Return argument by rank.
bool has_output_arguments() const
Check if the method has output arguments.
void build_list_of_output_argument_names(std::vector< std::string > &) const
Build the list of output arguments' names.
virtual ~method()
Destructor.
bool has_argument_by_rank(std::size_t rank_) const
Check if an argument at given rank exists.
bool has_argument_by_name(const std::string &name_) const
Check if an argument at given name exists.
data_type
Supported data types.
Definition: data_type.h:41
bool is_constness() const
Check if the method is const.
const argument & get_unique_returned() const
Return the unique returned argument (if any)
void export_to_config(datatools::properties &config_, uint32_t flags_=METHOD_XC_DEFAULT, const std::string &prefix_="") const
Export to a container of properties.
The Bayeux/datatools library top-level namespace.
Definition: algo.h:13
void reset_type_id()
Reset the type identifier.
const std::string & get_type_id() const
Return the type identifier.
method_xc_flags
Flags for export to a container of properties.
Definition: method.h:129
A base class with useful attributes usable in many contexts.
Definition: enriched_base.h:52
void initialize()
Initialization.
void add_argument(const argument &arg_, const std::string &arg_name_="")
Add an argument.
method()
Default constructor.
Definition: enriched_base.h:168
Description of a method argument.
A dictionary of arbitrary properties.
Definition: properties.h:125