ADTF  3.18.2
cStream

The cStream Class provides a basic, simple implementation for IStream interface. More...

Inheritance diagram for cStream:
[legend]

Public Types

enum  tStreamType : uint8_t { INPUT_STREAM = 1 , OUTPUT_STREAM = 2 }
 Stream direction type. More...
 

Public Member Functions

 cStream (tStreamType eType, tFileSize szBuffer=0, uint32_t ui32Flags=0)
 Constructs a Stream with the current size. More...
 
virtual ~cStream ()
 Destructor.
 
tResult SetSize (tFileSize szBuffer, uint32_t ui32Flags=0)
 Sets the current size of the stream. More...
 
tResult CopyTo (cStream &strmOutput) const
 Copies a Stream to another. More...
 
tResult CopyFrom (cStream &strmInput)
 Copies content from another Stream. More...
 
const void * GetCurrentPtr () const
 Gets the address of the buffers current seek position. More...
 
tFileSize GetCurrentSize () const
 Returns the current buffer size. More...
 
tFileSize GetHighestPosIndex () const
 Returns the current buffer size which was written (without a gap at the end). More...
 
tResult AttachReference (void *pReferenceBuffer, tFileSize szBufferSize)
 Reference to a extern buffer (no intern buffer will be used to write to or read from). More...
 
tResult DetachReference ()
 Reference to a buffer will be detached. More...
 
tResult Read (void *pvBuffer, size_t nBufferSize, size_t *pnBytesRead=nullptr) const override
 Implements. More...
 
tResult Write (const void *pvBuffer, size_t nBufferSize, size_t *pnBytesWritten=nullptr) override
 Implements. More...
 
tResult Seek (tFilePos nPos, tSeekOrigin eOrigin, tFilePos *pNewPos=nullptr) const override
 Implements IStream::Seek. More...
 
tResult Reset () override
 Implements. More...
 
tResult Flush () override
 Implements. More...
 
- Public Member Functions inherited from object< IInputStream, IOutputStream, IStream >
tResult GetInterface (const char *i_strIID, void *&o_pInterface) override
 Query interfaces on an object. More...
 
tResult GetInterface (const char *i_strIID, const void *&o_pInterface) const override
 Provides const correct interface querying. More...
 
void Destroy () const override
 Destruct and deallocate instantiations of type IObject. More...
 
- Public Member Functions inherited from IObject
 ADTF_IID (IObject, "object.ant.ucom.adtf.iid")
 Marks the IObject to be castable with the ucom_cast() More...
 

Protected Types

enum  tStreamFlags { FLG_KEEP_POSITION = 1 , FLG_DONT_GROW = 2 }
 Stream flags. More...
 

Protected Member Functions

bool IsEof () const
 Checks if end of stream is reached. More...
 
tFileSize GetRemainingBytes () const
 
- Protected Member Functions inherited from IObject
 ~IObject ()=default
 Protected destructor --> Use implemented Destroy() instead of delete!
 

Protected Attributes

tStreamType m_eType
 Type of Stream, see tStreamType.
 

Private Member Functions

 cStream (const cStream &oStream)=delete
 
cStreamoperator= (const cStream &oStream)=delete
 
cStreamoperator= (cStream &&oStream)=delete
 
 cStream (cStream &&oStream)=delete
 

Detailed Description

The cStream Class provides a basic, simple implementation for IStream interface.

Definition at line 20 of file stream.h.

Member Enumeration Documentation

◆ tStreamFlags

enum tStreamFlags
protected

Stream flags.

Enumerator
FLG_KEEP_POSITION 

Sets correct end of file marker at.

See also
cStream::SetSize() call.
FLG_DONT_GROW 

Will only have the at construction time decided size.

Definition at line 43 of file stream.h.

◆ tStreamType

enum tStreamType : uint8_t

Stream direction type.

Enumerator
INPUT_STREAM 

Is a Input Stream (can be read).

OUTPUT_STREAM 

Is a Output Stream (can be written).

Definition at line 29 of file stream.h.

Constructor & Destructor Documentation

◆ cStream()

cStream ( tStreamType  eType,
tFileSize  szBuffer = 0,
uint32_t  ui32Flags = 0 
)
explicit

Constructs a Stream with the current size.

Parameters
eType[in] The In or Ouput Type.
szBuffer[in] The stream buffer size which will be preallocated.
ui32Flags[in] The creating flags (
See also
tStreamFlags).

Member Function Documentation

◆ AttachReference()

tResult AttachReference ( void *  pReferenceBuffer,
tFileSize  szBufferSize 
)

Reference to a extern buffer (no intern buffer will be used to write to or read from).

Mind: A SetSize will be failed, while a Buffer is attached!!

Parameters
pReferenceBufferReference to the extern buffer.
szBufferSizeSize of the Extern buffer.
Returns
Standard Result Code.

◆ CopyFrom()

tResult CopyFrom ( cStream strmInput)

Copies content from another Stream.

Parameters
strmInputThe Stream to copy from.
Returns
Standard Result Code.

◆ CopyTo()

tResult CopyTo ( cStream strmOutput) const

Copies a Stream to another.

Parameters
strmOutputThe Stream to copy to.
Returns
Standard Result Code.

◆ DetachReference()

tResult DetachReference ( )

Reference to a buffer will be detached.

See also
AttachReference.
Returns
Standard Result Code.

◆ Flush()

tResult Flush ( )
override

Implements.

See also
IStream::Flush. This function is not supported in the cStream implementation.
Returns
Standard Result Code.

◆ GetCurrentPtr()

const void* GetCurrentPtr ( ) const

Gets the address of the buffers current seek position.

Returns
The buffer address.
Note
rtsafe

◆ GetCurrentSize()

tFileSize GetCurrentSize ( ) const

Returns the current buffer size.

Returns
The buffer size.
Note
rtsafe

◆ GetHighestPosIndex()

tFileSize GetHighestPosIndex ( ) const

Returns the current buffer size which was written (without a gap at the end).

Returns
The current highest pos reached with the Write() call.
Note
rtsafe

◆ GetRemainingBytes()

tFileSize GetRemainingBytes ( ) const
protected
Returns
Remaing vount of bytes
Note
rtsafe

◆ IsEof()

bool IsEof ( ) const
protected

Checks if end of stream is reached.

Return values
trueEnd of stream reached
falseEnd of stream is not reached
Note
rtsafe

◆ Read()

tResult Read ( void *  pvBuffer,
size_t  nBufferSize,
size_t *  pnBytesRead = nullptr 
) const
override

Implements.

See also
IStream::Read. Will Read from the intern Buffer or extern reference attached.
Parameters
pvBufferreference address the cStream will copy the read data to.
nBufferSizesize of bytes to read.
pnBytesReadreturn value for size of bytes read.
Returns
Standard Result Code.
Note
rtsafe

◆ Reset()

tResult Reset ( )
override

Implements.

See also
IStream::Seek. Sets the current position in the stream to the begin.
Returns
Standard Result Code.
Note
rtsafe

◆ Seek()

tResult Seek ( tFilePos  nPos,
tSeekOrigin  eOrigin,
tFilePos pNewPos = nullptr 
) const
override

Implements IStream::Seek.

Sets the current position in the stream.

Parameters
nPosPosition to set to (in bytes).
eOriginIStream::tSeekOrigin.
pNewPosreturn value for the new position (same as
See also
GetCurrentPtr).
Returns
Standard Result Code.
Note
rtsafe

◆ SetSize()

tResult SetSize ( tFileSize  szBuffer,
uint32_t  ui32Flags = 0 
)

Sets the current size of the stream.

Parameters
szBuffer[in] The stream buffer size which will be allocated.
ui32Flags[in] The set size flags (
See also
tStreamFlags).
Returns
Standard Result Code.

◆ Write()

tResult Write ( const void *  pvBuffer,
size_t  nBufferSize,
size_t *  pnBytesWritten = nullptr 
)
override

Implements.

See also
IStream::Write. Writes to the intern buffer or extern reference attached.
Parameters
pvBufferreference address the cStream will copy the data from.
nBufferSizesize of bytes to write.
pnBytesWrittenreturn value for size of bytes written.
Returns
Standard Result Code.