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       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     {
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   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   public:
00196     bifstream(const std::string& name, endian e = b_endian);
00197 
00199     bifstream();
00200 
00202     ~bifstream() { }
00203 
00211     void open(const std::string& name, endian e = b_endian);
00212 
00214     int length();
00215 
00217     bifstream& operator>>(char& a);
00219     bifstream& operator>>(unsigned char& a);
00221     bifstream& operator>>(int16_t& a);
00223     bifstream& operator>>(uint16_t& a);
00225     bifstream& operator>>(int32_t& a);
00227     bifstream& operator>>(uint32_t& a);
00229     bifstream& operator>>(int64_t& a);
00231     bifstream& operator>>(uint64_t& a);
00233     bifstream& operator>>(float& a);
00235     bifstream& operator>>(double& a);
00237     bifstream& operator>>(char* a);
00239     bifstream& operator>>(std::string& a);
00240   };
00241 
00246   class bfstream : public bfstream_base, public std::fstream {
00247   public:
00256     bfstream(const std::string& name, endian e = b_endian);
00257 
00259     bfstream();
00260 
00262     ~bfstream() { }
00263 
00272     void open(const std::string& name, bool trunc = false, endian e = b_endian);
00273 
00281     void open_readonly(const std::string& name, endian e = b_endian);
00282 
00284     int length();
00285 
00287     bfstream& operator<<(char a);
00289     bfstream& operator<<(unsigned char a);
00291     bfstream& operator<<(int16_t a);
00293     bfstream& operator<<(uint16_t a);
00295     bfstream& operator<<(int32_t a);
00297     bfstream& operator<<(uint32_t a);
00299     bfstream& operator<<(int64_t a);
00301     bfstream& operator<<(uint64_t a);
00303     bfstream& operator<<(float a);
00305     bfstream& operator<<(double a);
00307     bfstream& operator<<(const char* a);
00309     bfstream& operator<<(const std::string& a);
00310 
00312     bfstream& operator>>(char& a);
00314     bfstream& operator>>(unsigned char& a);
00316     bfstream& operator>>(int16_t& a);
00318     bfstream& operator>>(uint16_t& a);
00320     bfstream& operator>>(int32_t& a);
00322     bfstream& operator>>(uint32_t& a);
00324     bfstream& operator>>(int64_t& a);
00326     bfstream& operator>>(uint64_t& a);
00328     bfstream& operator>>(float& a);
00330     bfstream& operator>>(double& a);
00332     bfstream& operator>>(char* a);
00334     bfstream& operator>>(std::string& a);
00335   };
00336 
00337 } //namespace itpp
00338 
00339 #endif // #ifndef BINFILE_H
SourceForge Logo

Generated on Sat Apr 19 10:43:51 2008 for IT++ by Doxygen 1.5.5