Pyro higlevel API
Classes | Public Member Functions | List of all members
os::MemFile Class Reference

Virtual stream object. More...

Inheritance diagram for os::MemFile:
os::SeekableIO os::StreamableIO

Classes

class  Private
 

Public Member Functions

 MemFile ()
 Default constructor. More...
 
 MemFile (const void *pData, uint32 nLen)
 Constructor. More...
 
 ~MemFile ()
 
virtual ssize_t Read (void *pBuffer, ssize_t nSize)
 
virtual ssize_t Write (const void *pBuffer, ssize_t nSize)
 
virtual ssize_t ReadPos (off_t nPos, void *pBuffer, ssize_t nSize)
 
virtual ssize_t WritePos (off_t nPos, const void *pBuffer, ssize_t nSize)
 
virtual off_t Seek (off_t nPos, int nMode)
 
virtual void SetSize (uint32 nSize)
 Set the size of the internal buffer. More...
 
- Public Member Functions inherited from os::SeekableIO
virtual ~SeekableIO ()
 
- Public Member Functions inherited from os::StreamableIO
virtual ~StreamableIO ()
 

Detailed Description

Description:
This class simulates a SeekableIO object in memory. It may be used to capture data that would normally be sent to a file, or it may be used to supply compiled-in data, or data retrieved elsewhere to an object that expects a stream or file.

One possible application would be to decode data received from an HTTP link, with the BitmapImage class' Load() method.

See Also
os::StreamableIO, os::SeekableIO, os::BitmapImage
Author
Henrik Isaksson (henri.nosp@m.k@bo.nosp@m.ing.n.nosp@m.u)

Constructor & Destructor Documentation

MemFile::MemFile ( )
Description:
Initializes a MemFile object to default values (ie. an empty MemFile).
MemFile::MemFile ( const void *  pData,
uint32  nLen 
)
Description:
Creates a MemFile object with the data you specify. The data is not copied, unless the object is written to. This reduces overhead, since the data will often be static.
If the object is written to, memory is allocated and the data is copied to the newly allocated memory. Your original data will not be affected in any way.
Parameters
pDataPointer to the data you want to access as a stream.
nLenLength of the data.
Example:
const char bitmap[] = {
// Bitmap data
};
MemFile cBitmapStream( bitmap, sizeof( bitmap ) );
// Now cBitmapStream may be used like an ordinary stream object:
Image *cImg = new BitmapImage( &cBitmapStream );
Note
The object pointed to by pData must live as long as the MemFile object lives. (That is, unless you force MemFile to move it into it's own memory, with a dummy write).
Author
Henrik Isaksson (henri.nosp@m.k@bo.nosp@m.ing.n.nosp@m.u)

References os::MemFile::Private::m_nEOF, os::MemFile::Private::m_nSize, os::MemFile::Private::m_psFirst, and os::MemFile::Private::m_psLast.

MemFile::~MemFile ( )

Member Function Documentation

ssize_t MemFile::Read ( void *  pBuffer,
ssize_t  nSize 
)
virtual
ssize_t MemFile::ReadPos ( off_t  nPos,
void *  pBuffer,
ssize_t  nSize 
)
virtual
off_t MemFile::Seek ( off_t  nPos,
int  nMode 
)
virtual
void MemFile::SetSize ( uint32  nSize)
virtual
Description:
Set the size of the internal buffer. Any data past the end of new buffer will be discarded. Setting the buffer size to 0 will cause the MemFile object to free all allocated memory.
You may want to set a default buffer size, to optimize performance and reduce overhead. Normally, the buffer will be allocated incrementally, as needed, with at least MIN_BLOCKSIZE (currently 1 kbyte, but this may change in future versions).
Example:
If you know you will be writing at most 500 bytes, it makes sense to set the buffer to 500 bytes.
If you know you will be writing at least 200 k, it makes sense to set the buffer to 200 k. Even if you write more, you will still have reduced the number of blocks required.
Parameters
nSizeThe new buffer size.
Author
Henrik Isaksson (henri.nosp@m.k@bo.nosp@m.ing.n.nosp@m.u)

References os::MemFile::Private::SetBfrSize().

ssize_t MemFile::Write ( const void *  pBuffer,
ssize_t  nSize 
)
virtual
ssize_t MemFile::WritePos ( off_t  nPos,
const void *  pBuffer,
ssize_t  nSize 
)
virtual