PrevNextUpHome BREW C++ Class Library & GUI Framework & XML Middleware : SophiaFramework 4.1
SFXStreamReader
Class for accessing the input stream.
#include <SFXStreamReader.h.hpp>
class SFXStreamReader : public SFXInputStream;
SFMTYPEDEFCLASS(SFXStreamReader)

Inheritance diagram

 Inheritance diagram of SFXStreamReaderClass

Collaboration diagram

 Collaboration diagram of SFXStreamReaderClass

Description

The SFXStreamReader class is used to read data from the input stream such as file, TCP socket and so on.

According to the type of data to be read, select one among the following classes that inherit from the SFXStreamReader class: SFXBinaryStreamReader class, SFXAnsiStringStreamReader class, SFXWideStringStreamReader class.

Reference

SFXBinaryStreamReader | SFXAnsiStringStreamReader | SFXWideStringStreamReader | SFXStreamWriter

Member

Constructor/Destructor
SFXStreamReader( Void )
Constructor of SFXStreamReader class.
~SFXStreamReader( Void )
Destructor of SFXStreamReader class.
Public Functions
Void Attach( SFXInputStreamPtr stream )
Delegate the control privilege of SFXInputStream object to the SFXStreamReader object.
Void Cancel( Void )
Call the Cancel function for Storage class. And also unregister the callback functions.
SFXInputStreamPtr Detach( Void )
Delegate the control privilege of SFXStreamReader object to the SFXInputStream object.
Bool Ends( Void )
Check whether the stream ends or not.
SFCError Fetch( Void )
Fetch( CallbackSPP spp , VoidPtr reference )
Fetch for reading data newly.
SInt32 FirstIndexOf( Byte byte , SInt32 index = SINT32_MINIMUM )
FirstIndexOf( VoidConstPtr buffer , UInt32 size , SInt32 index = SINT32_MINIMUM )
FirstIndexOf( SFXBufferConstRef buffer , SInt32 index = SINT32_MINIMUM )
Get the first index of SFXStreamReader object to match with the specified data, searching from the beginning.
UInt32 GetReadableSize( Void )
Get the size of readable data.
SInt32 LastIndexOf( Byte byte , SInt32 index = SINT32_MAXIMUM )
LastIndexOf( VoidConstPtr buffer , UInt32 size , SInt32 index = SINT32_MAXIMUM )
LastIndexOf( SFXBufferConstRef buffer , SInt32 index = SINT32_MAXIMUM )
Get the last index of SFXStreamReader object to match with the specified data, searching from the end.
SFCError Read( SFXBufferPtr buffer )
Read( VoidPtr buffer , UInt32 size )
Read data from the stream.
Void Release( Void )
Release the stream.
SFCError ResetTrigger( Void )
Reset the trigger when the callback function will be called.
SFCError Seek( UInt32 size )
Move the read pointer foraward.
SFCError SetTrigger( UInt32 size )
SetTrigger( VoidConstPtr buffer , UInt32 size )
SetTrigger( SFXBufferConstRef buffer )
Set the trigger when the callback function will be called.
Bool Triggers( Void )
Check whether the callback function is called by trigger or not.
Types
CallbackSPP (inherits from SFXStream)
Constant that represents Callback function.

SFXStreamReader::SFXStreamReader
Constructor of SFXStreamReader class.
[ public, explicit ]
SFXStreamReader(Void);

SFXStreamReader::~SFXStreamReader
Destructor of SFXStreamReader class.
[ public, virtual ]
virtual ~SFXStreamReader(Void);

SFXStreamReader::Attach
Delegate the control privilege of SFXInputStream object to the SFXStreamReader object.
[ public ]
Void Attach(
    SFXInputStreamPtr stream   // stream to set
);

Description

The contents of SFXStreamReader object before calling the SFXStreamReader::Attach function will be destroyed.

What is delegation?: In object oriented programming, deligation means that an object have another deputy object behave like itself.

Reference

SFXStreamReader::Detach


SFXStreamReader::Cancel
Call the Cancel function for Storage class. And also unregister the callback functions.
[ public, virtual ]
Void Cancel(Void);

Description

Call the SFXFile::Cancel function for file, SFXTCPSocket::Cancel function for TCP socket, etc.

And also the callback functions registered by the SFXStreamReader::Fetch function are unregistered.

Reference

SFXStreamReader::Fetch | SFXFile::Cancel | SFXTCPSocket::Cancel


SFXStreamReader::Detach
Delegate the control privilege of SFXStreamReader object to the SFXInputStream object.
[ public ]
SFXInputStreamPtr Detach(Void);

Reference

SFXStreamReader::Attach


SFXStreamReader::Ends
Check whether the stream ends or not.
[ public, virtual, const ]
Bool Ends(Void);

Return value

  • If reach the end of stream, and there is no data to read : true
  • Otherwise : false

SFXStreamReader::Fetch
Fetch for reading data newly.
[ public, virtual ]
SFCError Fetch(Void);
[ public, virtual ]
SFCError Fetch(
    CallbackSPP spp     // callback function
    VoidPtr reference   // data sent to callback function
);

Return value

  • Success : SFERR_NO_ERROR
  • If argument is invalid : SFERR_INVALID_PARAM
  • If stream is not set, or the SFXStreamReader::Fetch function is under processing : SFERR_INVALID_STATE
  • If failed : SFERR_FAILED
  • Otherwise : The Error value that defined in AEEError.h

Description

There are two types of SFXStreamReader::Fetch functions: one is with the registration of callback function, and the other is without it. Which type of SFXStreamReader::Fetch function is available depends upon the storage of stream.

For example, only the type with the registration of callback function is availavle for TCP stream. However, both types can be used in the file stream.

In case of the SFXStreamReader::Fetch function without the registration of callback function, data is read into the internal buffer immediately after this function is called.

Reference

SFXStreamReader::SetTrigger


SFXStreamReader::FirstIndexOf
Get the first index of SFXStreamReader object to match with the specified data, searching from the beginning.
[ public, virtual, const ]
SInt32 FirstIndexOf(
    Byte byte                       // byte data to match with
    SInt32 index = SINT32_MINIMUM   // starting index to search from
);
[ public, virtual, const ]
SInt32 FirstIndexOf(
    SFXBufferConstRef buffer        // buffer object to match with
    SInt32 index = SINT32_MINIMUM   // starting index to search from
);
[ public, virtual, const ]
SInt32 FirstIndexOf(
    VoidConstPtr buffer             // buffer data to match with
    UInt32 size                     // size of buffer data to match with
    SInt32 index = SINT32_MINIMUM   // starting index to search from
);

Return value

  • Success : The first index where found.
  • If failed : -1

Description

To search from other than the beginning, specify the starting index to match with. (The origin index is 0.)

Reference

SFXStreamReader::LastIndexOf


SFXStreamReader::GetReadableSize
Get the size of readable data.
[ public, virtual, const ]
UInt32 GetReadableSize(Void);

Description

It is necessary to check the size of readable data by the SFXStreamReader::GetReadableSize function before calling the SFXStreamReader::Read function.

Reference

SFXStreamReader::Read


SFXStreamReader::LastIndexOf
Get the last index of SFXStreamReader object to match with the specified data, searching from the end.
[ public, virtual, const ]
SInt32 LastIndexOf(
    Byte byte                       // byte data to match with
    SInt32 index = SINT32_MAXIMUM   // starting index to search from
);
[ public, virtual, const ]
SInt32 LastIndexOf(
    SFXBufferConstRef buffer        // buffer object to match with
    SInt32 index = SINT32_MAXIMUM   // starting index to search from
);
[ public, virtual, const ]
SInt32 LastIndexOf(
    VoidConstPtr buffer             // buffer data to match with
    UInt32 size                     // size of buffer data to match with
    SInt32 index = SINT32_MAXIMUM   // starting index to search from
);

Return value

  • Success : The last index where found.
  • If failed : -1

Description

To search from other than the end, specify the starting index to match with. (The origin index is 0.)

Reference

SFXStreamReader::FirstIndexOf


SFXStreamReader::Read
Read data from the stream.
[ public, virtual ]
SFCError Read(
    SFXBufferPtr buffer   // buffer contains the reading data
);
[ public, virtual ]
SFCError Read(
    VoidPtr buffer   // pointer to the buffer contains the reading data
    UInt32 size      // size of the buffer contains the reading data
);

Return value

  • Success : SFERR_NO_ERROR
  • If the stream is not set : SFERR_INVALID_STATE
  • If argument is invalid : SFERR_INVALID_PARAM
  • If the size of data to be read exceeds the end of buffer : SFERR_FAILED

Description

The size of readable data can be gotten to call the SFXStreamReader::GetReadableSize function.

When receiving data by using the SFXBuffer class, set the size to receive data by the SFXBuffer::SetSize function.

Reference

SFXStreamReader::GetReadableSize


SFXStreamReader::Release
Release the stream.
[ public ]
Void Release(Void);

SFXStreamReader::ResetTrigger
Reset the trigger when the callback function will be called.
[ public, virtual ]
SFCError ResetTrigger(Void);

Return value

  • Success : SFERR_NO_ERROR
  • If the stream is not set, or the SFXStreamReader::Fetch function is under processing : SFERR_INVALID_STATE

Description

Reset the trigger set with the SFXStreamReader::SetTrigger function.

Reference

SFXStreamReader::SetTrigger | SFXStreamReader::Fetch


SFXStreamReader::Seek
Move the read pointer foraward.
[ public, virtual ]
SFCError Seek(
    UInt32 size   // forward size
);

Return value

  • Success : SFERR_NO_ERROR
  • If stream is not set : SFERR_INVALID_STATE
  • If failed : SFERR_FAILED

SFXStreamReader::SetTrigger
Set the trigger when the callback function will be called.
[ public, virtual ]
SFCError SetTrigger(
    UInt32 size   // data size to be read through input stream
);
[ public, virtual ]
SFCError SetTrigger(
    SFXBufferConstRef buffer   // SFXBuffer object to be read through input stream
);
[ public, virtual ]
SFCError SetTrigger(
    VoidConstPtr buffer   // data to be read through input stream
    UInt32 size           // size of data to be read through input stream
);

Return value

  • Success : SFERR_NO_ERROR
  • If the stream is not set, or the SFXStreamReader::Fetch function is under processing : SFERR_INVALID_STATE
  • If insufficient memory : SFERR_NO_MEMORY

Description

The callback function registered by the SFXStreamReader::Fetch function is called when the stream buffer is full or the end of data is read.

When the "size" parameter of SFXStreamReader::SetTrigger function is specified, callback function is called every time the "size" data is read.

When the "buffer" parameter of SFXStreamReader::SetTrigger function is specified, callback function is called every time the data same with "buffer" is read.

Example

The callback function is called every time the following line-feed character is read.

SetTrigger("\r\n", 2)

Reference

SFXStreamReader::ResetTrigger | SFXStreamReader::Fetch | SFXStreamReader::Triggers


SFXStreamReader::Triggers
Check whether the callback function is called by trigger or not.
[ public, virtual, const ]
Bool Triggers(Void);

Return value

Description

The SFXStreamReader::Triggers function is used for the callback function registered by the SFXStreamReader::Fetch function.

Reference

SFXStreamReader::SetTrigger | SFXStreamReader::ResetTrigger | SFXStreamReader::Fetch