steereo:classes:steereostream

SteereoStream

Description

The SteereoStream manages a dynamic byte array and provides functions to append and get data out of it. As most kind of data can be stored into a SteereoStream is used for nearly all send and receive operations.

Usage and Functions

Normally you will use the streaming operators (« and ») to put data into the stream and to get data out of it. If no more data is available to read a warning will be issued. If you want to write something into a “full” stream, it tries to resize itself. You should allocate the needed memory before writing to the stream, otherwise you will have a resize of the stream after every written variable.
These functions are available besides the streaming operators:

  •  template<class C> SteereoStream& insertArray (C* cptr, int arrayLength) 

    Just inserts the array C of length arrayLength into the stream.

  •  template<class C> SteereoStream& receiveArray (C** cptr, int arrayLength) 

    This sets *cptr to the current reading position of the stream and advances the reading position afterwards. No copying is involved this way !

  •  template<class C> SteereoStream& receiveIntoExistingArray (C* cptr, int arrayLength) 

    copies arrayLength elements into the array C. Of course the array C should be big enough.

  •  void readBoolVector (std::vector<bool>& vec, int bytes) 

    reads the next bytes bytes into the given boolean vector.

  •  void adoptComplete (SteereoStream* comm) 
     void adoptRest (SteereoStream* comm) 

    Replace the current stream with the complete stream comm or from the current reading position on (that is the part that has not been read from comm yet).

  •  int getStreamSize () 
     int getRestStreamSize () 

    returns the current size of the stream or respectively the not yet read size of the stream.

  •  void resetReadPos () 

    With this the reading position of the stream will be reset. Thus the next elements read will be those from the beginning of the stream (again).

  •  void allocateMemory (int size) 

    allocates size bytes for the stream. It is recommended to allocate the needed size before writing to the stream, if the size is actually known. But this is not mandatory.

steereo/classes/steereostream.txt · Last modified: 2010/03/22 15:25 (external edit)