Bayeux  3.4.1
Core Foundation library for SuperNEMO
temporary_files.h
Go to the documentation of this file.
1 
3 #ifndef DATATOOLS_TEMPORARY_FILES_H
4 #define DATATOOLS_TEMPORARY_FILES_H
5 
6 // Standard Library:
7 #include <iostream>
8 #include <fstream>
9 #include <string>
10 
11 namespace datatools {
12 
15  class temp_file
16  {
17  public:
18  static const std::string & default_pattern();
19 
20  public:
21 
23  temp_file();
24 
26  temp_file(const char* pattern_, bool remove_at_destroy_ = true);
27 
29  temp_file(std::string pattern_, bool remove_at_destroy_ = true);
30 
32  temp_file(const char* path_dir_, const char* pattern_,
33  bool remove_at_destroy_ = true);
34 
36  temp_file(std::string path_dir_, const char* pattern_,
37  bool remove_at_destroy_ = true);
38 
40  temp_file(std::string path_dir_, std::string pattern_,
41  bool remove_at_destroy_ = true);
42 
44  ~temp_file();
45 
47  const std::string& get_filename() const;
48 
50  bool is_valid() const;
51 
53  bool is_read_open() const;
54 
56  bool is_write_open() const;
57 
59  void set_remove_at_destroy(bool);
60 
62  void set_verbose(bool);
63 
65  std::ofstream& out();
66 
68  std::ifstream& in();
69 
71  void create(std::string path_dir_, std::string pattern_);
72 
74  void close();
75 
77  void remove();
78 
79  protected:
80 
82  void set_defaults();
83 
84  private:
85  bool _verbose_;
86  bool _remove_at_destroy_;
87  std::string _path_dir_;
88  std::string _pattern_;
89  std::string _full_pattern_;
90  std::string _filename_;
91  bool _read_open_;
92  bool _write_open_;
93  char * _template_;
94  std::ofstream _out_;
95  std::ifstream _in_;
96  };
97 
98 } // namespace datatools
99 
100 #endif // DATATOOLS_TEMPORARY_FILES_H
101 
102 // Local Variables: --
103 // mode: c++ --
104 // c-file-style: "gnu" --
105 // tab-width: 2 --
106 // End: --
void set_defaults()
Set the default values of attributes.
std::ofstream & out()
Return the associated output stream.
void close()
Close the temporary file.
void remove()
Remove the temporary file from the filesystem.
std::ifstream & in()
Return the associated input stream.
bool is_write_open() const
Check if the temporary file is open for writing.
void set_remove_at_destroy(bool)
Set the 'remove at destroy' flag.
static const std::string & default_pattern()
void create(std::string path_dir_, std::string pattern_)
Create the temporary file from path and filename pattern.
void set_verbose(bool)
Activate verbosity.
A class for the management of temporary unique file stored in a given directory.
Definition: temporary_files.h:15
The Bayeux/datatools library top-level namespace.
Definition: algo.h:13
const std::string & get_filename() const
Return the filename of the temporary file.
bool is_valid() const
Check the validity of the temporary file.
~temp_file()
Destructor.
bool is_read_open() const
Check if the temporary file is open for reading.
temp_file()
Default constructor.