Bayeux  3.4.1
Core Foundation library for SuperNEMO
io.h
Go to the documentation of this file.
1 /* Author(s) : Francois Mauger <mauger@lpccaen.in2p3.fr>
3  * Creation date : 2014-09-29
4  * Last modified : 2017-01-10
5  *
6  * Copyright (C) 2014-2017 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  * I/O utilities for variant registries and repositories.
26  *
27  */
28 
29 #ifndef DATATOOLS_CONFIGURATION_IO_H
30 #define DATATOOLS_CONFIGURATION_IO_H
31 
32 // Standard library:
33 #include <iostream>
34 #include <vector>
35 #include <string>
36 #include <iostream>
37 #include <map>
38 
39 // This project (Bayeux/datatools):
40 #include <datatools/bit_mask.h>
41 #include <datatools/logger.h>
42 #include <datatools/bit_mask.h>
44 #include <datatools/version_id.h>
45 
46 namespace datatools {
47 
48  namespace configuration {
49 
50  // Forward declarations:
51  class variant_record;
52  class variant_registry;
53  class variant_repository;
54 
56  class ascii_io
57  {
58  public:
59 
61  enum store_flags {
68  };
69 
71  static const std::string & unset_label();
72 
74  static const std::string & error_label();
75 
77  static const std::string & format_label();
78 
81 
83  explicit ascii_io(uint32_t flags_ = IO_DEFAULT);
84 
86  void store_record(std::ostream & out_, const variant_record & vrec_) const;
87 
89  int load_record(std::istream & in_, variant_record & vrec_) const;
90 
92  void store_registry(std::ostream & out_, const variant_registry & vreg_) const;
93 
95  int load_registry(std::istream & in_, variant_registry & vreg_) const;
96 
98  void store_repository(std::ostream & out_, const variant_repository & vrep_) const;
99 
101  int load_repository(std::istream & in_, variant_repository & vrep_) const;
102 
105 
108 
110  void print(std::ostream & out_, const std::string & title_ = "") const;
111 
112  private:
113 
114  bool _no_header_;
115  bool _with_description_;
116  bool _with_title_;
117  bool _dont_ignore_unknown_registries_;
118  logger::priority _logging_;
119  datatools::version_id _format_version_;
120 
121  };
122 
125  {
126  public:
127  typedef std::map<std::string, std::size_t> statistics_type;
128 
131 
134 
136  bool has_repository() const;
137 
139  void set_repository(const variant_repository & repository_);
140 
142  void reset_repository();
143 
145  const variant_repository & get_repository() const;
146 
148  void reset();
149 
151  void print_report(std::ostream & out_, uint32_t flags_ = 0) const;
152 
154  void add(const std::string & path_, std::size_t increment_ = 1);
155 
157  void dump(std::ostream & out_ = std::cerr) const;
158 
161 
164 
165  private:
166 
168  void _init_repository_();
169 
170  private:
171 
172  logger::priority _logging_;
173  const variant_repository * _repository_ = nullptr;
174  statistics_type _parameter_stats_;
175 
176  };
177 
180  {
181  public:
182 
184  enum flag_type {
187  };
188 
190  bool is_remove_quotes() const;
191 
193  void set_remove_quotes(bool);
194 
196  variant_preprocessor(unsigned int flags_ = 0);
197 
199  bool has_repository() const;
200 
202  void set_repository(const variant_repository & repository_);
203 
205  void reset_repository();
206 
208  bool repository_is_active() const;
209 
211  const variant_repository & get_repository() const;
212 
214  command::returned_info preprocess(const std::string & source_,
215  std::string & target_) const;
216 
218  std::string preprocess_string(const std::string & source_) const;
219 
221  bool preprocess_boolean(const std::string & source_) const;
222 
224  int preprocess_integer(const std::string & source_) const;
225 
227  double preprocess_real(const std::string & source_) const;
228 
230 
232  void preprocess_args_options(int argc_, char ** argv_,
233  std::vector<std::string> & preprocessed_args_);
234 
236 
238  void preprocess_args_options(const std::vector<std::string> & args_,
239  std::vector<std::string> & preprocessed_args_);
240 
242  command::returned_info preprocess_parameter(const std::string & parameter_token_,
243  std::string & parameter_effective_token_) const;
244 
288  command::returned_info resolve_variant(const std::string & variant_desc_,
289  bool & variant_active_,
290  bool & variant_reverse_) const;
291 
294 
297 
298  private:
299 
301  void _set_default_kernel_repository();
302 
303  private:
304 
305  logger::priority _logging_;
306  bool _remove_quotes_ = false;
307  const variant_repository * _repository_ = nullptr;
308 
309  };
310 
311  } // end of namespace configuration
312 
313 } // end of namespace datatools
314 
315 #endif // DATATOOLS_CONFIGURATION_IO_H
316 
317 // Local Variables: --
318 // mode: c++ --
319 // c-file-style: "gnu" --
320 // tab-width: 2 --
321 // End: --
logger::priority get_logging() const
Return the logging priority.
void store_repository(std::ostream &out_, const variant_repository &vrep_) const
Store a variant repository.
void set_remove_quotes(bool)
Set the remove quotes flag.
logger::priority get_logging() const
Return the logging priority.
bool has_repository() const
Check if a variant configuration repository is used.
const variant_repository & get_repository() const
Get the variant configuration repository.
int load_repository(std::istream &in_, variant_repository &vrep_) const
Load a variant repository.
Registry of configuration variant parameters and associated variants.
Definition: variant_registry.h:53
priority
Priority levels for logging from most to least critical.
Definition: logger.h:82
double preprocess_real(const std::string &source_) const
Process a source string into a target double.
int load_record(std::istream &in_, variant_record &vrec_) const
Load a variant registry record.
command::returned_info preprocess(const std::string &source_, std::string &target_) const
Process a source string into a target string.
bool repository_is_active() const
Check if the variant configuration repository is active.
void store_record(std::ostream &out_, const variant_record &vrec_) const
Store a variant registry record.
static const uint32_t bit01
Definition: bit_mask.h:28
logger::priority get_logging() const
Return the logging priority.
void set_logging(logger::priority)
Set the logging priority.
static const uint32_t bit03
Definition: bit_mask.h:30
Print title comment.
Definition: io.h:63
void set_logging(logger::priority)
Set the logging priority.
variant_preprocessor(unsigned int flags_=0)
Default constructor.
static const uint32_t bit04
Definition: bit_mask.h:31
std::map< std::string, std::size_t > statistics_type
Definition: io.h:127
Do not print header.
Definition: io.h:65
static const std::string & unset_label()
Return unset parameter label.
void store_registry(std::ostream &out_, const variant_registry &vreg_) const
Store a variant registry.
Command returned information.
Definition: command_utils.h:78
const variant_repository & get_repository() const
Get the variant configuration repository.
ascii_io(uint32_t flags_=IO_DEFAULT)
Default constructor.
void set_logging(logger::priority)
Set the logging priority.
store_flags
Special initialization flags for the ASCII I/O utility.
Definition: io.h:61
command::returned_info resolve_variant(const std::string &variant_desc_, bool &variant_active_, bool &variant_reverse_) const
void reset_repository()
Reset the variant configuration repository.
int preprocess_integer(const std::string &source_) const
Process a source string into a target integer.
void print_report(std::ostream &out_, uint32_t flags_=0) const
Print the statistic report.
int load_registry(std::istream &in_, variant_registry &vreg_) const
Load a variant registry.
void reset_repository()
Reset the variant configuration repository.
bool has_repository() const
Check if a variant configuration repository is used.
static const uint32_t bit02
Definition: bit_mask.h:29
variant processing reporting
Definition: io.h:124
bool is_remove_quotes() const
Check the remove quotes flag.
void preprocess_args_options(int argc_, char **argv_, std::vector< std::string > &preprocessed_args_)
Process a list of arguments and options.
Print meta comment.
Definition: io.h:62
static const std::string & format_label()
Return format label.
bool preprocess_boolean(const std::string &source_) const
Process a source string into a target boolean.
void set_repository(const variant_repository &repository_)
Set the variant configuration repository.
flag_type
Construction flags.
Definition: io.h:184
The Bayeux/datatools library top-level namespace.
Definition: algo.h:13
Utilities for logging information.
Flag to print trace messages.
Definition: io.h:185
Default flags.
Definition: io.h:67
void print(std::ostream &out_, const std::string &title_="") const
Print.
void set_repository(const variant_repository &repository_)
Set the variant configuration repository.
static version_id current_format_version_id()
Return the current format version identifier.
Flag to remove quotes around string parameters.
Definition: io.h:186
static const uint32_t bit00
Definition: bit_mask.h:27
Variant registry record node.
Definition: variant_record.h:52
Do not load unknown registries from profile.
Definition: io.h:66
command::returned_info preprocess_parameter(const std::string &parameter_token_, std::string &parameter_effective_token_) const
Process a source string into a target string as a variant parameter.
std::string preprocess_string(const std::string &source_) const
Process a source string into a target string.
void add(const std::string &path_, std::size_t increment_=1)
Increment the counter associated to a processed variant parameter.
A class representing a version ID :
Definition: version_id.h:67
void dump(std::ostream &out_=std::cerr) const
Print.
Variant repository.
Definition: variant_repository.h:57
static const std::string & error_label()
Return error parameter label.
Trace/debug mode.
Definition: io.h:64
Configuration variant string preprocessor.
Definition: io.h:179
ASCII I/O utility for variant repository and registries.
Definition: io.h:56