Bayeux  3.4.1
Core Foundation library for SuperNEMO
writer.h
Go to the documentation of this file.
1 /* Author (s) : Francois Mauger <mauger@lpccaen.in2p3.fr>
3  * Creation date: 2010-11-01
4  * Last modified: 2019-05-21
5  *
6  * License: GPL3
7  *
8  * Description:
9  *
10  * A Boost archive to ROOT file writer
11  *
12  */
13 
14 #ifndef BRIO_WRITER_H
15 #define BRIO_WRITER_H 1
16 
17 // Standard Library:
18 #include <stdexcept>
19 #include <iostream>
20 #include <sstream>
21 #include <string>
22 
23 // Third Party:
24 // - Boost:
25 #include <boost/iostreams/stream.hpp>
26 #include <boost/iostreams/device/back_inserter.hpp>
27 #include <boost/filesystem.hpp>
28 
29 #ifdef __clang__
30 #pragma clang diagnostic push
31 #pragma clang diagnostic ignored "-Wunused-parameter"
32 #endif
33 #include <boost/archive/text_oarchive.hpp>
34 #ifdef __clang__
35 #pragma clang diagnostic pop
36 #endif
37 
38 // - Bayeux/datatools:
40 #include <datatools/logger.h>
41 #include <datatools/exception.h>
42 
43 // This Project:
44 #include <brio/detail/base_io.h>
45 
46 namespace brio {
47 
49  class writer
50  : public detail::base_io
51  {
52  public:
54  writer();
55 
57  writer(const std::string & filename_,
59 
61  writer(const std::string & filename_,
62  const std::string & format_str_,
64 
66  virtual ~writer();
67 
69  void lock();
70 
72  void unlock();
73 
75  bool is_locked() const;
76 
78  bool is_allow_mixed_types_in_stores() const;
79 
81  bool is_allow_automatic_store() const;
82 
84  bool is_existing_file_protected() const;
85 
92  void set_allow_mixed_types_in_stores(bool new_value_ = true);
93 
99  void set_allow_automatic_store(bool new_value_ = true);
100 
102  void set_existing_file_protected(bool new_value_ = true);
103 
107  int add_store(const std::string & label_,
108  const std::string & serial_tag_,
109  size_t buffer_size_ = 256000);
110 
114  int add_store(const std::string & label_,
115  size_t buffer_size_ = 256000);
116 
120  int add_mixed_store(const std::string & label_,
121  size_t buffer_size_ = 0);
122 
123  // Store template method
124  template <typename T>
125  int store(const T & data_, const std::string & label_ = "");
126 
128  virtual void tree_dump(std::ostream & out_ = std::clog,
129  const std::string & title_ = "",
130  const std::string & indent_ = "",
131  bool inherit_ = false) const;
132 
134  void print_info(std::ostream & out_ = std::clog) const;
135 
136  protected:
137 
138  void _set_default();
139 
140  store_info * _add_store(const std::string & label_,
141  const std::string & serial_tag_,
142  size_t buffer_size_);
143 
144  template <typename T>
145  int _at_store(const T & dat, store_info * store_info_);
146 
147  virtual void _at_open(const std::string & filename_);
148 
149  private:
150 
151  bool _locked_;
152  bool _allow_mixed_types_in_stores_;
153  bool _allow_automatic_store_;
154  bool _existing_file_protected_;
155  store_info * _automatic_store_ = nullptr;
156 
157  };
158 
159 } // end of namespace brio
160 
161 #include <brio/writer-inl.h>
162 
163 #endif // BRIO_WRITER_H
164 
165 // Local Variables: --
166 // mode: c++ --
167 // c-file-style: "gnu" --
168 // tab-width: 2 --
169 // End: --
store_info * _add_store(const std::string &label_, const std::string &serial_tag_, size_t buffer_size_)
int add_mixed_store(const std::string &label_, size_t buffer_size_=0)
bool is_allow_mixed_types_in_stores() const
Check if mixed types are allowed in any given store.
priority
Priority levels for logging from most to least critical.
Definition: logger.h:82
virtual void tree_dump(std::ostream &out_=std::clog, const std::string &title_="", const std::string &indent_="", bool inherit_=false) const
Smart print.
The brio generic writer class.
Definition: writer.h:49
int add_store(const std::string &label_, const std::string &serial_tag_, size_t buffer_size_=256000)
A fatal error. The application will most likely terminate. This is the highest priority.
Definition: logger.h:85
A class that contains internal dynamic informations for a given store.
Definition: utils.h:33
bool is_allow_automatic_store() const
Check if automatic store is allowed.
void print_info(std::ostream &out_=std::clog) const
Print.
int _at_store(const T &dat, store_info *store_info_)
Definition: writer-inl.h:84
bool is_locked() const
Check if the writer is locked.
void set_allow_mixed_types_in_stores(bool new_value_=true)
The internal I/O base class.
Definition: base_io.h:43
Utility macros for exception handling.
void unlock()
Unlock the writer.
bool is_existing_file_protected() const
Check if protection against file overwriting exists.
writer()
Default constructor.
void lock()
Lock the writer.
Definitions of brio::writer template functions.
virtual ~writer()
Destructor.
void set_allow_automatic_store(bool new_value_=true)
Utilities for logging information.
void _set_default()
void set_existing_file_protected(bool new_value_=true)
Set the protection against file overwriting.
virtual void _at_open(const std::string &filename_)
int store(const T &data_, const std::string &label_="")
Definition: writer-inl.h:49
Top-level namespace of the Bayeux/brio module library.
Definition: base_io.h:37