Bayeux  3.4.1
Core Foundation library for SuperNEMO
variant_model.h
Go to the documentation of this file.
1 /* Author(s) : Francois Mauger <mauger@lpccaen.in2p3.fr>
3  * Creation date : 2014-05-11
4  * Last modified : 2014-08-10
5  *
6  * Copyright (C) 2014 Francois Mauger <mauger@lpccaen.in2p3.fr>
7  *
8  * This program 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 (at
11  * your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  *
23  * Description:
24  *
25  * The description of a configuration variant.
26  *
27  */
28 
29 #ifndef DATATOOLS_CONFIGURATION_VARIANT_MODEL_H
30 #define DATATOOLS_CONFIGURATION_VARIANT_MODEL_H
31 
32 // Standard library:
33 #include <string>
34 #include <set>
35 #include <vector>
36 #include <map>
37 
38 // This project (Bayeux/datatools):
39 #include <datatools/i_tree_dump.h>
41 #include <datatools/handle.h>
42 #include <datatools/types.h>
46 
47 namespace datatools {
48 
49  // Forward declaration:
50  class multi_properties;
51 
52  namespace configuration {
53 
54  // Forward declaration:
55  class parameter_model;
56  class parameter_physical;
57 
61  {
62  public:
63 
65  virtual bool is_name_valid(const std::string & name_) const;
66 
70  std::string description;
71  // Overriden default value(s) with respect to the parameter model ?
72  int rank = -1;
73  };
74 
76  typedef std::map<std::string, parameter_record> parameter_dict_type;
77 
79  variant_model();
80 
82  virtual ~variant_model();
83 
85  bool has_documentation() const;
86 
88  void set_documentation(const std::string & documentation_);
89 
91  const std::string & get_documentation() const;
92 
94  bool has_parameter(const std::string & name_) const;
95 
97  void add_parameter(const std::string & parameter_name_,
98  const pm_handle_type & parameter_model_handle_,
99  const std::string & description_ = "",
100  const std::string & occurence_def_ = "",
101  int rank_ = -1);
102 
104  void remove_parameter(const std::string & parameter_name_);
105 
107  bool is_rank_used(int rank_) const;
108 
110  bool is_ranked_parameter(const std::string & parameter_name_) const;
111 
113  int get_parameter_rank(const std::string & parameter_name_) const;
114 
116  void set_parameter_rank(const std::string & parameter_name_, int rank_);
117 
119  void build_list_of_ranked_parameters(std::vector<std::string> &) const;
120 
122  const std::string & get_parameter_description(const std::string & parameter_name_) const;
123 
125  const parameter_model & get_parameter_model(const std::string & parameter_name_) const;
126 
128  pm_handle_type get_parameter_model_handle(const std::string & parameter_name_) const;
129 
131  bool has_parameter_occurrence(const std::string & parameter_name_) const;
132 
134  const i_occurrence & get_parameter_occurrence(const std::string & parameter_name_) const;
135 
137  virtual void tree_dump(std::ostream & out_ = std::clog,
138  const std::string & title_ = "",
139  const std::string & indent_ = "",
140  bool inherit_ = false) const;
141 
143  enum rst_flags {
145  };
146 
148  void print_rst(std::ostream & out_,
149  const std::string & indent_ = "",
150  uint32_t flags_ = 0) const;
151 
153  bool is_initialized() const;
154 
156  void initialize(const properties & config_, model_item_dict_type & items_);
157 
159  void initialize_standalone(const properties & config_);
160 
162  void initialize_simple();
163 
165  void reset();
166 
168  const parameter_dict_type & get_parameters() const;
169 
172 
173  protected:
174 
176  void _set_default();
177 
178  private:
179 
180  bool _initialized_;
181  std::string _documentation_;
182  parameter_dict_type _parameters_;
183 
184  };
185 
186  } // end of namespace configuration
187 
188 } // end of namespace datatools
189 
190 // OCD support:
191 #include <datatools/ocd_macros.h>
192 
196 
197 #endif // DATATOOLS_CONFIGURATION_VARIANT_MODEL_H
198 
199 // Local Variables: --
200 // mode: c++ --
201 // c-file-style: "gnu" --
202 // tab-width: 2 --
203 // End: --
bool is_rank_used(int rank_) const
Check if a rank is already used.
void initialize_simple()
Bare initialization.
Model of a configuration variant.
Definition: variant_model.h:59
void print_rst(std::ostream &out_, const std::string &indent_="", uint32_t flags_=0) const
Print in ReST format.
void initialize_standalone(const properties &config_)
Initialization from properties only.
void set_parameter_rank(const std::string &parameter_name_, int rank_)
Set the rank of a parameter.
void initialize(const properties &config_, model_item_dict_type &items_)
Initialization from properties and a dictionary of configuration items.
Parameter record.
Definition: variant_model.h:68
const parameter_model & get_parameter_model(const std::string &parameter_name_) const
Return a const reference to a parameter.
bool has_parameter_occurrence(const std::string &parameter_name_) const
Check is an occurrence is associated to a given parameter.
virtual bool is_name_valid(const std::string &name_) const
Check if a name is valid.
parameter_physical physical
Definition: variant_model.h:69
An object that describes the way an object of a given class can be configured through properties.
Definition: object_configuration_description.h:234
void set_documentation(const std::string &documentation_)
Set the documentation.
std::map< std::string, model_item > model_item_dict_type
Dictionary of items.
Definition: utils.h:62
bool has_parameter(const std::string &name_) const
Check if a parameter exists.
const i_occurrence & get_parameter_occurrence(const std::string &parameter_name_) const
Return a const reference to the occurrence associated to a given parameter.
void build_list_of_ranked_parameters(std::vector< std::string > &) const
Build list of ranked parameters.
const std::string & get_documentation() const
Return the documentation.
DOCD_CLASS_DECLARATION(my::algo)
Declaration of the OCD support for the my::algo class.
void _set_default()
Set default values.
const std::string & get_parameter_description(const std::string &parameter_name_) const
Return a description string associated to a given parameter.
const parameter_dict_type & get_parameters() const
Return the dictionary of children parameters.
std::string description
Definition: variant_model.h:70
Physical parameter physical.
Definition: parameter_physical.h:53
static void init_ocd(datatools::object_configuration_description &)
OCD support.
std::map< std::string, parameter_record > parameter_dict_type
Dictionary of parameter physicals.
Definition: variant_model.h:76
bool has_documentation() const
Check if the documentation is empty.
rst_flags
ReST formating flags.
Definition: variant_model.h:143
int get_parameter_rank(const std::string &parameter_name_) const
Return the rank of a parameter.
void add_parameter(const std::string &parameter_name_, const pm_handle_type &parameter_model_handle_, const std::string &description_="", const std::string &occurence_def_="", int rank_=-1)
Add a new parameter.
pm_handle_type get_parameter_model_handle(const std::string &parameter_name_) const
Return a parameter model handle associated to a given parameter.
The Bayeux/datatools library top-level namespace.
Definition: algo.h:13
bool is_initialized() const
Check initialization status.
Abstract interface for all occurrence objects.
Definition: i_occurrence.h:48
A base class with useful attributes usable in many contexts.
Definition: enriched_base.h:52
void remove_parameter(const std::string &parameter_name_)
Remove parameter.
static const uint32_t bit00
Definition: bit_mask.h:27
bool is_ranked_parameter(const std::string &parameter_name_) const
Check ranked parameter.
virtual void tree_dump(std::ostream &out_=std::clog, const std::string &title_="", const std::string &indent_="", bool inherit_=false) const
Smart print.
Description/model of a configuration parameter.
Definition: parameter_model.h:60
A dictionary of arbitrary properties.
Definition: properties.h:125