home *** CD-ROM | disk | FTP | other *** search
/ Xentax forum attachments archive / xentax.7z / 5036 / source.7z / x_stream.h < prev    next >
Encoding:
C/C++ Source or Header  |  2011-12-19  |  5.8 KB  |  152 lines

  1. #ifndef __XENTAX_STREAM_H
  2. #define __XENTAX_STREAM_H
  3.  
  4. class binary_stream {
  5.  public :
  6.   typedef boost::shared_array<char> data_type;
  7.   typedef size_t size_type;
  8.   typedef ptrdiff_t diff_type;
  9.   static const size_type npos;
  10.  private :
  11.   data_type data;
  12.   size_type elem;
  13.   size_type position;
  14.  public :
  15.   size_type size(void)const { return elem; }
  16.   const char* c_str(void)const { return data.get(); }
  17.   const char* c_str(size_type pos)const { return data.get() + pos; }
  18.   const char* c_pos(void)const { return data.get() + position; }
  19.   size_type tell(void)const { return position; }
  20.   bool at_begin(void)const { return position == 0; }
  21.   bool at_end(void)const { return position == elem; }
  22.   bool can_seek(size_type pos)const { return ((position != npos) && !(elem < pos)); }
  23.   bool can_move(diff_type pos)const { return ((position != npos) && (pos != npos) && !(pos < 0 ? (position < (size_type)std::abs(pos)) : (elem < (position + pos)))); }
  24.   bool fail(void)const { return position == npos; }
  25.   bool good(void)const { return position != npos; }
  26.  public :
  27.   void seek(size_type pos);
  28.   void seek_reverse(size_type pos);
  29.   void move(diff_type pos);
  30.   void move(diff_type pos, size_type from);
  31.   void reset(void);
  32.  public :
  33.   size_type search(const char* pattern, size_type n, size_t from = 0);
  34.  public :
  35.   void read(char* ptr, size_type n);
  36.   void read_reverse(char* ptr, size_type n);
  37.   std::string read_string(void); // TODO
  38.  public :
  39.   sint08 LE_read_sint08(void);
  40.   uint08 LE_read_uint08(void);
  41.   sint16 LE_read_sint16(void);
  42.   uint16 LE_read_uint16(void);
  43.   sint32 LE_read_sint32(void);
  44.   uint32 LE_read_uint32(void);
  45.   sint64 LE_read_sint64(void);
  46.   uint64 LE_read_uint64(void);
  47.   sint08 LE_read_sint08(size_type pos);
  48.   uint08 LE_read_uint08(size_type pos);
  49.   sint16 LE_read_sint16(size_type pos);
  50.   uint16 LE_read_uint16(size_type pos);
  51.   sint32 LE_read_sint32(size_type pos);
  52.   uint32 LE_read_uint32(size_type pos);
  53.   sint64 LE_read_sint64(size_type pos);
  54.   uint64 LE_read_uint64(size_type pos);
  55.  public :
  56.   sint08 BE_read_sint08(void);
  57.   uint08 BE_read_uint08(void);
  58.   sint16 BE_read_sint16(void);
  59.   uint16 BE_read_uint16(void);
  60.   sint32 BE_read_sint32(void);
  61.   uint32 BE_read_uint32(void);
  62.   sint64 BE_read_sint64(void);
  63.   uint64 BE_read_uint64(void);
  64.   sint08 BE_read_sint08(size_type pos);
  65.   uint08 BE_read_uint08(size_type pos);
  66.   sint16 BE_read_sint16(size_type pos);
  67.   uint16 BE_read_uint16(size_type pos);
  68.   sint32 BE_read_sint32(size_type pos);
  69.   uint32 BE_read_uint32(size_type pos);
  70.   sint64 BE_read_sint64(size_type pos);
  71.   uint64 BE_read_uint64(size_type pos);
  72.  public :
  73.   float32 LE_read_float16(void);
  74.   float32 LE_read_float32(void);
  75.   float64 LE_read_float64(void);
  76.   float32 LE_read_float16(size_type pos);
  77.   float32 LE_read_float32(size_type pos);
  78.   float64 LE_read_float64(size_type pos);
  79.  public :
  80.   float32 BE_read_float16(void);
  81.   float32 BE_read_float32(void);
  82.   float64 BE_read_float64(void);
  83.   float32 BE_read_float16(size_type pos);
  84.   float32 BE_read_float32(size_type pos);
  85.   float64 BE_read_float64(size_type pos);
  86.  private :
  87.   void LE_read(sint08* ptr, size_type n);
  88.   void LE_read(sint16* ptr, size_type n);
  89.   void LE_read(sint32* ptr, size_type n);
  90.   void LE_read(sint64* ptr, size_type n);
  91.   void LE_read(sint08* ptr, size_type n, size_type pos);
  92.   void LE_read(sint16* ptr, size_type n, size_type pos);
  93.   void LE_read(sint32* ptr, size_type n, size_type pos);
  94.   void LE_read(sint64* ptr, size_type n, size_type pos);
  95.  private :
  96.   void BE_read(sint08* ptr, size_type n);
  97.   void BE_read(sint16* ptr, size_type n);
  98.   void BE_read(sint32* ptr, size_type n);
  99.   void BE_read(sint64* ptr, size_type n);
  100.   void BE_read(sint08* ptr, size_type n, size_type pos);
  101.   void BE_read(sint16* ptr, size_type n, size_type pos);
  102.   void BE_read(sint32* ptr, size_type n, size_type pos);
  103.   void BE_read(sint64* ptr, size_type n, size_type pos);
  104.  public :
  105.   void LE_read(uint08* ptr, size_type n);
  106.   void LE_read(uint16* ptr, size_type n);
  107.   void LE_read(uint32* ptr, size_type n);
  108.   void LE_read(uint64* ptr, size_type n);
  109.   void LE_read(uint08* ptr, size_type n, size_type pos);
  110.   void LE_read(uint16* ptr, size_type n, size_type pos);
  111.   void LE_read(uint32* ptr, size_type n, size_type pos);
  112.   void LE_read(uint64* ptr, size_type n, size_type pos);
  113.  public :
  114.   void BE_read(uint08* ptr, size_type n);
  115.   void BE_read(uint16* ptr, size_type n);
  116.   void BE_read(uint32* ptr, size_type n);
  117.   void BE_read(uint64* ptr, size_type n);
  118.   void BE_read(uint08* ptr, size_type n, size_type pos);
  119.   void BE_read(uint16* ptr, size_type n, size_type pos);
  120.   void BE_read(uint32* ptr, size_type n, size_type pos);
  121.   void BE_read(uint64* ptr, size_type n, size_type pos);
  122.  public :
  123.   void LE_read(float32* ptr, size_type n);
  124.   void LE_read(float64* ptr, size_type n);
  125.   void LE_read(float32* ptr, size_type n, size_type pos);
  126.   void LE_read(float64* ptr, size_type n, size_type pos);
  127.  public :
  128.   void BE_read(float32* ptr, size_type n);
  129.   void BE_read(float64* ptr, size_type n);
  130.   void BE_read(float32* ptr, size_type n, size_type pos);
  131.   void BE_read(float64* ptr, size_type n, size_type pos);
  132.  public :
  133.   void LE_read_float16(float32* ptr, size_type n);
  134.   void LE_read_float16(float64* ptr, size_type n);
  135.   void LE_read_float16(float32* ptr, size_type n, size_type pos);
  136.   void LE_read_float16(float64* ptr, size_type n, size_type pos);
  137.  public :
  138.   void BE_read_float16(float32* ptr, size_type n);
  139.   void BE_read_float16(float64* ptr, size_type n);
  140.   void BE_read_float16(float32* ptr, size_type n, size_type pos);
  141.   void BE_read_float16(float64* ptr, size_type n, size_type pos);
  142.  public :
  143.   binary_stream& operator =(const binary_stream& bs);
  144.  public :
  145.   binary_stream();
  146.   binary_stream(const binary_stream& bs);
  147.   binary_stream(const boost::shared_array<char>& stream, size_type n);
  148.  ~binary_stream();
  149. };
  150.  
  151. #endif
  152.