MemoryFile.h
// MemoryFile.h
//
// Author David Barrett-Lennard
// (C)opyright Cedanet Pty Ltd 2004
#pragma once
#ifndef Ceda_cxUtils_MemoryFile_H
#define Ceda_cxUtils_MemoryFile_H
#ifdef _WIN32
#include "cxUtils.h"
#include "MsWindows.h"
#include "File.h"
namespace ceda
{
///////////////////////////////////////////////////////////////////////////////////////////////////
// MemoryFile
// Implementation of a memory file with the WIN32 global memory allocation routines.
class cxUtils_API MemoryFile : public IFile
{
cxNotCloneable(MemoryFile)
public:
// Constructor for writing a new memory chunk
MemoryFile(EFileDirection direction, unsigned int uFlags, HGLOBAL hMem);
// Constructor for reading an existing memory chunk
MemoryFile(EFileDirection direction, HGLOBAL hMem);
~MemoryFile();
// Implementation of IInputStream
virtual ssize_t ReadStream(void* buffer, ssize_t numBytes);
// Implementation of ISeekableInputStream
virtual ssize_t GetStreamLength() const;
virtual ssize_t GetStreamPosition() const;
virtual void SetStreamPosition(ssize_t pos);
// Implementation of IOutputStream
virtual void WriteStream(const void* buffer, ssize_t numBytes);
virtual void FlushStream();
// Implementation of IFile
virtual void Close();
virtual EFileDirection Direction() const;
HGLOBAL GetMemoryBlock();
private:
EFileDirection m_direction;
HGLOBAL m_hMem;
ssize_t m_capacity;
ssize_t m_position;
unsigned int m_flags;
bool m_freeMemoryInDestructor;
};
} // namespace ceda
#endif // _WIN32
#endif // include guard