- Aldebaran documentation |
- C++ Libraries |
- index

libqi-api 2.8.7.4

- Main Page
- Related Pages
- Namespaces
- Classes
- Files
- Examples

- Class List
- Class Hierarchy
- Class Members

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

Class to store buffer. . More...

`#include <buffer.hpp>`

## Public Types
using | size_type = qi::uint32_t

## Public Member Functions
| Buffer ()
| Default constructor. More...
| Buffer (const Buffer &buffer)
| Copy constructor. More...
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. More...
| Buffer (Buffer &&buffer)
| Move constructor. The moved-from buffer's state is like a default constructed Buffer. More...
Buffer & | operator= (Buffer &&buffer)
| Move assignment operator. The moved-from buffer's state is like a default constructed Buffer. 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. 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. More...
bool | hasSubBuffer (size_t offset) const
| Check if there is a sub-buffer at given offset. More...
const Buffer & | subBuffer (size_t offset) const
| Return the sub-buffer at given offset. If there is no sub-buffer throw a std::runtime_error. 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...
bool | operator== (const Buffer &b) const

## 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 76 of file buffer.hpp.

## Member Typedef Documentation

using qi::Buffer::size_type = qi::uint32_t

Definition at line 79 of file buffer.hpp.

## Constructor & Destructor Documentation

qi::Buffer::Buffer | ( |  | ) |

Default constructor.

qi::Buffer::Buffer | ( | const Buffer & | buffer | ) |

Copy constructor.

Parameters

  buffer | The buffer to copy.

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

qi::Buffer::Buffer | ( | Buffer && | buffer | ) |

Move constructor. The moved-from buffer's state is like a default constructed Buffer.

Parameters

  buffer | The buffer to move from.

## Member Function Documentation

size_t 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

  buffer | The buffer to have as sub-buffer.

Returns
  return te offset at which sub-buffer have been added.

void qi::Buffer::clear | ( |  | ) |

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

void* qi::Buffer::data | ( |  | ) |

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

Returns
  the pointer to the data.

const void* qi::Buffer::data | ( |  | ) | const

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

Returns
  the pointer to the data.

bool qi::Buffer::hasSubBuffer | ( | size_t | offset | ) | const

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

Parameters

  offset | The offset to look at the presence of sub-buffer.

Returns
  true if there is a sub-buffer, false otherwise.

Buffer& 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

  buffer | The buffer to copy.

Buffer& qi::Buffer::operator= | ( | Buffer && | buffer | ) |

Move assignment operator. The moved-from buffer's state is like a default constructed Buffer.

Parameters

  buffer | The buffer to move from.

bool qi::Buffer::operator== | ( | const Buffer & | b | ) | const

const void* qi::Buffer::read | ( | size_t | offset = `0`,
|  | size_t | length = `0`
| ) |  | const

Read some data from the buffer.

Parameters

  offset | offset at which reading begin in the buffer.
  length | length 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.

size_t 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

  buffer | the pre-allocated buffer to store data.
  offset | Offset in the current buffer to start copy.
  length | Length 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.

void* qi::Buffer::reserve | ( | size_t | size | ) |

Reserve bytes at the end of current buffer.

Parameters

  size | number 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.

size_t qi::Buffer::size | ( |  | ) | const

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

Returns
  the size.

See Also
  totalSize

const Buffer& 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

  offset | The offset to look for sub-buffer.

Returns
  the sub-buffer.

const std::vector<std::pair<size_t, 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.

size_t qi::Buffer::totalSize | ( |  | ) | const

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

Returns
  the size.

See Also
  size

bool qi::Buffer::write | ( | const void * | data,
|  | size_t | size
| ) |  |

Write data in the buffer.

Parameters

  data | The data to write
  size | The 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 215 of file buffer.hpp.

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

- /home/opennao/work/release-2.8/sdk/libqi/qi/buffer.hpp