IT++ Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
binfile.h
Go to the documentation of this file.
1 
29 #ifndef BINFILE_H
30 #define BINFILE_H
31 
32 #include <itpp/base/ittypes.h>
33 #include <fstream>
34 
35 
36 namespace itpp
37 {
38 
43 bool exist(const std::string& name);
44 
54 {
55 public:
68  enum endian { l_endian, b_endian };
69 
77  bfstream_base(endian e = b_endian);
78 
83  if (switch_endianity) {
84  if (native_endianity == l_endian)
85  return b_endian;
86  else
87  return l_endian;
88  }
89  else
90  return native_endianity;
91  }
92 
100 
105  if (native_endianity == e)
106  switch_endianity = false;
107  else
108  switch_endianity = true;
109  }
110 
116 
117 protected:
122 };
123 
128 class bofstream : public bfstream_base, public std::ofstream
129 {
130 public:
139  bofstream(const std::string& name, endian e = b_endian);
140 
142  bofstream();
143 
146 
154  void open(const std::string& name, endian e = b_endian);
155 
157  bofstream& operator<<(char a);
159  bofstream& operator<<(unsigned char a);
161  bofstream& operator<<(int16_t a);
163  bofstream& operator<<(uint16_t a);
165  bofstream& operator<<(int32_t a);
167  bofstream& operator<<(uint32_t a);
169  bofstream& operator<<(int64_t a);
171  bofstream& operator<<(uint64_t a);
173  bofstream& operator<<(float a);
175  bofstream& operator<<(double a);
177  bofstream& operator<<(const char* a);
179  bofstream& operator<<(const std::string& a);
180 };
181 
186 class bifstream : public bfstream_base, public std::ifstream
187 {
188 public:
197  bifstream(const std::string& name, endian e = b_endian);
198 
200  bifstream();
201 
204 
212  void open(const std::string& name, endian e = b_endian);
213 
215  int length();
216 
218  bifstream& operator>>(char& a);
220  bifstream& operator>>(unsigned char& a);
222  bifstream& operator>>(int16_t& a);
224  bifstream& operator>>(uint16_t& a);
226  bifstream& operator>>(int32_t& a);
228  bifstream& operator>>(uint32_t& a);
230  bifstream& operator>>(int64_t& a);
232  bifstream& operator>>(uint64_t& a);
234  bifstream& operator>>(float& a);
236  bifstream& operator>>(double& a);
238  bifstream& operator>>(char* a);
240  bifstream& operator>>(std::string& a);
241 };
242 
247 class bfstream : public bfstream_base, public std::fstream
248 {
249 public:
258  bfstream(const std::string& name, endian e = b_endian);
259 
261  bfstream();
262 
264  ~bfstream() { }
265 
274  void open(const std::string& name, bool trunc = false, endian e = b_endian);
275 
283  void open_readonly(const std::string& name, endian e = b_endian);
284 
286  int length();
287 
289  bfstream& operator<<(char a);
291  bfstream& operator<<(unsigned char a);
293  bfstream& operator<<(int16_t a);
295  bfstream& operator<<(uint16_t a);
297  bfstream& operator<<(int32_t a);
299  bfstream& operator<<(uint32_t a);
301  bfstream& operator<<(int64_t a);
303  bfstream& operator<<(uint64_t a);
305  bfstream& operator<<(float a);
307  bfstream& operator<<(double a);
309  bfstream& operator<<(const char* a);
311  bfstream& operator<<(const std::string& a);
312 
314  bfstream& operator>>(char& a);
316  bfstream& operator>>(unsigned char& a);
318  bfstream& operator>>(int16_t& a);
320  bfstream& operator>>(uint16_t& a);
322  bfstream& operator>>(int32_t& a);
324  bfstream& operator>>(uint32_t& a);
326  bfstream& operator>>(int64_t& a);
328  bfstream& operator>>(uint64_t& a);
330  bfstream& operator>>(float& a);
332  bfstream& operator>>(double& a);
334  bfstream& operator>>(char* a);
336  bfstream& operator>>(std::string& a);
337 };
338 
339 } //namespace itpp
340 
341 #endif // #ifndef BINFILE_H
SourceForge Logo

Generated on Fri Mar 21 2014 17:14:12 for IT++ by Doxygen 1.8.1.2