home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2001 Mobile
/
Chip_Mobile_2001.iso
/
palm
/
business
/
printcar
/
printcar.exe
/
tests
/
Util
/
TestDataStream.h
< prev
Wrap
C/C++ Source or Header
|
2000-06-07
|
2KB
|
72 lines
//
// $Id: TestDataStream.h,v 1.2 2000/06/07 06:53:18 sergey Exp $
//
#ifndef _TestDataStream_h_
#define _TestDataStream_h_
#include "Util/DataInputStream.h"
#include "Util/DataOutputStream.h"
#include "Util/Assert.h"
namespace Util
{
class TestDataStream: public DataInputStream, public DataOutputStream
{
public:
TestDataStream():
_size(0), _position(0)
{}
TestDataStream(const char* str):
_position(0)
{
StrCopy(_buffer, str);
_size = StrLen(str);
}
void reset() { _position = 0; }
virtual int readData(void* data, int size) const
{
if (!eof())
{
if (_position+size > _size)
size = _size-_position;
MemMove(data, _buffer+_position, size);
_position += size;
return size;
}
return 0;
}
virtual bool eof() const { return _position >= _size; }
virtual void writeData(const void* data, int size)
{
if (_position < 256)
{
if (_position+size > 256)
size = 256-_position;
MemMove(_buffer+_position, data, size);
_position += size;
if (_position > _size)
_size = _position;
}
}
// data members
char _buffer[256];
int _size;
mutable int _position;
};
}
// namespace Util
#endif // _TestDataStream_h_