#ifndef _COMMON_IOBUFFER_HPP_
#define _COMMON_IOBUFFER_HPP_
#ifndef _COMMON_WINDOWS_HPP_
#include <common/windows.hpp>
#endif

class IOBuffer
{
public:
	IOBuffer(DWORD lengthBuffer);
	virtual ~IOBuffer();
	BYTE FAR *lpBufferPointer(void);
	BYTE FAR *lpBuffer(void);
	IOBuffer &operator++(void);
	BOOL operator+=(int offset);
	BOOL operator-=(int offset);
	DWORD bufferIndex(void)const;
  void bufferIndex(DWORD bufferIndex);
private:
  void destroyBuffer(void);
  WORD createBuffer(DWORD lengthBuffer);

	HGLOBAL mhGlobalBuffer;
	BYTE FAR *mlpBuffer;
	BYTE FAR *mlpBufferPointer;
  DWORD mBufferIndex;
};

inline
IOBuffer::IOBuffer(DWORD lengthBuffer)
: mhGlobalBuffer(0), mlpBuffer(0), mlpBufferPointer(0), mBufferIndex(0)
{
	createBuffer(lengthBuffer);
}

inline
IOBuffer::~IOBuffer()
{
  destroyBuffer();
}

class IOBufferBounds{};

inline
IOBuffer &IOBuffer::operator++(void)
{
	mlpBufferPointer++;
	mBufferIndex--;
  return *this;
}

inline
DWORD IOBuffer::bufferIndex(void)const
{
  return mBufferIndex;
}

inline
void IOBuffer::bufferIndex(DWORD bufferIndex)
{
	mBufferIndex=bufferIndex;
  mlpBufferPointer=mlpBuffer;
}

inline
BYTE FAR *IOBuffer::lpBuffer(void)
{
	return mlpBuffer;
}

inline
BYTE FAR *IOBuffer::lpBufferPointer(void)
{
  return mlpBufferPointer;
}
#endif
