![]() ![]() ![]()
|
BREW C++ Class Library & GUI Framework & XML Middleware : SophiaFramework 4.1 |


SFXMemory has an internal buffer that is read or written by the stream obtained by the SFXMemory::GetStreamReader or SFXMemory::GetStreamWriter function.
SFXMemory has the read/write pointer. In the SFXMemory::Read and SFXMemory::Write function, data is read and written through the pointer, which is moved by the amount of read/written data.
How to use the SFXMemory class
Example 478. Sample code for the memory stream
SFXMemory memory; SFXBinaryStreamWriter writer; // output stream for writing data to memory SFXBinaryStreamReader reader; // input stream for reading data from memory SFXAnsiString string; // variable to read data from memory storage // open memory storage if (memory.Open() == SFERR_NO_ERROR) { // get output stream for writing data to memory(buffer size is 1024) if (memory.GetStreamWriter(1024, &writer)== SFERR_NO_ERROR) { writer << "abc"; // write "abc" to output stream writer.Flush(); // write "abc" from output stream to memory storage // display data to write to memory storage on BREW Output Window TRACE("size = %d", memory.GetSize()); // display buffer size: "size = 4" TRACE("wrire = %s", memory.GetBuffer()); // display internal buffer: "write = abc + '\0'" writer.Release(); // release output stream } // seek at start memory.SeekStart(0); // get input stream for reading data from memory if (memory.GetStreamReader(1024, &reader) == SFERR_NO_ERROR) { reader.Fetch(); // read data from memory storage to input stream reader >> string; // read data from input stream to string // display data to read from memory storage on BREW Output Window TRACE("size = %d", string.GetLength()); // display string length: " size = 3" TRACE("read = %s", string.GetCString()); // display string: "read = abc" reader.Release(); // release input stream } memory.Close(); // close memory storage }
SFXBinaryStreamReader | SFXAnsiStringStreamReader | SFXWideStringStreamReader | SFXBinaryStreamWriter | SFXAnsiStringStreamWriter | SFXWideStringStreamWriter
| Constructor/Destructor |
|---|
|
SFXMemory( Void ) Constructor of SFXMemory class.
|
|
SFXMemory(
UInt16 threshold
, UInt16 cluster
) Constructor of SFXMemory class.
|
|
~SFXMemory( Void ) Destructor of SFXMemory class.
|
| Public Functions | |
|---|---|
| Void |
Cancel( Void ) [ This function cannot be used now. ]
|
| SFCError |
Close(
SFXBufferPtr buffer
) Close the memory.
|
| Void |
Close( Void ) Close the memory.
|
| VoidConstPtr |
GetBuffer( Void ) Get the pointer to the internal buffer.
|
| UInt16 |
GetCluster( Void ) Get the cluster size of the buffer memory used internally.
|
| UInt32 |
GetSize( Void ) Get the size of the buffer used internally.
|
| SFCError |
GetStreamReader(
UInt32 size
, SFXStreamReaderPtr result
) GetStreamReader( SFXStreamReaderPtr result ) Get the input stream for reading data from memory storage.
|
| SFCError |
GetStreamWriter(
UInt32 size
, SFXStreamWriterPtr result
) GetStreamWriter( SFXStreamWriterPtr result ) Get the output stream for writing data to memory storage.
|
| UInt16 |
GetThreshold( Void ) Get the minimum value of internal buffer size.
|
| SFCError |
Open(
SFXBufferConstRef buffer
) Open( Void ) Open( VoidConstPtr buffer , UInt32 size ) Open the memory storage.
|
| SFCError |
Read(
VoidPtr buffer
, UInt32Ptr size
) Read data from memory storage without using the input stream.
|
| SFCError |
ScheduleRead(
CallbackSPP spp
, VoidPtr reference
) [ This function cannot be used now. ]
|
| SFCError |
ScheduleWrite(
CallbackSPP spp
, VoidPtr reference
) [ This function cannot be used now. ]
|
| SFCError |
Seek(
SInt32 distance
) Move the memory pointer by the specified amount from the current position.
|
| SFCError |
SeekEnd(
SInt32 distance
) Move the memory pointer by the specified amount from the end position of buffer.
|
| SFCError |
SeekStart(
SInt32 distance
) Move the memory pointer by the specified amount from the start position of buffer.
|
| Void |
SetCluster(
UInt16 size
) Set the cluster size of internal buffer memory.
|
| Void |
SetThreshold(
UInt16 size
) Set the minimum value of internal buffer size.
|
| UInt32 |
Tell( Void ) Get the current position of the read/write pointer.
|
| SFCError |
Truncate(
UInt32 position
) Truncate the internal buffer with the specified size.
|
| SFCError |
Write(
VoidConstPtr buffer
, UInt32Ptr size
) Write data to memory storage without using the output stream.
|
| Types |
|---|
|
DefaultEnum Enumeration type of initial value of each parameter regarding the memory storage.
|
|
CallbackSPP
(inherits from SFXStorage)
The prototype of the callback function for the SFXStorage class.
|
[ public, explicit ] SFXMemory(Void);
[ public, explicit ]
SFXMemory(
UInt16 threshold // internal buffer's threshold
UInt16 cluster // internal buffer's cluster size
);
An internal buffer is allocated.
[ public, virtual ] virtual ~SFXMemory(Void);
[ public, virtual ] Void Cancel(Void);
[ public ] SFCError Close( SFXBufferPtr buffer // pointer to the buffer );
[ public ] Void Close(Void);
If the argument is not specified, nothing is returned.
If SFXBufferPtr is specified for the argument, error value is returned.
If the argument is not specified, internal buffer will be released.
If the buffer of SFXBufferPtr type is specified as an argument, the internal buffer is copied to the specified buffer and then released.
[ public, const ] VoidConstPtr GetBuffer(Void);
[ public, const ] UInt16 GetCluster(Void);
[ public, const ] UInt32 GetSize(Void);
[ public, virtual ] SFCError GetStreamReader( UInt32 size // buffer size SFXStreamReaderPtr result // pointer to the input stream for reading data from memory storage );
[ public, virtual ] SFCError GetStreamReader( SFXStreamReaderPtr result // pointer to the input stream for reading data from memory storage );
The buffer size of the input stream can be specified. Use the SFXBinaryStreamReader, SFXAnsiStringStreamReader, or SFXWideStringStreamReader class for the input stream properly according to the type of data to read.
SFXMemory::GetStreamWriter | SFXBinaryStreamReader | SFXAnsiStringStreamReader | SFXWideStringStreamReader
[ public, virtual ] SFCError GetStreamWriter( UInt32 size // size SFXStreamWriterPtr result // pointer to the output stream for writing data to memory storage );
[ public, virtual ] SFCError GetStreamWriter( SFXStreamWriterPtr result // pointer to the output stream for writing data to memory storage );
The buffer size of the output stream can be specified. Use the SFXBinaryStreamWriter, SFXAnsiStringStreamWriter, or SFXWideStringStreamWriter class for the output stream properly according to the written data type
SFXMemory::GetStreamReader | SFXBinaryStreamWriter | SFXAnsiStringStreamWriter | SFXWideStringStreamWriter
[ public, const ] UInt16 GetThreshold(Void);
[ public ] SFCError Open( SFXBufferConstRef buffer // buffer to be copied );
[ public ] SFCError Open( VoidConstPtr buffer // buffer to be copied UInt32 size // size of the buffer to be copied );
[ public ] SFCError Open(Void);
Initialize to use the memory storage. If the buffer is specified as an argument, the specified buffer is copied to the internal buffer. If the argument is not specified, the internal buffer is empty (size 0).
[ public, virtual ] SFCError Read( VoidPtr buffer // buffer to read data from memory storage UInt32Ptr size // bufer size );
Specify the buffer to read data from memory storage.
Specify the size of buffer when calling SFXMemory::Read function. When the SFXMemory::Read function ends, the size of data that is actually read is stored.
SFXMemory::Write | SFXMemory::GetSize | SFXMemory::Seek | SFXMemory::Tell
[ public, virtual ] SFCError ScheduleRead( CallbackSPP spp // callback function VoidPtr reference // data passed to callback function );
SFERR_UNSUPPORTED is returned.
[ public, virtual ] SFCError ScheduleWrite( CallbackSPP spp // callback function VoidPtr reference // data passed to callback function );
Return SFERR_UNSUPPORTED.
To move the memory pointer backward, set negative value as moving amount to the distance argument.
If the poition of memory pointer after moved by this function is under the start of buffer or over the end of buffer, it will be set to the start or end of buffer respectively.
To move the memory pointer backward, set negative value as moving amount to the distance argument.
If the poition of memory pointer after moved by this function is under the start of buffer or over the end of buffer, it will be set to the start or end of buffer respectively.
To move the memory pointer backward, set negative value as moving amount to the distance argument.
If the poition of memory pointer after moved by this function is under the start of buffer or over the end of buffer, it will be set to the start or end of buffer respectively.
Set the minimum unit size when allocating the internal buffer.
[ public, const ] UInt32 Tell(Void);
The read/write pointer will be moved to the end position of buffer truncated using the SFXMemory::Truncate function when the current pointer is over the end of buffer.
[ public, virtual ] SFCError Write( VoidConstPtr buffer // buffer to write data to memory storage UInt32Ptr size // size of data to write to memory storage );
Specify the buffer to write data to memory storage.
Specify the size of data to write to memory storage when calling the SFXMemory::Write function. When the SFXMemory::Write function ends, the size of data that is actually written is stored.
SFXMemory::Read | SFXMemory::GetSize | SFXMemory::Seek | SFXMemory::Tell
enum DefaultEnum {
DEFAULT_THRESHOLD = SFXBuffer::DEFAULT_THRESHOLD,
DEFAULT_CLUSTER = SFXBuffer::DEFAULT_CLUSTER
};
|
Copyright (C) 2002 - 2009 Sophia Cradle, Inc. All Rights Reserved. |
![]() ![]() ![]()
|