Jpp  18.0.1-rc.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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  * Clear status of reader.
70  */
71  virtual void clear() override
72  {
73  std::ifstream ::clear();
75  }
76 
77 
78  /**
79  * Rewind.
80  */
81  void rewind()
82  {
83  seekg(0); // rewind file stream
84 
85  reset(); // reset buffer
86  }
87  };
88 
89 
90  /**
91  * Binary buffered file output.
92  */
94  public std::ofstream,
95  public JBufferedWriter
96  {
97  public:
98 
99  using JAbstractObjectStatus::operator bool;
100  using JAbstractObjectStatus::operator!;
101  using JWriter::operator<<;
102 
103 
104  /**
105  * Default constructor.
106  */
108  std::ofstream(),
109  JBufferedWriter(new JStreamWriter(static_cast<std::ofstream&>(*this)))
110  {}
111 
112 
113  /**
114  * Constructor.
115  *
116  * \param file_name file name
117  * \param size size of internal buffer
118  */
119  JFileStreamWriter(const char* file_name,
120  const int size = 1048576) :
121  std::ofstream(),
122  JBufferedWriter(new JStreamWriter(static_cast<std::ofstream&>(*this)), size)
123  {
124  open(file_name);
125  }
126 
127 
128  /**
129  * Open file.
130  *
131  * \param file_name file name
132  */
133  void open(const char* file_name)
134  {
135  static_cast<std::ofstream*>(this)->open(file_name, std::ios::binary);
136  }
137 
138 
139  /**
140  * Close file.
141  */
142  void close()
143  {
144  static_cast<JBufferedWriter*>(this)->flush();
145  static_cast<std::ofstream*> (this)->close();
146  }
147  };
148 }
149 
150 #endif
virtual void clear() override
Clear status of reader.
Definition: JBufferedIO.hh:69
void close()
Close file.
JFileStreamWriter()
Default constructor.
void rewind()
Rewind.
void open(const char *file_name)
Open file.
then usage $script< detector file >< detectorfile > nIf the range of floors is the first detector file is aligned to the second before the comparison nIn this
Binary input based on std::istream.
Definition: JStreamIO.hh:24
virtual void clear() override
Clear status of reader.
JFileStreamReader()
Default constructor.
Buffered binary output.
Definition: JBufferedIO.hh:151
void open(const char *file_name)
Open file.
JFileStreamReader(const char *file_name, const int size=1048576)
Constructor.
int size
size of internal buffer
Definition: JBufferedIO.hh:239
int size
size of internal buffer
Definition: JBufferedIO.hh:134
Buffered binary input.
Definition: JBufferedIO.hh:25
JFileStreamWriter(const char *file_name, const int size=1048576)
Constructor.
void reset()
Reset.
Definition: JBufferedIO.hh:124
Binary buffered file output.
Binary buffered file input.
Binary output based on std::ostream.
Definition: JStreamIO.hh:81
void flush()
Write internal data to output.
Definition: JBufferedIO.hh:229