Bayeux  3.4.1
Core Foundation library for SuperNEMO
unit_support.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_UNIT_SUPPORT_H
22 #define DATATOOLS_INTROSPECTION_UNIT_SUPPORT_H
23 
24 // Third party:
25 // - Bayeux/datatools:
26 #include <datatools/properties.h>
27 #include <datatools/i_tree_dump.h>
28 #ifndef Q_MOC_RUN
30 #endif // Q_MOC_RUN
31 
32 namespace datatools {
33 
34  namespace introspection {
35 
42  };
43 
45  const std::string & to_string(unit_support_type);
46 
48  bool from_string(const std::string & label_, unit_support_type & us_);
49 
51  unit_support_type from_label_to_unit_support(const std::string & label_);
52 
55 
58 
61 
64 
67  {
68  public:
69 
71  unit_info();
72 
74  unit_info(unit_support_type, const std::string & unit_token_, const std::string & unit_token2_ = "");
75 
77  virtual ~unit_info();
78 
80  bool is_valid() const;
81 
83  bool has_implicit_unit() const;
84 
86  bool has_explicit_unit_dimension() const;
87 
90 
93 
95  void set_implicit_unit_symbol(const std::string &);
96 
98  const std::string & get_implicit_unit_symbol() const;
99 
101  void set_explicit_unit_dimension_label(const std::string &);
102 
104  const std::string & get_explicit_unit_dimension_label() const;
105 
107  bool has_preferred_unit_symbol() const;
108 
110  void set_preferred_unit_symbol(const std::string &);
111 
113  const std::string & get_preferred_unit_symbol() const;
114 
116  void make_none();
117 
119  void make_implicit_unit(const std::string & unit_symbol_,
120  const std::string & preferred_unit_symbol_ = "");
121 
122 
124  void make_explicit_unit_dimension(const std::string & unit_dimension_label_,
125  const std::string & preferred_unit_symbol_ = "");
126 
147  void initialize(const datatools::properties &);
148 
150  void reset();
151 
161  };
162 
165  uint32_t flags_ = UI_XC_DEFAULT,
166  const std::string & prefix_ = "") const;
167 
169  virtual void tree_dump(std::ostream & out_ = std::clog,
170  const std::string & title_ = "",
171  const std::string & indent_ = "",
172  bool inherit_ = false) const;
173 
199  bool operator==(const unit_info & ui_) const;
200 
201  private:
202 
203  unit_support_type _us_;
204  std::string _implicit_unit_symbol_;
205  std::string _explicit_unit_dimension_label_;
206  std::string _preferred_unit_symbol_;
207 
208  };
209 
210  } // end of namespace introspection
211 
212 } // end of namespace datatools
213 
214 #ifndef Q_MOC_RUN
215 // Activate reflection layer:
217 #endif // Q_MOC_RUN
218 
219 #endif // DATATOOLS_INTROSPECTION_UNIT_SUPPORT_H
220 
221 // Local Variables: --
222 // mode: c++ --
223 // c-file-style: "gnu" --
224 // tab-width: 2 --
225 // End: --
bool is_explicit_unit_dimension(unit_support_type)
Check if an unit support type is explicit dimension.
bool has_explicit_unit_dimension() const
Check the explicit unitdimension trait.
Invalid unit support.
Definition: unit_support.h:38
unit_info_xc_flags
Flags for export to a container of properties.
Definition: unit_support.h:153
const std::string & get_explicit_unit_dimension_label() const
Return the explicit unit dimension.
bool has_preferred_unit_symbol() const
Check if preferred unit symbol is set.
An interface with utilities for printable objects.
Definition: i_tree_dump.h:36
bool is_implicit_unit(unit_support_type)
Check if an unit support type is implicit unit.
static const uint32_t bit01
Definition: bit_mask.h:28
Implicit unit associated to the parameter.
Definition: unit_support.h:40
const std::string & get_implicit_unit_symbol() const
Return the implicit unit symbol.
No unit management (plain float/double)
Definition: unit_support.h:39
virtual void tree_dump(std::ostream &out_=std::clog, const std::string &title_="", const std::string &indent_="", bool inherit_=false) const
Smart print.
unit_support_type
Unit support type for real parameters.
Definition: unit_support.h:37
bool is_valid() const
Check validity.
unit_support_type from_label_to_unit_support(const std::string &label_)
Convert a string to an unit support type.
void make_implicit_unit(const std::string &unit_symbol_, const std::string &preferred_unit_symbol_="")
Make the unit info with implicit unit.
void set_unit_support(unit_support_type)
Set the unit support.
bool from_string(const std::string &label_, access_type &access_)
Convert a string to an access type.
Explicit unit associated to the parameter.
Definition: unit_support.h:41
const std::string & get_preferred_unit_symbol() const
Return the preferred unit symbol.
unit_info()
Default constructor.
bool operator==(const unit_info &ui_) const
static const uint32_t bit02
Definition: bit_mask.h:29
void set_preferred_unit_symbol(const std::string &)
Set the preferred unit symbol.
void make_none()
Make the unit info with no unit support.
const std::string & to_string(access_type)
Convert an access type to a string.
void export_to_config(datatools::properties &config_, uint32_t flags_=UI_XC_DEFAULT, const std::string &prefix_="") const
Export to a container of properties.
void set_explicit_unit_dimension_label(const std::string &)
Set the explicit unit dimension label.
bool is_valid(access_type t_)
Check the validity of an access type.
The Bayeux/datatools library top-level namespace.
Definition: algo.h:13
unit_support_type get_unit_support() const
Return the unit support.
#define DR_TYPE_INIT(Introspectable)
Definition: reflection_interface.h:165
static const uint32_t bit00
Definition: bit_mask.h:27
void initialize(const datatools::properties &)
bool is_no_unit_support(unit_support_type)
Check if an unit support type is none.
void set_implicit_unit_symbol(const std::string &)
Set the implicit unit symbol.
void make_explicit_unit_dimension(const std::string &unit_dimension_label_, const std::string &preferred_unit_symbol_="")
Make the unit info with explicit unit dimension.
bool has_implicit_unit() const
Check the implicit unit trait.
A dictionary of arbitrary properties.
Definition: properties.h:125
Unit information associated to a parameter.
Definition: unit_support.h:66