PagedBufferAsStream.h
// PagedBufferAsStream.h
//
// Author David Barrett-Lennard
// (C)opyright Cedanet Pty Ltd 2008
#pragma once
#ifndef Ceda_cxUtils_PagedBufferAsStream_H
#define Ceda_cxUtils_PagedBufferAsStream_H
#include "cxUtils.h"
#include "PagedBuffer.h"
#include "StreamInterfaces.h"
#ifdef _MSC_VER
// non dll-interface struct 'X' used as base for dll-interface class 'Y'
#pragma warning(disable:4275)
#endif
namespace ceda
{
///////////////////////////////////////////////////////////////////////////////////////////////////
// PagedBufferToOutputStreamAdapter
class cxUtils_API PagedBufferToOutputStreamAdapter : public IOutputStream
{
cxNotCloneable(PagedBufferToOutputStreamAdapter)
public:
PagedBufferToOutputStreamAdapter(PagedBuffer& pb);
// Implementation of IOutputStream
virtual void WriteStream(const void* buffer, ssize_t numBytes);
virtual void FlushStream() {}
private:
PagedBuffer& m_pb;
};
///////////////////////////////////////////////////////////////////////////////////////////////////
// PagedBufferToInputStreamAdapter
class cxUtils_API PagedBufferToInputStreamAdapter : public ISeekableInputStream
{
cxNotCloneable(PagedBufferToInputStreamAdapter)
public:
PagedBufferToInputStreamAdapter(const PagedBuffer& pb);
// Implementation of IInputStream
virtual ssize_t ReadStream(void* buffer, ssize_t numBytesRequested);
// Implementation of ISeekableInputStream
virtual ssize_t GetStreamLength() const;
virtual ssize_t GetStreamPosition() const;
virtual void SetStreamPosition(ssize_t pos);
private:
const PagedBuffer& m_pb;
PagedBuffer::Reader m_reader;
};
} // namespace ceda
#endif // include guard