IT++ Logo
binfile.h
Go to the documentation of this file.
00001 
00029 #ifndef BINFILE_H
00030 #define BINFILE_H
00031 
00032 #include <itpp/base/ittypes.h>
00033 #include <fstream>
00034 
00035 
00036 namespace itpp
00037 {
00038 
00043 bool exist(const std::string& name);
00044 
00053 class bfstream_base
00054 {
00055 public:
00068   enum endian { l_endian, b_endian };
00069 
00077   bfstream_base(endian e = b_endian);
00078 
00082   endian get_endianity() const {
00083     if (switch_endianity) {
00084       if (native_endianity == l_endian)
00085         return b_endian;
00086       else
00087         return l_endian;
00088     }
00089     else
00090       return native_endianity;
00091   }
00092 
00099   endian get_native_endianity() const { return native_endianity; }
00100 
00104   void set_endianity(endian e) {
00105     if (native_endianity == e)
00106       switch_endianity = false;
00107     else
00108       switch_endianity = true;
00109   }
00110 
00115   void set_native_endianity() { switch_endianity = false; }
00116 
00117 protected:
00119   bool switch_endianity;
00121   endian native_endianity;
00122 };
00123 
00128 class bofstream : public bfstream_base, public std::ofstream
00129 {
00130 public:
00139   bofstream(const std::string& name, endian e = b_endian);
00140 
00142   bofstream();
00143 
00145   ~bofstream() { }
00146 
00154   void open(const std::string& name, endian e = b_endian);
00155 
00157   bofstream& operator<<(char a);
00159   bofstream& operator<<(unsigned char a);
00161   bofstream& operator<<(int16_t a);
00163   bofstream& operator<<(uint16_t a);
00165   bofstream& operator<<(int32_t a);
00167   bofstream& operator<<(uint32_t a);
00169   bofstream& operator<<(int64_t a);
00171   bofstream& operator<<(uint64_t a);
00173   bofstream& operator<<(float a);
00175   bofstream& operator<<(double a);
00177   bofstream& operator<<(const char* a);
00179   bofstream& operator<<(const std::string& a);
00180 };
00181 
00186 class bifstream : public bfstream_base, public std::ifstream
00187 {
00188 public:
00197   bifstream(const std::string& name, endian e = b_endian);
00198 
00200   bifstream();
00201 
00203   ~bifstream() { }
00204 
00212   void open(const std::string& name, endian e = b_endian);
00213 
00215   int length();
00216 
00218   bifstream& operator>>(char& a);
00220   bifstream& operator>>(unsigned char& a);
00222   bifstream& operator>>(int16_t& a);
00224   bifstream& operator>>(uint16_t& a);
00226   bifstream& operator>>(int32_t& a);
00228   bifstream& operator>>(uint32_t& a);
00230   bifstream& operator>>(int64_t& a);
00232   bifstream& operator>>(uint64_t& a);
00234   bifstream& operator>>(float& a);
00236   bifstream& operator>>(double& a);
00238   bifstream& operator>>(char* a);
00240   bifstream& operator>>(std::string& a);
00241 };
00242 
00247 class bfstream : public bfstream_base, public std::fstream
00248 {
00249 public:
00258   bfstream(const std::string& name, endian e = b_endian);
00259 
00261   bfstream();
00262 
00264   ~bfstream() { }
00265 
00274   void open(const std::string& name, bool trunc = false, endian e = b_endian);
00275 
00283   void open_readonly(const std::string& name, endian e = b_endian);
00284 
00286   int length();
00287 
00289   bfstream& operator<<(char a);
00291   bfstream& operator<<(unsigned char a);
00293   bfstream& operator<<(int16_t a);
00295   bfstream& operator<<(uint16_t a);
00297   bfstream& operator<<(int32_t a);
00299   bfstream& operator<<(uint32_t a);
00301   bfstream& operator<<(int64_t a);
00303   bfstream& operator<<(uint64_t a);
00305   bfstream& operator<<(float a);
00307   bfstream& operator<<(double a);
00309   bfstream& operator<<(const char* a);
00311   bfstream& operator<<(const std::string& a);
00312 
00314   bfstream& operator>>(char& a);
00316   bfstream& operator>>(unsigned char& a);
00318   bfstream& operator>>(int16_t& a);
00320   bfstream& operator>>(uint16_t& a);
00322   bfstream& operator>>(int32_t& a);
00324   bfstream& operator>>(uint32_t& a);
00326   bfstream& operator>>(int64_t& a);
00328   bfstream& operator>>(uint64_t& a);
00330   bfstream& operator>>(float& a);
00332   bfstream& operator>>(double& a);
00334   bfstream& operator>>(char* a);
00336   bfstream& operator>>(std::string& a);
00337 };
00338 
00339 } //namespace itpp
00340 
00341 #endif // #ifndef BINFILE_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
SourceForge Logo

Generated on Sat Jul 9 2011 15:21:29 for IT++ by Doxygen 1.7.4