SophiaFramework UNIVERSE 5.3 |
#include <SFXElasticStreamReader.h.hpp>
class SFXElasticStreamReader : public SFXInputStream;
SFMTYPEDEFCLASS(SFXElasticStreamReader)
What is SFXElasticStreamReader?
The SFXElasticStreamReader class is internally used to read data from the stream with the elastic buffer.
If the SFXBinaryStreamReader / SFXAnsiStringStreamReader / SFXWideStringStreamReader instance is gotten (or set) with the GetStreamReader function of the storage class without specifying the size argument(i.e., buffer size), the stream buffer will be elastic.
At this time, internally, the SFXElasticStreamReader stream will be attached to the SFXBinaryStreamReader / SFXAnsiStringStreamReader / SFXWideStringStreamReader stream with the SFXElasticStreamReader::Attach function. By this operation, data will be read from the stream using the elastic buffer.
The buffer will automatically expanded to the same size of data to be read.
Note | |
---|---|
In general, you don't have to use the SFXElasticStreamReader class explicitly since the processing of reading data from the stream with the elastic buffer has already been implemented. |
SFXBinaryStreamReader | SFXAnsiStringStreamReader | SFXWideStringStreamReader | SFXElasticStreamWriter
Constructor/Destructor |
---|
SFXElasticStreamReader( Void ) Constructor of the SFXElasticStreamReader class.
|
~SFXElasticStreamReader( Void ) Destructor of the SFXElasticStreamReader class.
|
Public Functions | |
---|---|
Void |
Attach(
SFXInputStreamPtr stream
) Attach the specified stream to this stream.
|
Void |
Cancel( Void ) Cancel to read from this stream.
|
SFXInputStreamPtr |
Detach( Void ) Detach the stream from this stream.
|
Bool |
Ends( Void ) Check whether or not the read pointer reaches the end of this stream.
|
SFCError |
Fetch( Void ) Fetch for reading data newly.
|
SFCError |
Fetch(
CallbackSPP spp
, VoidPtr reference
) Fetch for reading data newly.
|
SInt32 |
FirstIndexOf(
Byte byte
, SInt32 index = SINT32_MINIMUM
) Get the first index to match the specified data, searching from the head of the stream buffer.
|
SInt32 |
FirstIndexOf(
SFXBufferConstRef buffer
, SInt32 index = SINT32_MINIMUM
) Get the first index to match the specified data, searching from the head of the stream buffer.
|
SInt32 |
FirstIndexOf(
VoidConstPtr buffer
, UInt32 size
, SInt32 index = SINT32_MINIMUM
) Get the first index to match the specified data, searching from the head of the stream buffer.
|
UInt32 |
GetReadableSize( Void ) Get the size of data that can be read from this stream. [in bytes]
|
SInt32 |
LastIndexOf(
Byte byte
, SInt32 index = SINT32_MAXIMUM
) Get the last index to match the specified data, searching from the tail of the stream buffer.
|
SInt32 |
LastIndexOf(
SFXBufferConstRef buffer
, SInt32 index = SINT32_MAXIMUM
) Get the last index to match the specified data, searching from the tail of the stream buffer.
|
SInt32 |
LastIndexOf(
VoidConstPtr buffer
, UInt32 size
, SInt32 index = SINT32_MAXIMUM
) Get the last index to match the specified data, searching from the tail of the stream buffer.
|
SFCError |
Read(
SFXBufferPtr buffer
) Read data from the input stream.
|
SFCError |
Read(
VoidPtr buffer
, UInt32 size
) Read data from the input stream.
|
Void |
Release( Void ) Release this stream.
|
SFCError |
ResetTrigger( Void ) Reset the trigger condition that the callback function will be booted up.
|
SFCError |
Seek(
UInt32 size
) Move the read pointer forward.
|
SFCError |
SetTrigger(
UInt32 size
) Set the trigger condition that the callback function will be booted up.
|
SFCError |
SetTrigger(
SFXBufferConstRef buffer
) Set the trigger condition that the callback function will be booted up.
|
SFCError |
SetTrigger(
VoidConstPtr buffer
, UInt32 size
) Set the trigger condition that the callback function will be booted up.
|
Bool |
Triggers( Void ) Check whether or not the callback function is booted up by the trigger condition.
|
Types |
---|
CallbackSPP
(inherits from SFXStream)
Type that represents the callback function.
|
[ public, explicit ] SFXElasticStreamReader(Void);
[ public, virtual ] virtual ~SFXElasticStreamReader(Void);
[ public ] Void Attach( SFXInputStreamPtr stream // stream to set );
The stream and the elastic buffer which have been set to this stream before this function is called will be destroyed.
[ public, virtual ] Void Cancel(Void);
This function cancels to read from this stream.
Concretely, the following operations are performed internally.
Call the Cancel function of the storage class associated with this stream.
In case of the file storage, the SFXFile::Cancel function will be called. In case of the TCP socket storage, the SFXTCPSocket::Cancel function will be called.
Unregister the callback functions registered into this stream with the SFXElasticStreamReader::Fetch function.
Note | |
---|---|
This function will be called internally in the SFXElasticStreamReader::Release function. |
SFXElasticStreamReader::Fetch | SFXFile::Cancel | SFXTCPSocket::Cancel
[ public ] SFXInputStreamPtr Detach(Void);
Stream which has been attached to this stream
After this function is executed, no stream will be set to this stream. And the elastic buffer will be destroyed.
[ public, virtual, const ] Bool Ends(Void);
This function checks whether or not the read pointer reaches the end of this stream.
If the read pointer reaches the end of this stream buffer and no more data can be read from the storage set to this stream, "true" will be returned. Otherwise "false" will be returned.
[ public, virtual ] SFCError Fetch(Void);
[ public, virtual ] SFCError Fetch( CallbackSPP spp // callback function VoidPtr reference // data passed to the callback function );
This function reads data from the storage set to this stream into the buffer of this stream.
There are two types of this function: one registers a callback function and another does not. Which type is available depends on the kind of the storage.
For instance, only the type to registet a callback function is availavle for the stream set to the SFXTCPSocket storage. However, both types are available for the stream to the SFXFile storage.
In case of the type not to registet a callback function, data in the stream buffer will be read from the storage immediately after this function is called.
Tip | |
---|---|
By calling the SFXElasticStreamReader::Read function, data will be read from the stream buffer. |
SFXElasticStreamReader::Read | SFXElasticStreamReader::SetTrigger | Stream Buffer | Storage
[ public, virtual, const ] SInt32 FirstIndexOf( Byte byte // data to match SInt32 index = SINT32_MINIMUM // beginning index to search from );
[ public, virtual, const ] SInt32 FirstIndexOf( SFXBufferConstRef buffer // data to match SInt32 index = SINT32_MINIMUM // beginning index to search from );
[ public, virtual, const ] SInt32 FirstIndexOf( VoidConstPtr buffer // data to match UInt32 size // size of the data to match SInt32 index = SINT32_MINIMUM // beginning index to search from );
This fucntion gets the first index to match the specified data, searching from the head of the stream buffer.
By specifying the beginning index, you can search from the position other than the head.
Note | |
---|---|
The index of the head of the stream buffer is 0. |
[ public, virtual, const ] UInt32 GetReadableSize(Void);
Size of data that can be read from the stream buffer [in bytes]
This function gets the size of data that can be read from the stream buffer. [in bytes]
Note | |
---|---|
The physical size of the stream buffer is specified in the size argument of the GetStreamReader function of the storage class. |
SFXElasticStreamReader::Read | SFXElasticStreamReader::Fetch | Stream Buffer | Variable Buffer Stream | Storage
[ public, virtual, const ] SInt32 LastIndexOf( Byte byte // data to match SInt32 index = SINT32_MAXIMUM // beginning index to search from );
[ public, virtual, const ] SInt32 LastIndexOf( SFXBufferConstRef buffer // data to match SInt32 index = SINT32_MAXIMUM // beginning index to search from );
[ public, virtual, const ] SInt32 LastIndexOf( VoidConstPtr buffer // data to match UInt32 size // size of the data to match SInt32 index = SINT32_MAXIMUM // beginning index to search from );
This fucntion gets the last index to match the specified data, searching from the tail of the stream buffer.
By specifying the beginning index, you can search from the position other than the tail.
Note | |
---|---|
The index of the head of the stream buffer is 0. |
[ public, virtual ] SFCError Read( SFXBufferPtr buffer // buffer to read data into );
[ public, virtual ] SFCError Read( VoidPtr buffer // pointer to the buffer to read data into UInt32 size // size of the buffer to read data into );
This fucntion reads data from the buffer of this stream into the variable specified in the argument.
The size of data that can be read is gotten with the SFXElasticStreamReader::GetReadableSize function.
Caution | |
---|---|
When using the buffer argument of the SFXBuffer type, it is necessary to set the size of data that will be read from this stream with the SFXBuffer::SetSize function. If the buffer argument is null, the size argument is less than or equals 0, or, the size of data specified on the buffer (or size) argument is bigger than the return value of the SFXElasticStreamReader::GetReadableSize function, SFERR_FAILED will be returned. If the stream buffer contains some of the memory region specified in the buffer argument, SFERR_INVALID_PARAM will be returned. |
Tip | |
---|---|
By calling the SFXElasticStreamReader::Fetch function, data will be read from the storage set to the stream into the stream buffer. |
SFXElasticStreamReader::GetReadableSize | SFXElasticStreamReader::Fetch | Stream Buffer | Variable Buffer Stream | Storage
[ public ] Void Release(Void);
This function cancels to read from this stream and releases this stream.
Note | |
---|---|
This function will be called in the destructor of this stream. Also, it cancels to read from this stream by calling the SFXElasticStreamReader::Cancel function. |
[ public, virtual ] SFCError ResetTrigger(Void);
This function resets the trigger condition set with the SFXElasticStreamReader::SetTrigger function.
SFXElasticStreamReader::SetTrigger | SFXElasticStreamReader::Triggers | SFXElasticStreamReader::Fetch
This function moves forward the read pointer which is for reading data from the stream buffer.
[ public, virtual, const ] Bool Triggers(Void);
This function checks whether or not the callback function is booted up by the trigger condition set with the SFXElasticStreamReader::SetTrigger function.
This function is used in the callback function to register with the SFXElasticStreamReader::Fetch function.
SFXElasticStreamReader::SetTrigger | SFXElasticStreamReader::ResetTrigger | SFXElasticStreamReader::Fetch
[ public, virtual ] SFCError SetTrigger( UInt32 size // size of the data to be read from this stream );
[ public, virtual ] SFCError SetTrigger( SFXBufferConstRef buffer // data to be read from this stream );
[ public, virtual ] SFCError SetTrigger( VoidConstPtr buffer // data to be read from this stream UInt32 size // size of data to be read from this stream );
The callback function registered by the SFXElasticStreamReader::Fetch function will be booted up when no more data is left to read from the storage set to this stream.
This function sets the trigger condition that the callback function will be booted up other than the above timing.
If only the size argument is specified, the callback function will be booted up every time the size of data specified in the argument is read from this stream.
If the buffer argument is specified, the callback function will be booted up every time the data specified in the arguments is read from this stream.
The code below is to boot up the callback function every time the line-feed character is read from the stream.
SetTrigger("\r\n", 2);
Copyright(c) 2002 - 2024 Sophia Cradle Incorporated All Rights Reserved. |