SophiaFramework UNIVERSE 5.3 |
#include <SFXStreamWriter.h.hpp>
class SFXStreamWriter : public SFXOutputStream;
SFMTYPEDEFCLASS(SFXStreamWriter)
The SFXStreamWriter class is used to write data into the stream of the storage.
According to the type of data to write, select one of the SFXBinaryStreamWriter / SFXAnsiStringStreamWriter / SFXWideStringStreamWriter class, which inherits from SFXStreamWriter.
In case of the variable buffer stream, the SFXElasticStreamWriter class is internally used. But you don't have to be aware of this class.
SFXBinaryStreamWriter | SFXAnsiStringStreamWriter | SFXWideStringStreamWriter | SFXElasticStreamWriter | SFXStreamReader | Stream | Storage
Constructor/Destructor |
---|
SFXStreamWriter( Void ) Constructor of the SFXStreamWriter class.
|
Public Functions | |
---|---|
Void |
Attach(
SFXOutputStreamPtr stream
) Attach the specified stream to this stream.
|
Void |
Cancel( Void ) Cancel to write onto this stream.
|
SFXOutputStreamPtr |
Detach( Void ) Detach the stream from this stream.
|
SFCError |
Flush( Void ) Write data in the stream buffer into the storage.
|
SFCError |
Flush(
CallbackSPP spp
, VoidPtr reference
) Write data in the stream buffer into the storage.
|
UInt32 |
GetWritableSize( Void ) Get the size of data that can be written into this stream. [in bytes]
|
Void |
Release( Void ) Release this stream.
|
SFCError |
ResetTrigger( Void ) Reset the trigger condition that the callback function will be booted up.
|
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.
|
SFCError |
Write(
SFXBufferConstRef buffer
) Write data onto the stream.
|
SFCError |
Write(
VoidConstPtr buffer
, UInt32 size
) Write data onto the stream.
|
Types |
---|
CallbackSPP
(inherits from SFXStream)
Type that represents the callback function.
|
[ public, explicit ] SFXStreamWriter(Void);
[ public ] Void Attach( SFXOutputStreamPtr stream // stream to set );
The stream which has been set to this stream before this function is called will be destroyed.
[ public, virtual ] Void Cancel(Void);
This function cancels to write onto 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 SFXStreamWriter::Flush function.
Note | |
---|---|
This function will be called internally in the SFXStreamWriter::Release function. |
SFXStreamWriter::Release | SFXStreamWriter::Flush | SFXFile::Cancel | SFXTCPSocket::Cancel
[ public ] SFXOutputStreamPtr Detach(Void);
Stream which has been attached to this stream
After this function is executed, no stream will be set to this stream.
[ public, virtual ] SFCError Flush(Void);
[ public, virtual ] SFCError Flush( CallbackSPP spp // callback function VoidPtr reference // data passed to the callback function );
This function writes data in the buffer of this stream into the storage set to 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 written into the storage immediately after this function is called.
If a callback function is registed with this function, it will be called immediately when data has been written(flushed) from the stream buffer into the storage. Any flush error will be passed to the 1st argument of the specified callback function. If this function returns the value other than SFERR_NO_ERROR, the specified callback function will not be called.
If no callback function is registed, data in the stream buffer will be written(flushed) into the storage immediately after this function is called.
Tip | |
---|---|
By calling the SFXStreamWriter::Write function, data will be written into the stream buffer. |
SFXStreamWriter::Write | SFXStreamWriter::SetTrigger | Stream Buffer | Storage
[ public, virtual, const ] UInt32 GetWritableSize(Void);
Size of data that can be written into the stream buffer. [in bytes]
This function gets the size of data that can be written into the stream buffer. [in bytes]
If the size of data to be written is larger than the return value of this function, it is necessary to divide data into chunks that can be written into the stream buffer and call the SFXStreamWriter::Write and SFXStreamWriter::Flush functions for each chunk in multiple times.
Note | |
---|---|
The physical size of the stream buffer is specified in the size argument of the GetStreamWriter function of the storage class. |
SFXStreamWriter::Write | SFXStreamWriter::Flush | Stream Buffer | Storage
[ public ] Void Release(Void);
This function cancels to write onto this stream and releases this stream.
Note | |
---|---|
This function will be called in the destructor of this stream. Also, it cancels to write onto this stream by calling the SFXStreamWriter::Cancel function. |
[ public, virtual ] SFCError ResetTrigger(Void);
This function resets the trigger condition set with the SFXStreamWriter::SetTrigger function.
[ public, virtual ] SFCError SetTrigger( UInt32 size // size of the data to write onto this stream );
[ public, virtual ] SFCError SetTrigger( SFXBufferConstRef buffer // data to write onto this stream );
[ public, virtual ] SFCError SetTrigger( VoidConstPtr buffer // data to write onto this stream UInt32 size // size of the data to write onto this stream );
The callback function registered by the SFXStreamWriter::Flush function will be booted up when data of the stream buffer is written into 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 specified size of data is written into this stream.
If the buffer argument is specified, the callback function will be booted up every time the specified data is written into this stream.
The code below is to boot up the callback function every time the line-feed character is written into the stream.
SetTrigger("\r\n", 2);
[ 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 SFXStreamWriter::SetTrigger function.
This function is used in the callback function to register with the SFXStreamWriter::Flush function.
[ public, virtual ] SFCError Write( SFXBufferConstRef buffer // writing data );
[ public, virtual ] SFCError Write( VoidConstPtr buffer // writing data UInt32 size // size of writing data );
This fucntion writes data specified in the buffer argument onto the buffer of this stream.
Note | |
---|---|
The physical size of the stream buffer is specified in the size argument of the GetStreamWriter function of the storage class. |
Caution | |
---|---|
If the size of data specified in the buffer (or size) argument bigger than SFXStreamWriter::GetWritableSize the return value of the SFXStreamWriter::GetWritableSize 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 SFXStreamWriter::Flush function, data in the stream buffer will be written into the storage set to the stream and the stream buffer will become empty. |
SFXStreamWriter::GetWritableSize | SFXStreamWriter::Flush | Stream Buffer | Storage
Copyright(c) 2002 - 2024 Sophia Cradle Incorporated All Rights Reserved. |