ARGoS  3
A parallel, multi-engine simulator for swarm robotics
argos::CByteArray Class Reference

Byte array utility class. More...

#include <byte_array.h>

List of all members.

Public Member Functions

 CByteArray ()
 Class constructor.
 CByteArray (const CByteArray &c_byte_array)
 Class copy constructor.
 CByteArray (const UInt8 *pun_buffer, size_t un_size)
 Class constructor.
 CByteArray (size_t un_size, UInt8 un_value=0)
 Class constructor.
size_t Size () const
 Returns the current size of the byte array.
void Resize (size_t un_size, UInt8 un_value=0)
 Resizes the byte array to the wanted size.
bool Empty () const
 Returns true if the byte array is empty.
const UInt8ToCArray () const
 Returns the contents of the byte array as a const c-style array.
void Clear ()
 Clears the byte array.
void Zero ()
 Sets the contents of the byte array to all zeros.
CByteArrayoperator= (const CByteArray &c_byte_array)
 Assignment operator.
UInt8operator[] (size_t un_index)
 Read/write index operator.
UInt8 operator[] (size_t un_index) const
 Read-only index operator.
CByteArrayAddBuffer (const UInt8 *pun_buffer, size_t un_size)
 Appends bytes to the byte array.
CByteArrayFetchBuffer (UInt8 *pun_buffer, size_t un_size)
 Moves elements from the byte array into the passed buffer.
CByteArrayoperator<< (UInt8 un_value)
 Appends a 8-bit unsigned integer to the byte array.
CByteArrayoperator>> (UInt8 &un_value)
 Moves an 8-bit unsigned integer from the byte array to the target variable.
CByteArrayoperator<< (SInt8 n_value)
 Appends a 8-bit signed integer to the byte array.
CByteArrayoperator>> (SInt8 &n_value)
 Moves an 8-bit signed integer from the byte array to the target variable.
CByteArrayoperator<< (UInt16 un_value)
 Appends a 16-bit unsigned integer to the byte array.
CByteArrayoperator>> (UInt16 &un_value)
 Moves a 16-bit unsigned integer from the byte array to the target variable.
CByteArrayoperator<< (SInt16 n_value)
 Appends a 16-bit signed integer to the byte array.
CByteArrayoperator>> (SInt16 &n_value)
 Moves a 16-bit signed integer from the byte array to the target variable.
CByteArrayoperator<< (UInt32 un_value)
 Appends a 32-bit unsigned integer to the byte array.
CByteArrayoperator>> (UInt32 &un_value)
 Moves a 32-bit unsigned integer from the byte array to the target variable.
CByteArrayoperator<< (SInt32 n_value)
 Appends a 32-bit signed integer to the byte array.
CByteArrayoperator>> (SInt32 &n_value)
 Moves a 32-bit signed integer from the byte array to the target variable.
CByteArrayoperator<< (UInt64 un_value)
 Appends a 64-bit unsigned integer to the byte array.
CByteArrayoperator>> (UInt64 &un_value)
 Moves a 64-bit unsigned integer from the byte array to the target variable.
CByteArrayoperator<< (SInt64 n_value)
 Appends a 64-bit signed integer to the byte array.
CByteArrayoperator>> (SInt64 &n_value)
 Moves a 64-bit signed integer from the byte array to the target variable.
CByteArrayoperator<< (unsigned long int un_value)
 Appends an unsigned long integer to the byte array.
CByteArrayoperator>> (unsigned long int &un_value)
 Moves an unsigned long integer from the byte array to the target variable.
CByteArrayoperator<< (signed long int n_value)
 Appends a signed long integer to the byte array.
CByteArrayoperator>> (signed long int &n_value)
 Moves a signed long integer from the byte array to the target variable.
CByteArrayoperator<< (Real f_value)
 Appends an argos::Real to the byte array.
CByteArrayoperator>> (Real &f_value)
 Moves an argos::Real from the byte array to the target variable.
CByteArrayoperator<< (const std::string &str_value)
 Appends a std::string to the byte array.
CByteArrayoperator>> (std::string &str_value)
 Moves a std::string from the byte array to the target variable.

Friends

std::ostream & operator<< (std::ostream &c_os, const CByteArray &c_byte_array)
 Stream operator.

Detailed Description

Byte array utility class.

This class is useful for serializing any kind of data into a byte array, to be then streamed to something. It is used by the argos::CMemento class as a basic tool to store the state of an object and retrieve it.

Definition at line 27 of file byte_array.h.


Constructor & Destructor Documentation

Class constructor.

Definition at line 34 of file byte_array.h.

argos::CByteArray::CByteArray ( const CByteArray c_byte_array) [inline]

Class copy constructor.

Definition at line 39 of file byte_array.h.

argos::CByteArray::CByteArray ( const UInt8 pun_buffer,
size_t  un_size 
)

Class constructor.

Copies the given buffer into the byte array. The original buffer can be safely deleted.

Parameters:
pun_bufferthe original buffer to copy from.
un_sizethe size of the original buffer.

Definition at line 15 of file byte_array.cpp.

argos::CByteArray::CByteArray ( size_t  un_size,
UInt8  un_value = 0 
)

Class constructor.

Creates a byte array that contains un_size copies of un_value.

Parameters:
un_sizethe initial size of the byte array.
un_valuethe value to use to populate the byte array.

Definition at line 23 of file byte_array.cpp.


Member Function Documentation

CByteArray & argos::CByteArray::AddBuffer ( const UInt8 pun_buffer,
size_t  un_size 
)

Appends bytes to the byte array.

The contents of the buffer can be erased, since this method copies them.

Parameters:
pun_bufferthe byte buffer to copy from.
un_sizethe size of the byte buffer.
Returns:
a reference to this byte array.

Definition at line 48 of file byte_array.cpp.

void argos::CByteArray::Clear ( ) [inline]

Clears the byte array.

After calling this method, the byte array is empty.

See also:
Empty()
Size()

Definition at line 113 of file byte_array.h.

bool argos::CByteArray::Empty ( ) const [inline]

Returns true if the byte array is empty.

Returns:
true if the byte array is empty.

Definition at line 91 of file byte_array.h.

CByteArray & argos::CByteArray::FetchBuffer ( UInt8 pun_buffer,
size_t  un_size 
)

Moves elements from the byte array into the passed buffer.

The elements whose values were written into the target buffer are removed from the byte array.

Parameters:
pun_bufferthe byte buffer to write into.
un_sizethe size of the target byte buffer.
Returns:
a reference to this byte array.

Definition at line 59 of file byte_array.cpp.

CByteArray & argos::CByteArray::operator<< ( UInt8  un_value)

Appends a 8-bit unsigned integer to the byte array.

Parameters:
un_valuethe value of the 8-bit unsigned integer.
Returns:
a reference to this byte array.

Definition at line 72 of file byte_array.cpp.

CByteArray & argos::CByteArray::operator<< ( SInt8  n_value)

Appends a 8-bit signed integer to the byte array.

Parameters:
n_valuethe value of the 8-bit signed integer.
Returns:
a reference to this byte array.

Definition at line 90 of file byte_array.cpp.

CByteArray & argos::CByteArray::operator<< ( UInt16  un_value)

Appends a 16-bit unsigned integer to the byte array.

Parameters:
un_valuethe value of the 16-bit unsigned integer.
Returns:
a reference to this byte array.

Definition at line 108 of file byte_array.cpp.

CByteArray & argos::CByteArray::operator<< ( SInt16  n_value)

Appends a 16-bit signed integer to the byte array.

Parameters:
n_valuethe value of the 16-bit signed integer.
Returns:
a reference to this byte array.

Definition at line 130 of file byte_array.cpp.

CByteArray & argos::CByteArray::operator<< ( UInt32  un_value)

Appends a 32-bit unsigned integer to the byte array.

Parameters:
un_valuethe value of the 32-bit unsigned integer.
Returns:
a reference to this byte array.

Definition at line 152 of file byte_array.cpp.

CByteArray & argos::CByteArray::operator<< ( SInt32  n_value)

Appends a 32-bit signed integer to the byte array.

Parameters:
n_valuethe value of the 32-bit signed integer.
Returns:
a reference to this byte array.

Definition at line 178 of file byte_array.cpp.

CByteArray & argos::CByteArray::operator<< ( UInt64  un_value)

Appends a 64-bit unsigned integer to the byte array.

Parameters:
un_valuethe value of the 64-bit unsigned integer.
Returns:
a reference to this byte array.

Definition at line 204 of file byte_array.cpp.

CByteArray & argos::CByteArray::operator<< ( SInt64  n_value)

Appends a 64-bit signed integer to the byte array.

Parameters:
n_valuethe value of the 64-bit signed integer.
Returns:
a reference to this byte array.

Definition at line 238 of file byte_array.cpp.

CByteArray & argos::CByteArray::operator<< ( unsigned long int  un_value)

Appends an unsigned long integer to the byte array.

This function should be avoided as much as possible because the size of long integers changes on 32- and 64-bit architectures.

Parameters:
un_valuethe value of the unsigned long integer.
Returns:
a reference to this byte array.

Definition at line 272 of file byte_array.cpp.

CByteArray & argos::CByteArray::operator<< ( signed long int  n_value)

Appends a signed long integer to the byte array.

This function should be avoided as much as possible because the size of long integers changes on 32- and 64-bit architectures.

Parameters:
n_valuethe value of the signed long integer.
Returns:
a reference to this byte array.

Definition at line 299 of file byte_array.cpp.

CByteArray & argos::CByteArray::operator<< ( Real  f_value)

Appends an argos::Real to the byte array.

Parameters:
f_valuethe value of the argos::Real.
Returns:
a reference to this byte array.

Definition at line 326 of file byte_array.cpp.

CByteArray & argos::CByteArray::operator<< ( const std::string &  str_value)

Appends a std::string to the byte array.

Parameters:
str_valuethe value of the std::string.
Returns:
a reference to this byte array.

Definition at line 353 of file byte_array.cpp.

CByteArray & argos::CByteArray::operator= ( const CByteArray c_byte_array)

Assignment operator.

Deep-copies the given byte array into the current byte array.

Definition at line 38 of file byte_array.cpp.

CByteArray & argos::CByteArray::operator>> ( UInt8 un_value)

Moves an 8-bit unsigned integer from the byte array to the target variable.

The element whose value was written into the target buffer are removed from the byte array.

Parameters:
un_valuethe buffer for the 8-bit unsigned integer.
Returns:
a reference to this byte array.

Definition at line 80 of file byte_array.cpp.

CByteArray & argos::CByteArray::operator>> ( SInt8 n_value)

Moves an 8-bit signed integer from the byte array to the target variable.

The element whose value was written into the target buffer are removed from the byte array.

Parameters:
n_valuethe buffer for the 8-bit unsigned integer.
Returns:
a reference to this byte array.

Definition at line 98 of file byte_array.cpp.

CByteArray & argos::CByteArray::operator>> ( UInt16 un_value)

Moves a 16-bit unsigned integer from the byte array to the target variable.

The element whose value was written into the target buffer are removed from the byte array.

Parameters:
un_valuethe buffer for the 16-bit unsigned integer.
Returns:
a reference to this byte array.

Definition at line 118 of file byte_array.cpp.

CByteArray & argos::CByteArray::operator>> ( SInt16 n_value)

Moves a 16-bit signed integer from the byte array to the target variable.

The element whose value was written into the target buffer are removed from the byte array.

Parameters:
n_valuethe buffer for the 16-bit signed integer.
Returns:
a reference to this byte array.

Definition at line 140 of file byte_array.cpp.

CByteArray & argos::CByteArray::operator>> ( UInt32 un_value)

Moves a 32-bit unsigned integer from the byte array to the target variable.

The element whose value was written into the target buffer are removed from the byte array.

Parameters:
un_valuethe buffer for the 32-bit unsigned integer.
Returns:
a reference to this byte array.

Definition at line 164 of file byte_array.cpp.

CByteArray & argos::CByteArray::operator>> ( SInt32 n_value)

Moves a 32-bit signed integer from the byte array to the target variable.

The element whose value was written into the target buffer are removed from the byte array.

Parameters:
n_valuethe buffer for the 32-bit signed integer.
Returns:
a reference to this byte array.

Definition at line 190 of file byte_array.cpp.

CByteArray & argos::CByteArray::operator>> ( UInt64 un_value)

Moves a 64-bit unsigned integer from the byte array to the target variable.

The element whose value was written into the target buffer are removed from the byte array.

Parameters:
un_valuethe buffer for the 64-bit unsigned integer.
Returns:
a reference to this byte array.

Definition at line 220 of file byte_array.cpp.

CByteArray & argos::CByteArray::operator>> ( SInt64 n_value)

Moves a 64-bit signed integer from the byte array to the target variable.

The element whose value was written into the target buffer are removed from the byte array.

Parameters:
n_valuethe buffer for the 64-bit signed integer.
Returns:
a reference to this byte array.

Definition at line 254 of file byte_array.cpp.

CByteArray & argos::CByteArray::operator>> ( unsigned long int &  un_value)

Moves an unsigned long integer from the byte array to the target variable.

The element whose value was written into the target buffer are removed from the byte array. This function should be avoided as much as possible because the size of long integers changes on 32- and 64-bit architectures.

Parameters:
un_valuethe buffer for the unsigned long integer.
Returns:
a reference to this byte array.

Definition at line 284 of file byte_array.cpp.

CByteArray & argos::CByteArray::operator>> ( signed long int &  n_value)

Moves a signed long integer from the byte array to the target variable.

The element whose value was written into the target buffer are removed from the byte array. This function should be avoided as much as possible because the size of long integers changes on 32- and 64-bit architectures.

Parameters:
n_valuethe buffer for the signed long integer.
Returns:
a reference to this byte array.

Definition at line 311 of file byte_array.cpp.

CByteArray & argos::CByteArray::operator>> ( Real f_value)

Moves an argos::Real from the byte array to the target variable.

The element whose value was written into the target buffer are removed from the byte array.

Parameters:
f_valuethe buffer for the argos::Real.
Returns:
a reference to this byte array.

Definition at line 338 of file byte_array.cpp.

CByteArray & argos::CByteArray::operator>> ( std::string &  str_value)

Moves a std::string from the byte array to the target variable.

The element whose value was written into the target buffer are removed from the byte array.

Parameters:
str_valuethe buffer for the std::string.
Returns:
a reference to this byte array.

Definition at line 366 of file byte_array.cpp.

UInt8& argos::CByteArray::operator[] ( size_t  un_index) [inline]

Read/write index operator.

Parameters:
un_indexthe index of the wanted element.
Returns:
a reference to the wanted element.
Exceptions:
CARGoSExceptionif the passed index is out of bounds.

Definition at line 136 of file byte_array.h.

UInt8 argos::CByteArray::operator[] ( size_t  un_index) const [inline]

Read-only index operator.

Parameters:
un_indexthe index of the wanted element.
Returns:
the value of the wanted element.
Exceptions:
CARGoSExceptionif the passed index is out of bounds.

Definition at line 147 of file byte_array.h.

void argos::CByteArray::Resize ( size_t  un_size,
UInt8  un_value = 0 
) [inline]

Resizes the byte array to the wanted size.

If the new size is smaller than the old one, the first un_size elements are kept, and the extra ones are erased. If the new size is greater than the old one, new elements are added to the byte array and initialized with un_value. This operation could entail a reallocation of the internal storage structure, which would invalide the pointer returned by ToCArray().

Parameters:
un_sizeThe new size.
un_valueThe init value for the padding elements.
See also:
ToCArray()

Definition at line 82 of file byte_array.h.

size_t argos::CByteArray::Size ( ) const [inline]

Returns the current size of the byte array.

Returns:
the current size of the byte array.

Definition at line 65 of file byte_array.h.

const UInt8* argos::CByteArray::ToCArray ( ) const [inline]

Returns the contents of the byte array as a const c-style array.

The returned pointer is valid under two conditions: (i) the CByteArray object has not been deallocated, and (ii) the contents of the byte array have not been changed. If the byte array is empty, this method returns NULL.

Returns:
the contents of the byte array as a const c-style array.

Definition at line 103 of file byte_array.h.

Sets the contents of the byte array to all zeros.

This method does not change the size of the byte array.

See also:
Size()

Definition at line 31 of file byte_array.cpp.


Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  c_os,
const CByteArray c_byte_array 
) [friend]

Stream operator.

It streams the byte array through the given stream. Useful for files, for instance.

Parameters:
c_osthe C++ output stream the byte array to.
c_byte_arraythe byte array to stream.
Returns:
the new state of the output stream.

Definition at line 384 of file byte_array.cpp.


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