$search

industrial::byte_array::ByteArray Class Reference

The byte array wraps a traditional, fixed size, array of bytes (i.e. char*). More...

#include <byte_array.h>

List of all members.

Public Member Functions

 ByteArray (void)
 Default constructor.
void copyFrom (ByteArray &buffer)
 Deep-Copy.
unsigned int getBufferSize ()
 gets current buffer size
unsigned int getMaxBufferSize ()
 gets current buffer size
char * getRawDataPtr ()
 returns a char* pointer to the raw data. WARNING: This method is meant for read-only operations
bool init (const char *buffer, const industrial::shared_types::shared_int byte_size)
 initializes byte array from char* buffer
void init ()
 Initializes or Reinitializes and empty buffer.
bool load (void *value, const industrial::shared_types::shared_int byte_size)
 loads a void* (treated as char*) into the byte array
bool load (ByteArray &value)
 loads a whole byte array into this byte array
bool load (industrial::simple_serialize::SimpleSerialize &value)
 loads a complex SimpleSerialize into the byte array
bool load (industrial::shared_types::shared_int value)
 loads an integer into the byte array
bool load (industrial::shared_types::shared_real value)
 loads a double into the byte array
bool load (industrial::shared_types::shared_bool value)
 loads a boolean into the byte array
bool unload (void *value, const industrial::shared_types::shared_int byteSize)
 unloads a void* (treated as char*) from the byte array
bool unload (ByteArray &value, const industrial::shared_types::shared_int byte_size)
 unloads a partial byte array from the byte array into the passed in byte array (this is done using the byte array load method so any data in the passed in byte array remains intact)
bool unload (industrial::simple_serialize::SimpleSerialize &value)
 unloads a complex SimpleSerialize value from the byte array
bool unload (industrial::shared_types::shared_int &value)
 unloads an integer value from the byte array
bool unload (industrial::shared_types::shared_real &value)
 unloads a double value from the byte array
bool unload (industrial::shared_types::shared_bool &value)
 unloads a boolean value from the byte array
bool unloadFront (void *value, const industrial::shared_types::shared_int byteSize)
 unloads a void* (treated as char*) from the beginning of the array. WARNING: This method performs a memmove every time it is called (this is expensive).
 ~ByteArray (void)
 Destructor.

Private Member Functions

bool extendBufferSize (const industrial::shared_types::shared_int size)
 extends current buffer size
char * getLoadPtr ()
 gets pointer to unload location (buffer_size + 1)
char * getUnloadPtr (const industrial::shared_types::shared_int num_bytes)
 gets pointer to unload location (buffer_size - num_bytes)
bool setBufferSize (const industrial::shared_types::shared_int size)
 sets current buffer size
bool shortenBufferSize (industrial::shared_types::shared_int size)
 shortens current buffer size

Private Attributes

char buffer_ [MAX_SIZE]
 internal data buffer
industrial::shared_types::shared_int buffer_size_
 current buffer size

Static Private Attributes

static const
industrial::shared_types::shared_int 
MAX_SIZE = 1024
 maximum array size (WARNING: THIS VALUE SHOULD NOT EXCEED THE MAX 32-BIT INTEGER SIZE)

Friends

class SimpleSerialize

Detailed Description

The byte array wraps a traditional, fixed size, array of bytes (i.e. char*).

The byte array wraps a traditional, fixed size, array of bytes (i.e. char*).

It provides convenient methods for loading and unloading data types to and from the byte array. The class acts as an interface definition to raw data (in case the underlying structure of the raw data changes). It's intended use is for socket communications.

A fixed size array is used for simplicity (i.e. avoiding re-implementing the STL vector class for those systems that don't have access to the STL, i.e. Motoman robotics Motoplus compiler.

THIS CLASS IS NOT THREAD-SAFE

Definition at line 87 of file byte_array.h.


Constructor & Destructor Documentation

industrial::byte_array::ByteArray::ByteArray ( void   ) 

Default constructor.

This method creates and empty byte array.

Definition at line 55 of file byte_array.cpp.

industrial::byte_array::ByteArray::~ByteArray ( void   ) 

Destructor.

Definition at line 60 of file byte_array.cpp.


Member Function Documentation

void industrial::byte_array::ByteArray::copyFrom ( ByteArray buffer  ) 

Deep-Copy.

This method creates a byte array containing a deep copy of the passed in buffer

Parameters:
buffer buffer to copy

Definition at line 89 of file byte_array.cpp.

bool industrial::byte_array::ByteArray::extendBufferSize ( const industrial::shared_types::shared_int  size  )  [private]

extends current buffer size

Parameters:
number of bytes to extend
Returns:
true on success, false otherwise (new size is too large)
unsigned int industrial::byte_array::ByteArray::getBufferSize (  ) 

gets current buffer size

Returns:
buffer size

Definition at line 313 of file byte_array.cpp.

char * industrial::byte_array::ByteArray::getLoadPtr (  )  [private]

gets pointer to unload location (buffer_size + 1)

Parameters:
size new size
Returns:
pointer to load location (NULL if array is at max size)

Definition at line 375 of file byte_array.cpp.

unsigned int industrial::byte_array::ByteArray::getMaxBufferSize (  ) 

gets current buffer size

Returns:
buffer size

Definition at line 318 of file byte_array.cpp.

char * industrial::byte_array::ByteArray::getRawDataPtr (  ) 

returns a char* pointer to the raw data. WARNING: This method is meant for read-only operations

This function returns a pointer to the actual raw data stored within the class. Care should be taken not to modified the data oustide of the class. This method of providing a reference to private class data is used in order to avoid dynamic memory allocation that would be required to return a copy.

Returns:
char* pointer to the raw data

Definition at line 102 of file byte_array.cpp.

char* industrial::byte_array::ByteArray::getUnloadPtr ( const industrial::shared_types::shared_int  num_bytes  )  [private]

gets pointer to unload location (buffer_size - num_bytes)

The unload location is the beginning of the data item that is to be unloaded.

Returns:
pointer to load location (NULL is num_bytes > buffer_size_)
bool industrial::byte_array::ByteArray::init ( const char *  buffer,
const industrial::shared_types::shared_int  byte_size 
)

initializes byte array from char* buffer

This method creates a byte array containing a copy of the passed in buffer (up to byteSize)

Parameters:
buffer pointer to byte buffer
byte_size size of buffer to copy. If the byte size is greater than the max buffer size then only the max buffer amount of bytes is copied
Returns:
true on success, false otherwise (max array size exceeded).
void industrial::byte_array::ByteArray::init (  ) 

Initializes or Reinitializes and empty buffer.

This method sets all values to 0 and resets the buffer size.

Definition at line 64 of file byte_array.cpp.

bool industrial::byte_array::ByteArray::load ( void *  value,
const industrial::shared_types::shared_int  byte_size 
)

loads a void* (treated as char*) into the byte array

Parameters:
value to load number of bytes to load
Returns:
true on success, false otherwise (max array size exceeded). Value not loaded
bool industrial::byte_array::ByteArray::load ( ByteArray value  ) 

loads a whole byte array into this byte array

Parameters:
value to load
Returns:
true on success, false otherwise (max array size exceeded). Value not loaded

Definition at line 134 of file byte_array.cpp.

bool industrial::byte_array::ByteArray::load ( industrial::simple_serialize::SimpleSerialize value  ) 

loads a complex SimpleSerialize into the byte array

Parameters:
value to load
Returns:
true on success, false otherwise (max array size exceeded). Value not loaded

Definition at line 128 of file byte_array.cpp.

bool industrial::byte_array::ByteArray::load ( industrial::shared_types::shared_int  value  ) 

loads an integer into the byte array

Parameters:
value to load
Returns:
true on success, false otherwise (max array size exceeded). Value not loaded
bool industrial::byte_array::ByteArray::load ( industrial::shared_types::shared_real  value  ) 

loads a double into the byte array

Parameters:
value to load
Returns:
true on success, false otherwise (max array size exceeded). Value not loaded
bool industrial::byte_array::ByteArray::load ( industrial::shared_types::shared_bool  value  ) 

loads a boolean into the byte array

Parameters:
value to load
Returns:
true on success, false otherwise (max array size exceeded). Value not loaded
bool industrial::byte_array::ByteArray::setBufferSize ( const industrial::shared_types::shared_int  size  )  [private]

sets current buffer size

Parameters:
size new size
Returns:
true on success, false otherwise (new size is too large)
bool industrial::byte_array::ByteArray::shortenBufferSize ( industrial::shared_types::shared_int  size  )  [private]

shortens current buffer size

Parameters:
number of bytes to shorten
Returns:
true on success, false otherwise (new size is less than 0)
bool industrial::byte_array::ByteArray::unload ( void *  value,
const industrial::shared_types::shared_int  byteSize 
)

unloads a void* (treated as char*) from the byte array

Parameters:
value to unload number of bytes to unload
Returns:
true on success, false otherwise (array is empty)
bool industrial::byte_array::ByteArray::unload ( ByteArray value,
const industrial::shared_types::shared_int  byte_size 
)

unloads a partial byte array from the byte array into the passed in byte array (this is done using the byte array load method so any data in the passed in byte array remains intact)

Parameters:
value value to unload
Returns:
true on success, false otherwise (array is empty)
bool industrial::byte_array::ByteArray::unload ( industrial::simple_serialize::SimpleSerialize value  ) 

unloads a complex SimpleSerialize value from the byte array

Parameters:
value value to unload
Returns:
true on success, false otherwise (array is empty)

Definition at line 194 of file byte_array.cpp.

bool industrial::byte_array::ByteArray::unload ( industrial::shared_types::shared_int &  value  ) 

unloads an integer value from the byte array

Parameters:
value value to unload
Returns:
true on success, false otherwise (array is empty)
bool industrial::byte_array::ByteArray::unload ( industrial::shared_types::shared_real &  value  ) 

unloads a double value from the byte array

Parameters:
value value to unload
Returns:
true on success, false otherwise (array is empty)
bool industrial::byte_array::ByteArray::unload ( industrial::shared_types::shared_bool &  value  ) 

unloads a boolean value from the byte array

Parameters:
value value to unload
Returns:
true on success, false otherwise (array is empty)
bool industrial::byte_array::ByteArray::unloadFront ( void *  value,
const industrial::shared_types::shared_int  byteSize 
)

unloads a void* (treated as char*) from the beginning of the array. WARNING: This method performs a memmove every time it is called (this is expensive).

Parameters:
value to unload number of bytes to unload
Returns:
true on success, false otherwise (array is empty)

Definition at line 267 of file byte_array.cpp.


Friends And Related Function Documentation

friend class SimpleSerialize [friend]

Definition at line 92 of file byte_array.h.


Member Data Documentation

internal data buffer

Definition at line 328 of file byte_array.h.

industrial::shared_types::shared_int industrial::byte_array::ByteArray::buffer_size_ [private]

current buffer size

Definition at line 333 of file byte_array.h.

const industrial::shared_types::shared_int industrial::byte_array::ByteArray::MAX_SIZE = 1024 [static, private]

maximum array size (WARNING: THIS VALUE SHOULD NOT EXCEED THE MAX 32-BIT INTEGER SIZE)

The byte array class uses shared 32-bit types, so the buffer size cannot be larger than this. Ideally this value would be relatively small as passing large amounts of data is not desired.

Definition at line 323 of file byte_array.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends


simple_message
Author(s): Shaun Edwards
autogenerated on Mon Mar 4 11:36:28 2013