IT++ Logo

binfile.h

Go to the documentation of this file.
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 
00043   bool exist(const std::string& name);
00044 
00053   class bfstream_base {
00054   public:
00067     enum endian { l_endian, b_endian };
00068 
00076     bfstream_base(endian e = b_endian);
00077 
00081     endian get_endianity() const
00082     {
00083       return switch_endianity
00084   ? static_cast<endian>(!native_endianity) : native_endianity;
00085     }
00086 
00093     endian get_native_endianity() const { return native_endianity; }
00094 
00098     void set_endianity(endian e)
00099     {
00100       (native_endianity == e)
00101   ? switch_endianity = false : switch_endianity = true;
00102     }
00103 
00108     void set_native_endianity() { switch_endianity = false; }
00109 
00110   protected:
00112     bool switch_endianity;
00114     endian native_endianity;
00115   };
00116 
00121   class bofstream : public bfstream_base, public std::ofstream {
00122   public:
00131     bofstream(const std::string& name, endian e = b_endian);
00132 
00134     bofstream();
00135 
00137     ~bofstream() { }
00138 
00146     void open(const std::string& name, endian e = b_endian);
00147 
00149     bofstream& operator<<(char a);
00151     bofstream& operator<<(unsigned char a);
00153     bofstream& operator<<(int16_t a);
00155     bofstream& operator<<(uint16_t a);
00157     bofstream& operator<<(int32_t a);
00159     bofstream& operator<<(uint32_t a);
00161     bofstream& operator<<(int64_t a);
00163     bofstream& operator<<(uint64_t a);
00165     bofstream& operator<<(float a);
00167     bofstream& operator<<(double a);
00169     bofstream& operator<<(const char* a);
00171     bofstream& operator<<(const std::string& a);
00172   };
00173 
00178   class bifstream : public bfstream_base, public std::ifstream {
00179   public:
00188     bifstream(const std::string& name, endian e = b_endian);
00189 
00191     bifstream();
00192 
00194     ~bifstream() { }
00195 
00203     void open(const std::string& name, endian e = b_endian);
00204 
00206     int length();
00207 
00209     bifstream& operator>>(char& a);
00211     bifstream& operator>>(unsigned char& a);
00213     bifstream& operator>>(int16_t& a);
00215     bifstream& operator>>(uint16_t& a);
00217     bifstream& operator>>(int32_t& a);
00219     bifstream& operator>>(uint32_t& a);
00221     bifstream& operator>>(int64_t& a);
00223     bifstream& operator>>(uint64_t& a);
00225     bifstream& operator>>(float& a);
00227     bifstream& operator>>(double& a);
00229     bifstream& operator>>(char* a);
00231     bifstream& operator>>(std::string& a);
00232   };
00233 
00238   class bfstream : public bfstream_base, public std::fstream {
00239   public:
00248     bfstream(const std::string& name, endian e = b_endian);
00249 
00251     bfstream();
00252 
00254     ~bfstream() { }
00255 
00264     void open(const std::string& name, bool trunc = false, endian e = b_endian);
00265 
00273     void open_readonly(const std::string& name, endian e = b_endian);
00274 
00276     int length();
00277 
00279     bfstream& operator<<(char a);
00281     bfstream& operator<<(unsigned char a);
00283     bfstream& operator<<(int16_t a);
00285     bfstream& operator<<(uint16_t a);
00287     bfstream& operator<<(int32_t a);
00289     bfstream& operator<<(uint32_t a);
00291     bfstream& operator<<(int64_t a);
00293     bfstream& operator<<(uint64_t a);
00295     bfstream& operator<<(float a);
00297     bfstream& operator<<(double a);
00299     bfstream& operator<<(const char* a);
00301     bfstream& operator<<(const std::string& a);
00302 
00304     bfstream& operator>>(char& a);
00306     bfstream& operator>>(unsigned char& a);
00308     bfstream& operator>>(int16_t& a);
00310     bfstream& operator>>(uint16_t& a);
00312     bfstream& operator>>(int32_t& a);
00314     bfstream& operator>>(uint32_t& a);
00316     bfstream& operator>>(int64_t& a);
00318     bfstream& operator>>(uint64_t& a);
00320     bfstream& operator>>(float& a);
00322     bfstream& operator>>(double& a);
00324     bfstream& operator>>(char* a);
00326     bfstream& operator>>(std::string& a);
00327   };
00328 
00329 } //namespace itpp
00330 
00331 #endif // #ifndef BINFILE_H
SourceForge Logo

Generated on Sun Dec 9 17:30:59 2007 for IT++ by Doxygen 1.5.4