Bayeux  3.4.1
Core Foundation library for SuperNEMO
id_mgr.h
Go to the documentation of this file.
1 /* Author(s) : Francois Mauger <mauger@lpccaen.in2p3.fr>
3  * Creation date: 2010-03-14
4  * Last modified: 2016-07-04
5  *
6  * License:
7  *
8  * Description:
9  *
10  * Geometry ID manager
11  *
12  */
13 
14 #ifndef GEOMTOOLS_ID_MGR_H
15 #define GEOMTOOLS_ID_MGR_H 1
16 
17 // Standard library:
18 #include <string>
19 #include <vector>
20 #include <map>
21 
22 // Third party:
23 // - Bayeux/datatools:
24 #include <datatools/utils.h>
25 #include <datatools/logger.h>
27 
28 // This project:
29 #include <geomtools/geom_id.h>
30 
31 namespace geomtools {
32 
37  class id_mgr
39  {
40 
41  public:
42 
43  static const std::string & category_key_label();
44  static const std::string & type_meta_label();
45  static const std::string & default_world_category();
46  static const std::string & default_plain_category();
47  static const std::string & plain_item_address();
48  static const uint32_t WORD_TYPE = 0;
49  static const uint32_t PLAIN_TYPE = 1;
50 
60  {
61 
62  public:
63 
65  bool has_subaddress(const std::string & a_label, int a_count = 1) const;
66 
68  int get_subaddress_index(const std::string & a_label, int a_count = 1) const;
69 
71  bool is_valid() const;
72 
73  // Check if the category is final (cannot be inherited)
74  bool is_final_category() const;
75 
76  // Set the final category flag
77  void set_final_category(bool);
78 
79  // Set the category name
80  void set_category(const std::string & cat_);
81 
83  const std::string & get_category() const;
84 
86  bool has_ancestor(const std::string & cat_) const;
87 
89  void add_ancestor(const std::string & cat_);
90 
92  void add_address(const std::string & address_);
93 
95  void add_extends_by(const std::string & by_);
96 
98  bool has_group() const;
99 
101  void set_group(const std::string &);
102 
104  const std::string & get_group() const;
105 
107  void set_type(uint32_t);
108 
110  uint32_t get_type() const;
111 
113  const std::string & get_inherits() const;
114 
116  void set_inherits(const std::string &);
117 
119  bool is_inherited() const;
120 
122  bool is_extension() const;
123 
125  void set_extends(const std::string &);
126 
128  const std::string & get_extends() const;
129 
130  void set_ancestors(const std::vector<std::string> &);
131 
132  const std::vector<std::string> & get_ancestors() const;
133 
134  void set_extends_by(const std::vector<std::string> &);
135 
136  const std::vector<std::string> & get_extends_by() const;
137 
138  void set_addresses(const std::vector<std::string> &);
139 
140  const std::vector<std::string> & get_addresses() const;
141 
143  category_info();
144 
146  virtual ~category_info();
147 
149  size_t get_depth() const;
150 
152  size_t get_by_depth() const;
153 
155  void create(geom_id & id_) const;
156 
158  void dump(std::ostream & = std::clog) const;
159 
172  virtual void print_tree(std::ostream & out_ = std::clog,
173  const boost::property_tree::ptree & options_ = datatools::i_tree_dumpable::empty_options()) const;
174 
176  bool is_locked() const;
177 
179  void lock();
180 
182  void reset();
183 
184  private:
185  bool _locked_;
186  std::string _category_;
187  uint32_t _type_;
188  std::string _group_;
189  std::string _inherits_;
190  std::string _extends_;
191  bool _final_category_;
192  std::vector<std::string> _ancestors_;
193  std::vector<std::string> _extends_by_;
194  std::vector<std::string> _addresses_;
195  std::vector<int> _nbits_;
196 
197  };
198 
199  /***************************************/
200 
201  typedef std::map<std::string, category_info> categories_by_name_col_type;
202  typedef std::map<int, const category_info *> categories_by_type_col_type;
203 
204  public:
205 
206  bool is_debug() const;
207 
208  void set_debug(bool);
209 
211 
213 
215  id_mgr();
216 
218  virtual ~id_mgr();
219 
220  void set_force_world(bool);
221 
222  bool is_force_world() const;
223 
224  void set_force_plain(bool);
225 
226  bool is_force_plain() const;
227 
229  void set_world_category(const std::string & n_);
230 
232  const std::string & get_world_category() const;
233 
235  void set_plain_category(const std::string & n_);
236 
238  const std::string & get_plain_category() const;
239 
241  void init_from(const datatools::multi_properties & mp_);
242 
244  void load(const std::string & filename_);
245 
246  // /// Smart print
247  // virtual void tree_dump(std::ostream & out_ = std::clog,
248  // const std::string & title_ = "",
249  // const std::string & indent_ = "",
250  // bool inherit_ = false) const;
251 
253  virtual void print_tree(std::ostream & out_ = std::clog,
254  const boost::property_tree::ptree & options_ = datatools::i_tree_dumpable::empty_options()) const;
255 
257  bool has_category_info(int type_) const;
258 
260  bool has_category_info(const std::string &) const;
261 
263  const category_info & get_category_info(int type_) const;
264 
266  const category_info & get_category_info(const std::string &) const;
267 
269  bool is_category(const geom_id & id_, const std::string & category_) const;
270 
272  bool inherits(const geom_id & id_, const std::string & category_) const;
273 
275  bool has(const geom_id &, const std::string & what_) const;
276 
278  const std::string & get_category(const geom_id &) const;
279 
281  uint32_t get_category_type(const std::string & a_category) const;
282 
284  int get(const geom_id &, const std::string & what_) const;
285 
287  void set(geom_id &, const std::string & what_, uint32_t value_) const;
288 
290  bool check_inheritance(const geom_id & mother_id_,
291  const geom_id & id_) const;
292 
296  void extract(const geom_id & child_id_, geom_id & mother_id_) const;
297 
299  bool validate_id(const geom_id & id_) const;
300 
302  void id_to_human_readable_format_string(const geom_id & id_, std::string &) const;
303 
305  std::string id_to_human_readable_format_string(const geom_id & id_) const;
306 
308  void make_id(geom_id & id_,
309  uint32_t address_) const;
310 
312  void make_id(const std::string & category_, geom_id & id_) const;
313 
315  int print_list_of_categories(const std::string & command_,
316  const std::vector<std::string> & argv_,
317  std::ostream & out_ = std::clog) const;
318 
319  /*
320  void make_extended(const geom_id & mother_id_,
321  geom_id & id_,
322  uint32_t address_) const;
323  */
324 
337  int compute_id_from_info(geom_id & id_,
338  const geom_id & mother_id_,
339  const std::string & id_info_,
340  const std::vector<uint32_t> & items_index_) const;
341 
342  int compute_id_from_info(geom_id & id_,
343  const geom_id & mother_id_,
344  const std::string & id_info_,
345  uint32_t nitem0_ = geom_id::INVALID_ADDRESS,
346  uint32_t nitem1_ = geom_id::INVALID_ADDRESS,
347  uint32_t nitem2_ = geom_id::INVALID_ADDRESS) const;
348 
350 
352 
354  bool is_initialized() const;
355 
357  void initialize(const datatools::properties & config_);
358 
360  void reset();
361 
362  protected:
363 
364  virtual void _at_initialize();
365 
366  private:
367 
368  // Management;
369  datatools::logger::priority _logging_priority_;
370  bool _initialized_;
371 
372  // Configuration:
373  bool _force_world_;
374  bool _force_plain_;
375  std::string _world_category_;
376  std::string _plain_category_;
377  std::vector<std::string> _categories_lists_;
378 
379  // Working data:
380  categories_by_name_col_type _categories_by_name_;
381  categories_by_type_col_type _categories_by_type_;
382 
383  };
384 
385 } // end of namespace geomtools
386 
387 /***************
388  * OCD support *
389  ***************/
390 #include <datatools/ocd_macros.h>
392 
393 #endif // GEOMTOOLS_ID_MGR_H
394 
395 /*
396 ** Local Variables: --
397 ** mode: c++ --
398 ** c-file-style: "gnu" --
399 ** tab-width: 2 --
400 ** End: --
401 */
static const boost::property_tree::ptree & empty_options()
void set_force_plain(bool)
priority
Priority levels for logging from most to least critical.
Definition: logger.h:82
A container of mapped properties objects.
Definition: multi_properties.h:99
virtual ~category_info()
Destructor.
void set_ancestors(const std::vector< std::string > &)
const std::string & get_category() const
Get the name of the category.
void dump(std::ostream &=std::clog) const
Default print.
void add_address(const std::string &address_)
Add an address.
int print_list_of_categories(const std::string &command_, const std::vector< std::string > &argv_, std::ostream &out_=std::clog) const
Print the list of categories.
void set_type(uint32_t)
Set the type.
const std::vector< std::string > & get_addresses() const
bool has_ancestor(const std::string &cat_) const
Check if ancestor with a given category name exists.
uint32_t get_type() const
Get the type.
const std::string & get_plain_category() const
Return the plain category name.
An interface with utilities for printable objects.
Definition: i_tree_dump.h:36
const std::vector< std::string > & get_ancestors() const
static const std::string & default_plain_category()
void extract(const geom_id &child_id_, geom_id &mother_id_) const
bool is_extension() const
Check if the category extends another one.
void set_addresses(const std::vector< std::string > &)
id_mgr()
Constructor.
static const std::string & default_world_category()
bool validate_id(const geom_id &id_) const
Check if a given ID is valid and managed.
bool has(const geom_id &, const std::string &what_) const
Check is an ID has an subaddress labelled 'what':
bool is_debug() const
bool is_force_plain() const
virtual void print_tree(std::ostream &out_=std::clog, const boost::property_tree::ptree &options_=datatools::i_tree_dumpable::empty_options()) const
Smart print.
bool is_initialized() const
Check lock status.
int get(const geom_id &, const std::string &what_) const
Returns the value of the address labelled 'what' from an ID.
bool is_valid() const
Check if the category data are valid.
void reset()
Reset the category.
uint32_t get_category_type(const std::string &a_category) const
Return the type associated to a category.
bool has_subaddress(const std::string &a_label, int a_count=1) const
Check if a subaddress with a given label exists at given occurence.
static const uint32_t WORD_TYPE
Definition: id_mgr.h:48
void set_group(const std::string &)
Set the group.
void initialize(const datatools::properties &config_)
Initialize the manager from a properties container.
bool has_category_info(int type_) const
Check if some category's description exists for a given type.
int compute_id_from_info(geom_id &id_, const geom_id &mother_id_, const std::string &id_info_, const std::vector< uint32_t > &items_index_) const
static const std::string & plain_item_address()
const std::vector< std::string > & get_extends_by() const
static const std::string & type_meta_label()
void set_force_world(bool)
virtual ~id_mgr()
Destructor.
bool is_locked() const
Check lock status.
const std::string & get_extends() const
Get the name of the extended category (if any)
void lock()
Lock the category.
DOCD_CLASS_DECLARATION(my::algo)
Declaration of the OCD support for the my::algo class.
const std::string & get_inherits() const
Get the name of the parent category (if any)
void add_extends_by(const std::string &by_)
Add an extends by.
Definition: id_mgr.h:37
void set_world_category(const std::string &n_)
Set the world category name.
void create(geom_id &id_) const
Create a geom ID with the proper type and depth following the description of the category.
const std::string & get_world_category() const
Return the world category name.
datatools::logger::priority get_logging_priority() const
size_t get_depth() const
Returns the size of the list of addresses.
void set_extends_by(const std::vector< std::string > &)
const category_info & get_category_info(int type_) const
Get the category descriptor assocated to a category associated to a given type.
static const uint32_t INVALID_ADDRESS
Definition: geom_id.h:46
const std::string & get_category(const geom_id &) const
Returns the category associated to an ID.
std::map< std::string, category_info > categories_by_name_col_type
Definition: id_mgr.h:201
bool inherits(const geom_id &id_, const std::string &category_) const
Check if an ID inherits a category.
void set_plain_category(const std::string &n_)
Set the plain category name.
void set_extends(const std::string &)
Set the extended parent category.
const std::string & get_group() const
Return the group.
void set_logging_priority(datatools::logger::priority)
static const std::string & category_key_label()
void add_ancestor(const std::string &cat_)
Add an ancestor with a given category name dexists.
bool is_category(const geom_id &id_, const std::string &category_) const
Check the category of an ID.
const categories_by_type_col_type & categories_by_type() const
void make_id(geom_id &id_, uint32_t address_) const
Factory method that ... (I don't know what for !!!)
void reset()
Reset/invalidate the manager.
virtual void print_tree(std::ostream &out_=std::clog, const boost::property_tree::ptree &options_=datatools::i_tree_dumpable::empty_options()) const
void set_category(const std::string &cat_)
Utilities for logging information.
bool check_inheritance(const geom_id &mother_id_, const geom_id &id_) const
Check if an ID inherits or extends a candidate mother ID.
bool has_group() const
Check if a group is defined.
Definition: geom_id.h:41
int get_subaddress_index(const std::string &a_label, int a_count=1) const
Fetch the subaddress associated to a given label at given occurence.
void set(geom_id &, const std::string &what_, uint32_t value_) const
Set the value of the address labelled 'what' from an ID.
Definition: id_mgr.h:58
size_t get_by_depth() const
Returns the size of the list of extending addresses.
std::map< int, const category_info * > categories_by_type_col_type
Definition: id_mgr.h:202
static const uint32_t PLAIN_TYPE
Definition: id_mgr.h:49
virtual void _at_initialize()
bool is_force_world() const
bool is_inherited() const
Check if a parent category exists.
void init_from(const datatools::multi_properties &mp_)
Initialize the manager from a properties multi container.
const categories_by_name_col_type & categories_by_name() const
void set_debug(bool)
void load(const std::string &filename_)
Load manager configuration from a file.
void set_inherits(const std::string &)
Set the inherited parent category.
void id_to_human_readable_format_string(const geom_id &id_, std::string &) const
String formatting.
Top-level namespace of the Bayeux/geomtools module library.
Definition: electromagnetic_field_manager.h:39
A dictionary of arbitrary properties.
Definition: properties.h:125