ARGoS
3
A parallel, multi-engine simulator for swarm robotics
|
Byte array utility class. More...
#include <byte_array.h>
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 UInt8 * | ToCArray () 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. | |
CByteArray & | operator= (const CByteArray &c_byte_array) |
Assignment operator. | |
UInt8 & | operator[] (size_t un_index) |
Read/write index operator. | |
UInt8 | operator[] (size_t un_index) const |
Read-only index operator. | |
CByteArray & | AddBuffer (const UInt8 *pun_buffer, size_t un_size) |
Appends bytes to the byte array. | |
CByteArray & | FetchBuffer (UInt8 *pun_buffer, size_t un_size) |
Moves elements from the byte array into the passed buffer. | |
CByteArray & | operator<< (UInt8 un_value) |
Appends a 8-bit unsigned integer to the byte array. | |
CByteArray & | operator>> (UInt8 &un_value) |
Moves an 8-bit unsigned integer from the byte array to the target variable. | |
CByteArray & | operator<< (SInt8 n_value) |
Appends a 8-bit signed integer to the byte array. | |
CByteArray & | operator>> (SInt8 &n_value) |
Moves an 8-bit signed integer from the byte array to the target variable. | |
CByteArray & | operator<< (UInt16 un_value) |
Appends a 16-bit unsigned integer to the byte array. | |
CByteArray & | operator>> (UInt16 &un_value) |
Moves a 16-bit unsigned integer from the byte array to the target variable. | |
CByteArray & | operator<< (SInt16 n_value) |
Appends a 16-bit signed integer to the byte array. | |
CByteArray & | operator>> (SInt16 &n_value) |
Moves a 16-bit signed integer from the byte array to the target variable. | |
CByteArray & | operator<< (UInt32 un_value) |
Appends a 32-bit unsigned integer to the byte array. | |
CByteArray & | operator>> (UInt32 &un_value) |
Moves a 32-bit unsigned integer from the byte array to the target variable. | |
CByteArray & | operator<< (SInt32 n_value) |
Appends a 32-bit signed integer to the byte array. | |
CByteArray & | operator>> (SInt32 &n_value) |
Moves a 32-bit signed integer from the byte array to the target variable. | |
CByteArray & | operator<< (UInt64 un_value) |
Appends a 64-bit unsigned integer to the byte array. | |
CByteArray & | operator>> (UInt64 &un_value) |
Moves a 64-bit unsigned integer from the byte array to the target variable. | |
CByteArray & | operator<< (SInt64 n_value) |
Appends a 64-bit signed integer to the byte array. | |
CByteArray & | operator>> (SInt64 &n_value) |
Moves a 64-bit signed integer from the byte array to the target variable. | |
CByteArray & | operator<< (unsigned long int un_value) |
Appends an unsigned long integer to the byte array. | |
CByteArray & | operator>> (unsigned long int &un_value) |
Moves an unsigned long integer from the byte array to the target variable. | |
CByteArray & | operator<< (signed long int n_value) |
Appends a signed long integer to the byte array. | |
CByteArray & | operator>> (signed long int &n_value) |
Moves a signed long integer from the byte array to the target variable. | |
CByteArray & | operator<< (Real f_value) |
Appends an argos::Real to the byte array. | |
CByteArray & | operator>> (Real &f_value) |
Moves an argos::Real from the byte array to the target variable. | |
CByteArray & | operator<< (const std::string &str_value) |
Appends a std::string to the byte array. | |
CByteArray & | operator>> (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. |
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.
argos::CByteArray::CByteArray | ( | ) | [inline] |
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.
pun_buffer | the original buffer to copy from. |
un_size | the 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
.
un_size | the initial size of the byte array. |
un_value | the value to use to populate the byte array. |
Definition at line 23 of file byte_array.cpp.
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.
pun_buffer | the byte buffer to copy from. |
un_size | the size of the byte buffer. |
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.
Definition at line 113 of file byte_array.h.
bool argos::CByteArray::Empty | ( | ) | const [inline] |
Returns true
if the byte array is empty.
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.
pun_buffer | the byte buffer to write into. |
un_size | the size of the target byte buffer. |
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.
un_value | the value of the 8-bit unsigned integer. |
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.
n_value | the value of the 8-bit signed integer. |
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.
un_value | the value of the 16-bit unsigned integer. |
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.
n_value | the value of the 16-bit signed integer. |
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.
un_value | the value of the 32-bit unsigned integer. |
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.
n_value | the value of the 32-bit signed integer. |
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.
un_value | the value of the 64-bit unsigned integer. |
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.
n_value | the value of the 64-bit signed integer. |
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.
un_value | the value of the unsigned long integer. |
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.
n_value | the value of the signed long integer. |
Definition at line 299 of file byte_array.cpp.
CByteArray & argos::CByteArray::operator<< | ( | Real | f_value | ) |
Appends an argos::Real to the byte array.
f_value | the value of the argos::Real. |
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.
str_value | the value of the std::string . |
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.
un_value | the buffer for the 8-bit unsigned integer. |
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.
n_value | the buffer for the 8-bit unsigned integer. |
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.
un_value | the buffer for the 16-bit unsigned integer. |
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.
n_value | the buffer for the 16-bit signed integer. |
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.
un_value | the buffer for the 32-bit unsigned integer. |
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.
n_value | the buffer for the 32-bit signed integer. |
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.
un_value | the buffer for the 64-bit unsigned integer. |
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.
n_value | the buffer for the 64-bit signed integer. |
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.
un_value | the buffer for the unsigned long integer. |
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.
n_value | the buffer for the signed long integer. |
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.
f_value | the buffer for the argos::Real. |
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.
str_value | the buffer for the std::string . |
Definition at line 366 of file byte_array.cpp.
UInt8& argos::CByteArray::operator[] | ( | size_t | un_index | ) | [inline] |
Read/write index operator.
un_index | the index of the wanted element. |
CARGoSException | if 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.
un_index | the index of the wanted element. |
CARGoSException | if 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().
un_size | The new size. |
un_value | The init value for the padding elements. |
Definition at line 82 of file byte_array.h.
size_t argos::CByteArray::Size | ( | ) | const [inline] |
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
.
Definition at line 103 of file byte_array.h.
void argos::CByteArray::Zero | ( | ) |
Sets the contents of the byte array to all zeros.
This method does not change the size of the byte array.
Definition at line 31 of file byte_array.cpp.
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.
c_os | the C++ output stream the byte array to. |
c_byte_array | the byte array to stream. |
Definition at line 384 of file byte_array.cpp.