Bayeux  3.4.1
Core Foundation library for SuperNEMO
library_info.h
Go to the documentation of this file.
1 /* Author(s): Francois Mauger <mauger@lpccaen.in2p3.fr>
3  * Creation date: 2013-09-16
4  * Last modified: 2013-09-26
5  *
6  * License:
7  *
8  * Copyright (C) 2013 Francois Mauger <mauger@lpccaen.in2p3.fr>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 3 of the License, or (at
13  * your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor,
23  * Boston, MA 02110-1301, USA.
24  *
25  * Description:
26  *
27  * Some tools to register static and/or dynamic informations about libraries.
28  *
29  */
30 
31 #ifndef DATATOOLS_LIBRARY_INFO_H
32 #define DATATOOLS_LIBRARY_INFO_H
33 
34 // Standard library:
35 #include <iostream>
36 #include <string>
37 #include <vector>
38 #include <set>
39 
40 // This project:
41 #include <datatools/logger.h>
43 #include <datatools/i_tree_dump.h>
44 
45 namespace datatools {
46 
47  class multi_properties;
48  class properties;
49 
52  : public i_tree_dumpable
53  {
54 
55  public:
57  struct keys {
58  static const std::string & lib_label();
59  static const std::string & exec_label();
60  static const std::string & resource_label();
61  static const std::string & name();
62  static const std::string & libname();
63  static const std::string & description();
64  static const std::string & urn();
65  static const std::string & url();
66  static const std::string & authors();
67  static const std::string & copyright();
68  static const std::string & version();
69  static const std::string & version_major();
70  static const std::string & version_minor();
71  static const std::string & version_patch();
72  static const std::string & build_type();
73  static const std::string & modules();
74  static const std::string & install_prefix();
75  static const std::string & install_include_dir();
76  static const std::string & install_lib_dir();
77  static const std::string & install_bin_dir();
78  static const std::string & install_data_dir();
79  static const std::string & install_resource_dir();
80  static const std::string & install_plugin_lib_dir();
81  static const std::string & install_doc_dir();
82  static const std::string & env_prefix();
83  static const std::string & env_include_dir();
84  static const std::string & env_lib_dir();
85  static const std::string & env_bin_dir();
86  static const std::string & env_data_dir();
87  static const std::string & env_resource_dir();
88  static const std::string & env_plugin_lib_dir();
89  static const std::string & env_doc_dir();
90  };
91 
92  // Set of supported topic labels
93  static const std::set<std::string> & topic_labels();
94 
95  // Default topic label ("resources");
96  static std::string default_topic_label();
97 
98  // Convert
99  static std::string topic_label_to_install_key(const std::string & label_);
100 
101  // Convert
102  static std::string topic_label_to_env_key(const std::string & label_);
103 
105  library_info();
106 
108  virtual ~library_info();
109 
112 
115 
117  void names(std::vector<std::string> &) const;
118 
120  void aliases(std::vector<std::string> &) const;
121 
123  void add_alias(const std::string & library_alias_,
124  const std::string & library_name_);
125 
127  void remove_alias(const std::string & library_alias_);
128 
150  static bool parse_path_registration_directive(const std::string & rule_,
151  std::string & library_name_,
152  std::string & topic_,
153  std::string & path_,
154  std::string & error_msg_);
155 
161  bool resolve_path(const std::string & path_,
162  std::string & resolved_path_,
163  std::string & error_msg_) const;
164 
166  void path_registration(const std::string & library_name_,
167  const std::string & topic_,
168  const std::string & path_,
169  bool overwrite_ = false);
170 
172  void path_unregistration(const std::string & library_name_,
173  const std::string & topic_);
174 
176  properties & registration(const std::string & library_name_,
177  const std::string & library_desc_ = "",
178  const std::string & library_version_ = "",
179  const std::string & install_prefix_ = "",
180  const std::string & install_lib_path_ = "",
181  const std::string & install_resource_path_ = "");
182 
184  void unregistration(const std::string & library_name_);
185 
187  bool has(const std::string & library_key_) const;
188 
190  bool is_library(const std::string & library_name_) const;
191 
193  bool is_alias(const std::string & library_key_) const;
194 
196  std::string resolve(const std::string & library_key_,
197  bool check_ = false) const;
198 
200  void update(const std::string & library_name_,
201  const std::string & info_key_,
202  const std::string & info_value_,
203  const std::string & info_type_ = "",
204  bool locked_ = true);
205 
207  void erase(const std::string & library_name_,
208  const std::string & info_key_);
209 
211  void clear();
212 
214  void print(const std::string & library_name_,
215  std::ostream & out_ = std::clog) const;
216 
218  void initialize();
219 
221  void reset();
222 
224  bool is_initialized();
225 
227  const properties & get(const std::string & library_key_) const;
228 
230  properties & grab(const std::string & library_key_);
231 
233  void tree_dump(std::ostream & out_ = std::clog,
234  const std::string & title_ = "",
235  const std::string & indent_ = "",
236  bool inherit_ = false) const;
237 
238  private:
239 
240  // Management:
241  bool _initialized_;
242  logger::priority _logging_;
243 
244  // Working data:
246  std::map<std::string,std::string> _db_aliases_;
247 
248  };
249 
250 } // end of namespace datatools
251 
252 #endif // DATATOOLS_LIBRARY_INFO_H
253 
254 // Local Variables: --
255 // mode: c++ --
256 // c-file-style: "gnu" --
257 // tab-width: 2 --
258 // End: --
static const std::string & libname()
static const std::string & env_plugin_lib_dir()
bool resolve_path(const std::string &path_, std::string &resolved_path_, std::string &error_msg_) const
priority
Priority levels for logging from most to least critical.
Definition: logger.h:82
void aliases(std::vector< std::string > &) const
Build a list of currently defined library aliases.
A container of mapped properties objects.
Definition: multi_properties.h:99
void names(std::vector< std::string > &) const
Build a list of currently registered library names.
static const std::string & install_bin_dir()
static const std::string & install_doc_dir()
void add_alias(const std::string &library_alias_, const std::string &library_name_)
Add alias.
bool is_alias(const std::string &library_key_) const
Check if an alias is defined.
static const std::string & name()
static const std::string & version_major()
void print(const std::string &library_name_, std::ostream &out_=std::clog) const
Print the library infos from the register.
static const std::set< std::string > & topic_labels()
bool is_initialized()
Check the library info register initialization status.
An interface with utilities for printable objects.
Definition: i_tree_dump.h:36
static const std::string & authors()
Host a register of static and/or dynamic informations about libraries or software components.
Definition: library_info.h:51
static const std::string & install_resource_dir()
library_info()
Constructor.
static std::string topic_label_to_install_key(const std::string &label_)
std::string resolve(const std::string &library_key_, bool check_=false) const
Resolve the true name of the library.
static const std::string & build_type()
static const std::string & version_minor()
void unregistration(const std::string &library_name_)
Unregister a given library.
static std::string topic_label_to_env_key(const std::string &label_)
static const std::string & env_resource_dir()
static const std::string & exec_label()
void erase(const std::string &library_name_, const std::string &info_key_)
Erase a library info from the register.
void set_logging(logger::priority)
Set the logging priority of the library info register.
void initialize()
Initialize the library info register.
static std::string default_topic_label()
properties & grab(const std::string &library_key_)
Return a mutable reference to the library infos container.
void clear()
Clear all library infos from the register.
static const std::string & env_doc_dir()
static const std::string & install_data_dir()
static const std::string & urn()
static const std::string & env_prefix()
static const std::string & install_plugin_lib_dir()
static const std::string & resource_label()
static bool parse_path_registration_directive(const std::string &rule_, std::string &library_name_, std::string &topic_, std::string &path_, std::string &error_msg_)
void update(const std::string &library_name_, const std::string &info_key_, const std::string &info_value_, const std::string &info_type_="", bool locked_=true)
Update.
void path_registration(const std::string &library_name_, const std::string &topic_, const std::string &path_, bool overwrite_=false)
Register a path associated to a library/app name.
static const std::string & env_bin_dir()
static const std::string & version_patch()
static const std::string & env_lib_dir()
void remove_alias(const std::string &library_alias_)
Remove alias.
static const std::string & install_include_dir()
static const std::string & modules()
static const std::string & install_prefix()
static const std::string & env_data_dir()
void reset()
Terminate the library info register.
Library/software component description property keys.
Definition: library_info.h:57
The Bayeux/datatools library top-level namespace.
Definition: algo.h:13
static const std::string & install_lib_dir()
Utilities for logging information.
static const std::string & env_include_dir()
bool is_library(const std::string &library_name_) const
Check if a given library exist (by name)
static const std::string & url()
static const std::string & lib_label()
static const std::string & description()
static const std::string & version()
virtual ~library_info()
Destructor.
void tree_dump(std::ostream &out_=std::clog, const std::string &title_="", const std::string &indent_="", bool inherit_=false) const
Smart print.
logger::priority get_logging() const
Return the logging priority of the library info register.
properties & registration(const std::string &library_name_, const std::string &library_desc_="", const std::string &library_version_="", const std::string &install_prefix_="", const std::string &install_lib_path_="", const std::string &install_resource_path_="")
Register basic infos for a given library.
const properties & get(const std::string &library_key_) const
Return a non-mutable reference to the library infos container.
void path_unregistration(const std::string &library_name_, const std::string &topic_)
Unregister a path associated to a library/app name.
bool has(const std::string &library_key_) const
Check if some infos about a given library exist (by name or alias)
static const std::string & copyright()
A dictionary of arbitrary properties.
Definition: properties.h:125