home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 Mobile / Chip_Mobile_2001.iso / palm / business / printcar / printcar.exe / tests / Util / TestDataStream.h < prev   
C/C++ Source or Header  |  2000-06-07  |  2KB  |  72 lines

  1. //
  2. //  $Id: TestDataStream.h,v 1.2 2000/06/07 06:53:18 sergey Exp $
  3. //
  4.  
  5.  
  6. #ifndef _TestDataStream_h_
  7. #define _TestDataStream_h_
  8.  
  9. #include "Util/DataInputStream.h"
  10. #include "Util/DataOutputStream.h"
  11. #include "Util/Assert.h"
  12.  
  13.  
  14. namespace Util
  15. {
  16.     class TestDataStream: public DataInputStream, public DataOutputStream
  17.     {
  18.     public:
  19.         TestDataStream():
  20.             _size(0), _position(0)
  21.         {}
  22.  
  23.         TestDataStream(const char* str):
  24.             _position(0)
  25.         {
  26.             StrCopy(_buffer, str);
  27.             _size = StrLen(str);
  28.         }
  29.  
  30.         void reset() { _position = 0; }
  31.  
  32.         virtual int readData(void* data, int size) const
  33.         {
  34.             if (!eof())
  35.             {
  36.                 if (_position+size > _size)
  37.                     size = _size-_position;
  38.                 MemMove(data, _buffer+_position, size);
  39.  
  40.                 _position += size;
  41.                 return size;
  42.             }
  43.             return 0;
  44.         }
  45.  
  46.         virtual bool eof() const { return _position >= _size; }
  47.  
  48.         virtual void writeData(const void* data, int size)
  49.         {
  50.             if (_position < 256)
  51.             {
  52.                 if (_position+size > 256)
  53.                     size = 256-_position;
  54.                 MemMove(_buffer+_position, data, size);
  55.  
  56.                 _position += size;
  57.                 if (_position > _size)
  58.                     _size = _position;
  59.             }
  60.         }
  61.  
  62.     // data members
  63.  
  64.         char _buffer[256];
  65.         int  _size;
  66.         mutable int  _position;
  67.     };
  68. }
  69. // namespace Util
  70.  
  71. #endif  // _TestDataStream_h_
  72.