00001 00032 #ifndef BINFILE_H 00033 #define BINFILE_H 00034 00035 #include <itpp/base/binary.h> 00036 #include <fstream> 00037 00038 00039 namespace itpp { 00040 00045 bool exist(const std::string &name); 00046 00054 class bfstream_base { 00055 public: 00066 enum endian { l_endian, b_endian }; 00067 00073 bfstream_base(endian e=b_endian); 00074 00078 endian get_endianity() const { return endianity; } 00079 00085 endian get_native_endianity() const { return native_endianity; } 00086 00090 void set_endianity(endian e) { endianity = e; } 00091 00095 void set_native_endianity() { endianity = native_endianity; } 00096 00097 protected: 00099 endian endianity; 00101 endian native_endianity; 00102 }; 00103 00108 class bofstream : public bfstream_base, public std::ofstream { 00109 public: 00116 bofstream(const std::string &name, endian e=b_endian); 00117 00119 bofstream(); 00120 00122 ~bofstream() { } 00123 00130 void open(const std::string &name, endian e=b_endian); 00131 00133 bofstream& operator<<(char a); 00135 bofstream& operator<<(const class bin &a); 00137 bofstream& operator<<(int a); 00139 bofstream& operator<<(unsigned int a); 00141 bofstream& operator<<(short a); 00143 bofstream& operator<<(unsigned short a); 00145 bofstream& operator<<(float a); 00147 bofstream& operator<<(double a); 00148 // Writes a \c long \c double variable to the binary output file 00149 //bofstream& operator<<(long double a); 00151 bofstream& operator<<(long int a); 00153 bofstream& operator<<(unsigned long int a); 00154 // Writes a \c long_long variable to the binary output file 00155 //bofstream& operator<<(long_long a); 00157 bofstream& operator<<(const char *a); 00159 bofstream& operator<<(const std::string &a); 00160 }; 00161 00166 class bifstream : public bfstream_base, public std::ifstream { 00167 public: 00174 bifstream(const std::string &name, endian e=b_endian); 00175 00177 bifstream(); 00178 00180 ~bifstream() { } 00181 00188 void open(const std::string &name, endian e=b_endian); 00189 00191 long length(); 00192 00194 bifstream& operator>>(char &a); 00196 bifstream& operator>>(class bin &a); 00198 bifstream& operator>>(int &a); 00200 bifstream& operator>>(unsigned int &a); 00202 bifstream& operator>>(short int &a); 00204 bifstream& operator>>(unsigned short int &a); 00206 bifstream& operator>>(float &a); 00208 bifstream& operator>>(double &a); 00209 // Reads a \c long \c double variable from the binary input file 00210 //bifstream& operator>>(long double &a); 00212 bifstream& operator>>(long int &a); 00214 bifstream& operator>>(unsigned long int &a); 00215 // Reads a \c long_long variable from the binary input file 00216 //bifstream& operator>>(long_long &a); 00218 bifstream& operator>>(char *a); 00220 bifstream& operator>>(std::string &a); 00221 }; 00222 00227 class bfstream : public bfstream_base, public std::fstream { 00228 public: 00235 bfstream(const std::string &name, endian e=b_endian); 00236 00238 bfstream(); 00239 00241 ~bfstream() { } 00242 00250 void open(const std::string &name, bool trunc=false, endian e=b_endian); 00251 00258 void open_readonly(const std::string &name, endian e=b_endian); 00259 00261 long length(); 00262 00264 bfstream& operator<<(char a); 00266 bfstream& operator<<(const class bin &a); 00268 bfstream& operator<<(int a); 00270 bfstream& operator<<(unsigned int a); 00272 bfstream& operator<<(short a); 00274 bfstream& operator<<(unsigned short a); 00276 bfstream& operator<<(float a); 00278 bfstream& operator<<(double a); 00279 // Writes a \c long \c double variable to the binary file 00280 //bfstream& operator<<(long double a); 00282 bfstream& operator<<(long int a); 00284 bfstream& operator<<(unsigned long int a); 00285 // Writes a \c long_long variable to the binary file 00286 //bfstream& operator<<(long_long a); 00288 bfstream& operator<<(const char *a); 00290 bfstream& operator<<(const std::string &a); 00291 00293 bfstream& operator>>(char &a); 00295 bfstream& operator>>(class bin &a); 00297 bfstream& operator>>(int &a); 00299 bfstream& operator>>(unsigned int &a); 00301 bfstream& operator>>(short int &a); 00303 bfstream& operator>>(unsigned short int &a); 00305 bfstream& operator>>(float &a); 00307 bfstream& operator>>(double &a); 00308 // Reads a \c long \c double variable from the binary file 00309 //bfstream& operator>>(long double &a); 00311 bfstream& operator>>(long int &a); 00313 bfstream& operator>>(unsigned long int &a); 00314 // Reads a \c long_long variable from the binary file 00315 //bfstream& operator>>(long_long &a); 00317 bfstream& operator>>(char *a); 00319 bfstream& operator>>(std::string &a); 00320 }; 00321 00322 } //namespace itpp 00323 00324 #endif // #ifndef BINFILE_H 00325 00326 00327 00328 00329 00330 00331 00332 00333 00334 00335 00336 00337
Generated on Thu Apr 19 14:23:56 2007 for IT++ by Doxygen 1.4.6