Jpp
JFileStreamIO.hh
Go to the documentation of this file.
1 #ifndef __JIO__JFILESTREAMIO__
2 #define __JIO__JFILESTREAMIO__
3 
4 #include <fstream>
5 
6 #include "JIO/JStreamIO.hh"
7 #include "JIO/JBufferedIO.hh"
8 
9 
10 /**
11  * \author mdejong
12  */
13 
14 namespace JIO {}
15 namespace JPP { using namespace JIO; }
16 
17 namespace JIO {
18 
19  /**
20  * Binary buffered file input.
21  */
23  public std::ifstream,
24  public JBufferedReader
25  {
26  public:
27 
28  using JAbstractObjectStatus::operator bool;
29  using JAbstractObjectStatus::operator!;
30  using JReader::operator>>;
31 
32 
33  /**
34  * Default constructor.
35  */
37  std::ifstream(),
38  JBufferedReader(new JStreamReader(static_cast<std::ifstream&>(*this)))
39  {}
40 
41 
42  /**
43  * Constructor.
44  *
45  * \param file_name file name
46  * \param size size of internal buffer
47  */
48  JFileStreamReader(const char* file_name,
49  const int size = 1048576) :
50  std::ifstream (),
51  JBufferedReader(new JStreamReader(static_cast<std::ifstream&>(*this)), size)
52  {
53  open(file_name);
54  }
55 
56 
57  /**
58  * Open file.
59  *
60  * \param file_name file name
61  */
62  void open(const char* file_name)
63  {
64  static_cast<std::ifstream*>(this)->open(file_name, std::ios::binary);
65  }
66  };
67 
68 
69  /**
70  * Binary buffered file output.
71  */
73  public std::ofstream,
74  public JBufferedWriter
75  {
76  public:
77 
78  using JAbstractObjectStatus::operator bool;
79  using JAbstractObjectStatus::operator!;
80  using JWriter::operator<<;
81 
82 
83  /**
84  * Default constructor.
85  */
87  std::ofstream(),
88  JBufferedWriter(new JStreamWriter(static_cast<std::ofstream&>(*this)))
89  {}
90 
91 
92  /**
93  * Constructor.
94  *
95  * \param file_name file name
96  * \param size size of internal buffer
97  */
98  JFileStreamWriter(const char* file_name,
99  const int size = 1048576) :
100  std::ofstream(),
101  JBufferedWriter(new JStreamWriter(static_cast<std::ofstream&>(*this)), size)
102  {
103  open(file_name);
104  }
105 
106 
107  /**
108  * Open file.
109  *
110  * \param file_name file name
111  */
112  void open(const char* file_name)
113  {
114  static_cast<std::ofstream*>(this)->open(file_name, std::ios::binary);
115  }
116 
117 
118  /**
119  * Close file.
120  */
121  void close()
122  {
123  static_cast<JBufferedWriter*>(this)->flush();
124  static_cast<std::ofstream*> (this)->close();
125  }
126  };
127 }
128 
129 #endif
JIO::JFileStreamReader::JFileStreamReader
JFileStreamReader()
Default constructor.
Definition: JFileStreamIO.hh:36
JStreamIO.hh
JIO::JFileStreamWriter
Binary buffered file output.
Definition: JFileStreamIO.hh:72
JIO::JFileStreamReader
Binary buffered file input.
Definition: JFileStreamIO.hh:22
JIO::JBufferedReader::size
int size
size of internal buffer
Definition: JBufferedIO.hh:127
JIO::JStreamWriter
Binary output based on std::ostream.
Definition: JStreamIO.hh:81
JIO::JBufferedWriter
Buffered binary output.
Definition: JBufferedIO.hh:138
JIO::JBufferedWriter::size
int size
size of internal buffer
Definition: JBufferedIO.hh:226
JBufferedIO.hh
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JIO::JFileStreamWriter::JFileStreamWriter
JFileStreamWriter(const char *file_name, const int size=1048576)
Constructor.
Definition: JFileStreamIO.hh:98
JIO::JFileStreamReader::open
void open(const char *file_name)
Open file.
Definition: JFileStreamIO.hh:62
JIO::JFileStreamWriter::close
void close()
Close file.
Definition: JFileStreamIO.hh:121
JIO::JStreamReader
Binary input based on std::istream.
Definition: JStreamIO.hh:24
JIO::JFileStreamWriter::JFileStreamWriter
JFileStreamWriter()
Default constructor.
Definition: JFileStreamIO.hh:86
std
Definition: jaanetDictionary.h:36
JIO
Auxiliary classes and methods for binary I/O.
Definition: JBinaryFileReader.hh:17
JIO::JFileStreamWriter::open
void open(const char *file_name)
Open file.
Definition: JFileStreamIO.hh:112
JIO::JFileStreamReader::JFileStreamReader
JFileStreamReader(const char *file_name, const int size=1048576)
Constructor.
Definition: JFileStreamIO.hh:48
JIO::JBufferedReader
Buffered binary input.
Definition: JBufferedIO.hh:25