Class Ecrion.Ultrascale.Stream

Top Previous Topic Next Topic  Print this topic

The Stream class is a generic stream interface. The user must implement this interface in order to supply input to the engine or to get the output.

 

 

class Stream

{

public:

       virtual size_t read(unsigned char* destination, size_t bytesCountToRead) = 0;

       virtual size_t write(const unsigned char* source, size_t bytesCountToWrite) = 0;

       virtual size_t length() = 0;

       virtual int seek(int offset, int position) = 0;

};

 

 

 

Interface Methods

 

Name

Description

read

Read from the stream.

write

Write to the stream.

length

Get the length of the stream.

seek

Set the position indicator associated with the stream to a new position.

 

 

read

Reads from the stream.

 

 

       virtual size_t read(unsigned char* destination, size_t bytesCountToRead) = 0;

 

                       

Parameters

 

destination

       Where to store the bytes read.

bytesCountToRead

       The number of bytes that should be read.

 

Return Value

 

The number of bytes read.

 

 

write

Writes to the stream.

 

 

       virtual size_t write(const unsigned char* source, size_t bytesCountToWrite) = 0;

 

                       

Parameters

 

source

       The source for writing

bytesCountToWrite

       The number of bytes that should be written.

 

Return Value

 

The number of bytes written.

 

 

length

Get the length of the stream.

 

 

       virtual size_t length() = 0;

 

                       

Return Value

 

The length of the stream.

 

 

seek

Set the position indicator associated with the stream to a new position defined by adding offset to a reference position specified by position.

 

 

       virtual int seek(int offset, int position) = 0;

 

                       

Parameters

 

offset

       The number of bytes to offset from position

position

       Origin from where the offset is added. It is specified by one of the following constants defined in <stdio.h>:

SEEK_SET

Beginning of the stream

SEEK_CUR

Current position in the stream

SEEK_END

End of the stream

 

Return Value

 

If successful, returns a zero value. Otherwise, returns a nonzero value.

 

 

The FileStream Class

 

A sample FileStream class is included that implements the Stream interface. Its constructor is detailed below:

 

 

       FileStream(const String filePath, bool write = false, bool create = false, bool append = false);

 

 

Parameters

 

filePath

       A string representing the path to the file on the disk

write

       Specifies whether the application will read from or write into the file

create

       If write is set to true, this specifies whether or not to create the file if it does not exist

append

       If write is set to true, this specifies whether to append to the existing file or overwrite all its contents