Bayeux  3.4.1
Core Foundation library for SuperNEMO
base_io.h
Go to the documentation of this file.
1 /* Author(s) : Francois Mauger <mauger@lpccaen.in2p3.fr>
3  * Creation date: 2010-11-03
4  * Last modified: 2012-12-20
5  *
6  * License: GPL3
7  *
8  * Description:
9  *
10  * A brio reader/writer base class
11  *
12  */
13 
14 #ifndef BRIO_DETAIL_BASE_IO_H
15 #define BRIO_DETAIL_BASE_IO_H 1
16 
17 // Standard Library:
18 #include <string>
19 #include <list>
20 #include <locale>
21 
22 // Third Party:
23 // - Boost:
24 #include <boost/math/special_functions/nonfinite_num_facets.hpp>
25 
26 // - Bayeux/datatools:
28 #include <datatools/i_tree_dump.h>
29 #include <datatools/logger.h>
30 
31 // This Project:
32 #include <brio/utils.h>
33 
34 class TFile;
35 
37 namespace brio {
38 
40  namespace detail {
41 
43  class base_io
45  {
46  public:
47  static const std::string & pba_label();
48  static const std::string & text_label();
49 
50  enum format_type {
52  FORMAT_PBA = 1,
54  };
55 
56  enum rw_type {
58  RW_READ = 1,
59  RW_WRITE = 2
60  };
61 
62  public:
63 
64  base_io(int rw_);
65 
67 
68  base_io(int rw_, int format_, datatools::logger::priority p_);
69 
70  virtual ~base_io();
71 
73  virtual void open(const std::string & filename_);
74 
76  virtual void close();
77 
78  virtual bool is_opened() const;
79 
80  bool is_reading() const;
81 
82  bool is_writing() const;
83 
84  bool is_format_pba() const;
85 
86  bool is_format_text() const;
87 
88  int get_format() const;
89 
90  void set_format(int format_);
91 
92  void set_format(const std::string & format_str_);
93 
94  static int get_format (const std::string & format_str_);
95 
96  bool is_debug() const;
97 
98  void set_debug(bool);
99 
100  bool is_verbose() const;
101 
102  void set_verbose(bool);
103 
104  int64_t get_number_of_entries(const std::string & label_ = "") const;
105 
106  int64_t get_current_entry(const std::string & label_ = "") const;
107 
108  const std::string & get_serialization_tag(const std::string & label_ = "") const;
109 
110  bool has_store(const std::string & label_) const;
111 
112  bool has_store_with_serial_tag(const std::string & label_,
113  const std::string & serial_tag_) const;
114 
115  template <class T>
116  bool has_store_with_matching_serial_tag(const std::string & label_) const;
117 
118  bool has_mixed_store(const std::string & label_) const;
119 
120  void select_store(const std::string & label_);
121 
122  bool has_automatic_store() const;
123 
124  void select_automatic_store();
125 
126  void unselect_store();
127 
128  void get_list_of_stores(std::list<std::string> & list_) const;
129 
130  virtual void tree_dump(std::ostream & out_ = std::clog,
131  const std::string & title_ = "",
132  const std::string & indent_ = "",
133  bool inherit_ = false) const;
134 
135  void reset();
136 
138 
140 
141  protected:
142  virtual void _at_open(const std::string & filename_) = 0;
143 
144  void _set_default();
145 
146  void _reset();
147 
148  store_info * _get_store_info(const std::string & label_ = "");
149 
150  const store_info * _get_store_info(const std::string & label_ = "") const;
151 
152  protected:
153  std::string _filename;
154  TFile * _file;
157  int _rw;
158  std::locale * _default_locale;
159  std::locale * _locale;
160 
161  private:
162  datatools::logger::priority _logging_priority_;
163  int _format_;
164  };
165 
166  //----------------------------------------------------------------------
167  // Template function definitions
168  //
169  template <class T>
170  bool base_io::has_store_with_matching_serial_tag(const std::string & label_) const
171  {
172  store_info_dict_type::const_iterator found = _store_infos.find(label_);
173  if (found == _store_infos.end()) return false;
174  const store_info& the_si = found->second;
175  if (the_si.has_dedicated_serialization_tag()) {
176  return datatools::check_serial_tag<T>(the_si.get_serialization_tag());
177  }
178  return false;
179  }
180 
181  } // end of namespace detail
182 
183 } // end of namespace brio
184 
185 #endif // BRIO_DETAIL_BASE_IO_H
186 
187 // Local Variables: --
188 // mode: c++ --
189 // c-file-style: "gnu" --
190 // tab-width: 2 --
191 // End: --
bool is_debug() const
void set_logging_priority(datatools::logger::priority)
store_info * _get_store_info(const std::string &label_="")
virtual void tree_dump(std::ostream &out_=std::clog, const std::string &title_="", const std::string &indent_="", bool inherit_=false) const
Main old interface method for printing.
const std::string & get_serialization_tag() const
bool is_verbose() const
priority
Priority levels for logging from most to least critical.
Definition: logger.h:82
bool is_reading() const
Definition: base_io.h:58
int _rw
Read/write mode tag.
Definition: base_io.h:157
An interface with utilities for printable objects.
Definition: i_tree_dump.h:36
virtual void close()
File close.
A class that contains internal dynamic informations for a given store.
Definition: utils.h:33
bool has_automatic_store() const
store_info_dict_type _store_infos
Dictionnary of stores.
Definition: base_io.h:155
datatools::logger::priority get_logging_priority() const
Boost portable binary archive (file extension: .brio)
Definition: base_io.h:53
The internal I/O base class.
Definition: base_io.h:43
std::locale * _default_locale
Default I/O locale (for portable streams)
Definition: base_io.h:158
virtual bool is_opened() const
store_info * _current_store
Handle to the current active store (if any)
Definition: base_io.h:156
std::map< std::string, store_info > store_info_dict_type
Definition: utils.h:87
bool has_mixed_store(const std::string &label_) const
bool has_store_with_serial_tag(const std::string &label_, const std::string &serial_tag_) const
static const std::string & text_label()
Label for Boost portable binary archive.
bool has_store_with_matching_serial_tag(const std::string &label_) const
Definition: base_io.h:170
bool is_format_pba() const
rw_type
Definition: base_io.h:56
const std::string & get_serialization_tag(const std::string &label_="") const
int get_format() const
void select_store(const std::string &label_)
void set_format(int format_)
bool has_dedicated_serialization_tag() const
bool has_store(const std::string &label_) const
Definition: base_io.h:52
Reader mode.
Definition: base_io.h:59
std::string _filename
Name of the current I/O file (extensions are .brio or .trio)
Definition: base_io.h:153
Utilities for logging information.
Definition: base_io.h:57
static const std::string & pba_label()
format_type
Label for Boost portable text archive.
Definition: base_io.h:50
virtual void _at_open(const std::string &filename_)=0
void get_list_of_stores(std::list< std::string > &list_) const
virtual void open(const std::string &filename_)
File open.
std::locale * _locale
I/O locale (for portable streams)
Definition: base_io.h:159
TFile * _file
Handle to the current embedded ROOT file.
Definition: base_io.h:154
int64_t get_number_of_entries(const std::string &label_="") const
int64_t get_current_entry(const std::string &label_="") const
bool is_writing() const
bool is_format_text() const
Top-level namespace of the Bayeux/brio module library.
Definition: base_io.h:37