libqi-api  2.1.4.13
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Friends | List of all members
qi::Buffer Class Reference

Class to store buffer. More...

#include <buffer.hpp>

Public Member Functions

 Buffer ()
 Default constructor. More...
 
 Buffer (const Buffer &b)
 Copy constructor. More...
 
Bufferoperator= (const Buffer &b)
 Assignment operator. More...
 
bool write (const void *data, size_t size)
 Write data in the buffer. More...
 
size_t addSubBuffer (const Buffer &buffer)
 Add a sub-buffer to the main buffer. More...
 
bool hasSubBuffer (size_t offset) const
 Check if there is a sub-buffer at given offset. More...
 
const BuffersubBuffer (size_t offset) const
 Return the sub-buffer at given offset. More...
 
size_t size () const
 Return the content size of this buffer not counting sub-buffers. More...
 
size_t totalSize () const
 Return the content size of this buffer and of all its sub-buffers. More...
 
const std::vector< std::pair
< size_t, Buffer > > & 
subBuffers () const
 Return a vector of sub-buffers of the current buffer. More...
 
void * reserve (size_t size)
 Reserve bytes at the end of current buffer. More...
 
void clear ()
 Erase content of buffer and remove sub-buffers whithout clearing them. More...
 
void * data ()
 Return a pointer to the raw data storage of this buffer. More...
 
const void * data () const
 Return a const pointer to the raw data in this buffer. More...
 
const void * read (size_t offset=0, size_t length=0) const
 Read some data from the buffer. More...
 
size_t read (void *buffer, size_t offset=0, size_t length=0) const
 Read some data in the buffer and store it in a new pre-allocated buffer. More...
 

Friends

class BufferReader
 

Detailed Description

Class to store buffer.

* This class can store buffer and sub-buffers.
* Here is a representation of internal management of sub-buffers.
*
* .. graphviz::
*
*      digraph g {
*          graph [ rankdir = "LR" ];
*          node [ fontsize = "16", shape = "ellipse" ];
*
*          subgraph cluster_buffer {
*              mainbuffer;
*              label = "Main buffer";
*          }
*
*          subgraph cluster_subbuffer1 {
*              subbuffer1;
*              label = "Sub-buffer 1";
*          }
*
*          subgraph cluster_subbuffer2 {
*              subbuffer2;
*              label = "Sub-buffer 2";
*          }
*
*          "mainbuffer" [
*              label = "...| ...| ...| ...| ...| ...|<f0> uint32_t subBufferSize| ...| ...|<f1> uint32_t subBufferSize| ...| ...| ..."
*              shape = "record"
*          ];
*          "subbuffer1" [
*              label = "<f0> ...| ...|...| ...|  ...|  ...| ...| ...| ...| ..."
*              shape = "record"
*          ];
*          "subbuffer2" [
*              label = "<f0> ...| ...|...| ...|  ...|  ...| ...| ...| ...| ..."
*              shape = "record"
*          ];
*          "mainbuffer":f0-> "subbuffer1":f0[
*              id = 0
*          ];
*          "mainbuffer":f1-> "subbuffer2":f0[
*              id = 0
*          ];
*      }
*
* 

Definition at line 26 of file buffer.hpp.

Constructor & Destructor Documentation

qi::Buffer::Buffer ( )

Default constructor.

qi::Buffer::Buffer ( const Buffer buffer)

Copy constructor.

As data are store as a shared pointer, the different copy of the same buffer all handle the same data.

Parameters
bufferThe buffer to copy.

Member Function Documentation

qi::Buffer::addSubBuffer ( const Buffer buffer)

Add a sub-buffer to the main buffer.

This function add a uint32_t for the size of sub-buffers in main buffer and add the buffer to the list of sub-buffers.

Parameters
bufferThe buffer to have as sub-buffer.
Returns
return te offset at which sub-buffer have been added.
qi::Buffer::clear ( )

Erase content of buffer and remove sub-buffers whithout clearing them.

qi::Buffer::data ( )

Return a pointer to the raw data storage of this buffer.

Returns
the pointer to the data.
qi::Buffer::data ( ) const

Return a const pointer to the raw data in this buffer.

Returns
the pointer to the data.
qi::Buffer::hasSubBuffer ( size_t  offset) const

Check if there is a sub-buffer at given offset.

Parameters
offsetThe offset to look at the presence of sub-buffer.
Returns
true if there is a sub-buffer, false otherwise.
qi::Buffer::operator= ( const Buffer buffer)

Assignment operator.

As data are store as a shared pointer, the different copy of the same buffer all handle the same data.

Parameters
bufferThe buffer to copy.
qi::Buffer::read ( size_t  offset = 0,
size_t  length = 0 
) const

Read some data from the buffer.

Parameters
offsetoffset at which reading begin in the buffer.
lengthlength of the data to read.
Returns
0 if the buffer is empty or if we try to read data after the end of the buffer.
Otherwise return a pointer to the data. Only length bytes can be read in the returned buffer.
qi::Buffer::read ( void *  buffer,
size_t  offset = 0,
size_t  length = 0 
) const

Read some data in the buffer and store it in a new pre-allocated buffer.

Warning
the given buffer must be freed.
Parameters
bufferthe pre-allocated buffer to store data.
offsetOffset in the current buffer to start copy.
lengthLength of the data to be copied.
Returns
-1 if there is no data in buffer or if offset is bigger than total data in buffer.
Otherwise return the total length of copied data.
qi::Buffer::reserve ( size_t  size)

Reserve bytes at the end of current buffer.

Parameters
sizenumber of new bytes to reserve at the end of buffer.
Returns
a pointer to the data.
Warning
The return value is valid until the next non-const operation.
qi::Buffer::size ( ) const

Return the content size of this buffer not counting sub-buffers.

Returns
the size.
See Also
totalSize
qi::Buffer::subBuffer ( size_t  offset) const

Return the sub-buffer at given offset.

If there is no sub-buffer throw a std::runtime_error.

Parameters
offsetThe offset to look for sub-buffer.
Returns
the sub-buffer.
qi::Buffer::subBuffers ( ) const

Return a vector of sub-buffers of the current buffer.

Returns
a vector of pairs. The first value of the pair is the offset of the sub-buffer into the master buffer. The second value is the sub-buffer itself.
qi::Buffer::totalSize ( ) const

Return the content size of this buffer and of all its sub-buffers.

Returns
the size.
See Also
size
qi::Buffer::write ( const void *  data,
size_t  size 
)

Write data in the buffer.

Parameters
dataThe data to write
sizeThe size of the data to write
Returns
true if operation succeeded, false otherwise.

Friends And Related Function Documentation

friend class BufferReader
friend

Definition at line 70 of file buffer.hpp.


The documentation for this class was generated from the following files: