00001 00030 #ifndef BINFILE_H 00031 #define BINFILE_H 00032 00033 #include <itpp/base/ittypes.h> 00034 #include <fstream> 00035 00036 00037 namespace itpp 00038 { 00039 00044 bool exist(const std::string& name); 00045 00054 class bfstream_base 00055 { 00056 public: 00069 enum endian { l_endian, b_endian }; 00070 00078 bfstream_base(endian e = b_endian); 00079 00083 endian get_endianity() const { 00084 if (switch_endianity) { 00085 if (native_endianity == l_endian) 00086 return b_endian; 00087 else 00088 return l_endian; 00089 } 00090 else 00091 return native_endianity; 00092 } 00093 00100 endian get_native_endianity() const { return native_endianity; } 00101 00105 void set_endianity(endian e) { 00106 if (native_endianity == e) 00107 switch_endianity = false; 00108 else 00109 switch_endianity = true; 00110 } 00111 00116 void set_native_endianity() { switch_endianity = false; } 00117 00118 protected: 00120 bool switch_endianity; 00122 endian native_endianity; 00123 }; 00124 00129 class bofstream : public bfstream_base, public std::ofstream 00130 { 00131 public: 00140 bofstream(const std::string& name, endian e = b_endian); 00141 00143 bofstream(); 00144 00146 ~bofstream() { } 00147 00155 void open(const std::string& name, endian e = b_endian); 00156 00158 bofstream& operator<<(char a); 00160 bofstream& operator<<(unsigned char a); 00162 bofstream& operator<<(int16_t a); 00164 bofstream& operator<<(uint16_t a); 00166 bofstream& operator<<(int32_t a); 00168 bofstream& operator<<(uint32_t a); 00170 bofstream& operator<<(int64_t a); 00172 bofstream& operator<<(uint64_t a); 00174 bofstream& operator<<(float a); 00176 bofstream& operator<<(double a); 00178 bofstream& operator<<(const char* a); 00180 bofstream& operator<<(const std::string& a); 00181 }; 00182 00187 class bifstream : public bfstream_base, public std::ifstream 00188 { 00189 public: 00198 bifstream(const std::string& name, endian e = b_endian); 00199 00201 bifstream(); 00202 00204 ~bifstream() { } 00205 00213 void open(const std::string& name, endian e = b_endian); 00214 00216 int length(); 00217 00219 bifstream& operator>>(char& a); 00221 bifstream& operator>>(unsigned char& a); 00223 bifstream& operator>>(int16_t& a); 00225 bifstream& operator>>(uint16_t& a); 00227 bifstream& operator>>(int32_t& a); 00229 bifstream& operator>>(uint32_t& a); 00231 bifstream& operator>>(int64_t& a); 00233 bifstream& operator>>(uint64_t& a); 00235 bifstream& operator>>(float& a); 00237 bifstream& operator>>(double& a); 00239 bifstream& operator>>(char* a); 00241 bifstream& operator>>(std::string& a); 00242 }; 00243 00248 class bfstream : public bfstream_base, public std::fstream 00249 { 00250 public: 00259 bfstream(const std::string& name, endian e = b_endian); 00260 00262 bfstream(); 00263 00265 ~bfstream() { } 00266 00275 void open(const std::string& name, bool trunc = false, endian e = b_endian); 00276 00284 void open_readonly(const std::string& name, endian e = b_endian); 00285 00287 int length(); 00288 00290 bfstream& operator<<(char a); 00292 bfstream& operator<<(unsigned char a); 00294 bfstream& operator<<(int16_t a); 00296 bfstream& operator<<(uint16_t a); 00298 bfstream& operator<<(int32_t a); 00300 bfstream& operator<<(uint32_t a); 00302 bfstream& operator<<(int64_t a); 00304 bfstream& operator<<(uint64_t a); 00306 bfstream& operator<<(float a); 00308 bfstream& operator<<(double a); 00310 bfstream& operator<<(const char* a); 00312 bfstream& operator<<(const std::string& a); 00313 00315 bfstream& operator>>(char& a); 00317 bfstream& operator>>(unsigned char& a); 00319 bfstream& operator>>(int16_t& a); 00321 bfstream& operator>>(uint16_t& a); 00323 bfstream& operator>>(int32_t& a); 00325 bfstream& operator>>(uint32_t& a); 00327 bfstream& operator>>(int64_t& a); 00329 bfstream& operator>>(uint64_t& a); 00331 bfstream& operator>>(float& a); 00333 bfstream& operator>>(double& a); 00335 bfstream& operator>>(char* a); 00337 bfstream& operator>>(std::string& a); 00338 }; 00339 00340 } //namespace itpp 00341 00342 #endif // #ifndef BINFILE_H
Generated on Tue Dec 6 2011 16:51:41 for IT++ by Doxygen 1.7.4