V
vrishba
Hi,
Suppose we have
class CAbstractFile {
public:
virtual bool Open()=0;
virtual bool Read(long num_bytes,void *bufferp)=0;
virtual bool Write(long num_bytes,void *bufferp)=0;
virtual bool Close()=0;
};
class CDiskFile : public CAbstractFile {
private:
CString Path;
HANDLE Handle;
public:
// all implemented in CDiskFile.cpp
void SetPath(CString path);
virtual bool Open();
virtual bool Read(long num_bytes,void *bufferp);
virtual bool Write(long num_bytes,void *bufferp);
virtual bool Close();
};
class CRamFile : public CAbstractFile {
private:
void *BufferStart;
long BufferLength;
long Position;
public:
// all implemented in CRamFile.cpp
void SetRamBuffer(void *startp,long length);
virtual bool Open();
virtual bool Read(long num_bytes,void *bufferp);
virtual bool Write(long num_bytes,void *bufferp);
virtual bool Close();
};
Now i want to derive a new class CJpegFile that implements reading &
writing of Jpeg files.
I want that CJpegFile object can be a CDiskFile or a CRamFile,
so that we can read/write a jpeg file as well via a diskfile as well
via a ramfile.
How should this be done in good C++?
I can't find the answer, and i'm sorry if this is a stupid question.
Cheers,
Vrish
Suppose we have
class CAbstractFile {
public:
virtual bool Open()=0;
virtual bool Read(long num_bytes,void *bufferp)=0;
virtual bool Write(long num_bytes,void *bufferp)=0;
virtual bool Close()=0;
};
class CDiskFile : public CAbstractFile {
private:
CString Path;
HANDLE Handle;
public:
// all implemented in CDiskFile.cpp
void SetPath(CString path);
virtual bool Open();
virtual bool Read(long num_bytes,void *bufferp);
virtual bool Write(long num_bytes,void *bufferp);
virtual bool Close();
};
class CRamFile : public CAbstractFile {
private:
void *BufferStart;
long BufferLength;
long Position;
public:
// all implemented in CRamFile.cpp
void SetRamBuffer(void *startp,long length);
virtual bool Open();
virtual bool Read(long num_bytes,void *bufferp);
virtual bool Write(long num_bytes,void *bufferp);
virtual bool Close();
};
Now i want to derive a new class CJpegFile that implements reading &
writing of Jpeg files.
I want that CJpegFile object can be a CDiskFile or a CRamFile,
so that we can read/write a jpeg file as well via a diskfile as well
via a ramfile.
How should this be done in good C++?
I can't find the answer, and i'm sorry if this is a stupid question.
Cheers,
Vrish