Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends
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
void init ()
 Initializes or Reinitializes an empty buffer.
bool init (const char *buffer, const industrial::shared_types::shared_int byte_size)
 initializes byte array from char* buffer
bool load (industrial::shared_types::shared_bool value)
 loads a boolean into the byte array
bool load (industrial::shared_types::shared_real value)
 loads a float on the byte array. If byte swapping is enabled, then the bytes are swapped (this assumes a common float representation)
bool load (industrial::shared_types::shared_int value)
 loads an integer into the byte array. If byte swapping is enabled, then the bytes are swapped.
bool load (industrial::simple_serialize::SimpleSerialize &value)
 loads a complex SimpleSerialize into the byte array
bool load (ByteArray &value)
 loads a whole byte array into this byte array
bool load (void *value, const industrial::shared_types::shared_int byte_size)
 loads a void* (treated as char*) into the byte array. WARNING: Byte swapping is not performed in this function.
bool unload (industrial::shared_types::shared_bool &value)
 unloads a boolean value from the byte array
bool unload (industrial::shared_types::shared_real &value)
 unloads a double value from the byte array. If byte swapping is enabled, then the bytes are swapped.
bool unload (industrial::shared_types::shared_int &value)
 unloads an integer value from the byte array. If byte swapping is enabled, then the bytes are swapped.
bool unload (industrial::simple_serialize::SimpleSerialize &value)
 unloads a complex SimpleSerialize value 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 (void *value, const industrial::shared_types::shared_int byteSize)
 unloads a void* (treated as char*) from the byte array. WARNING: Byte swapping is not performed in this function.
bool unloadFront (industrial::shared_types::shared_real &value)
 unloads a double value from the beginning of the byte array. If byte swapping is enabled, then the bytes are swapped. WARNING: This method performs a memmove every time it is called (this is expensive).
bool unloadFront (industrial::shared_types::shared_int &value)
 unloads an integer value from the beginning of the byte array. If byte swapping is enabled, then the bytes are swapped WARNING: This method performs a memmove every time it is called (this is expensive).
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). WARNING: Byte swapping is not performed in this function.
 ~ByteArray (void)
 Destructor.

Static Public Member Functions

static bool isByteSwapEnabled ()
 returns true if byte swapping is enabled (this is a global option set by compiler flag). This function gives the status of the compiler flag.

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*).

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.

By default data using the load/unload methods is appended/removed from the end of the array. As long as the standard load/unload methods are uses, this is transparent to the user.

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 83 of file byte_array.h.


Constructor & Destructor Documentation

Default constructor.

This method creates and empty byte array.

Definition at line 55 of file byte_array.cpp.

Destructor.

Definition at line 63 of file byte_array.cpp.


Member Function Documentation

Deep-Copy.

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

Parameters:
bufferbuffer to copy

Definition at line 92 of file byte_array.cpp.

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

extends current buffer size

Parameters:
numberof bytes to extend
Returns:
true on success, false otherwise (new size is too large)

Definition at line 443 of file byte_array.cpp.

gets current buffer size

Returns:
buffer size

Definition at line 405 of file byte_array.cpp.

gets pointer to unload location (buffer_size + 1)

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

Definition at line 476 of file byte_array.cpp.

gets current buffer size

Returns:
buffer size

Definition at line 410 of file byte_array.cpp.

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 132 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_)

Definition at line 482 of file byte_array.cpp.

Initializes or Reinitializes an empty buffer.

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

Definition at line 67 of file byte_array.cpp.

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:
bufferpointer to byte buffer
byte_sizesize 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).

returns true if byte swapping is enabled (this is a global option set by compiler flag). This function gives the status of the compiler flag.

Returns:
true if byte swapping is enabled.

Definition at line 416 of file byte_array.cpp.

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

loads a boolean into the byte array

Parameters:
valueto 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 float on the byte array. If byte swapping is enabled, then the bytes are swapped (this assumes a common float representation)

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

loads an integer into the byte array. If byte swapping is enabled, then the bytes are swapped.

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

loads a complex SimpleSerialize into the byte array

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

Definition at line 170 of file byte_array.cpp.

loads a whole byte array into this byte array

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

Definition at line 176 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. WARNING: Byte swapping is not performed in this function.

Parameters:
valueto load number of bytes 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:
sizenew size
Returns:
true on success, false otherwise (new size is too large)

Definition at line 424 of file byte_array.cpp.

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

shortens current buffer size

Parameters:
numberof bytes to shorten
Returns:
true on success, false otherwise (new size is less than 0)

Definition at line 452 of file byte_array.cpp.

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

unloads a boolean value from the byte array

Parameters:
valuevalue 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. If byte swapping is enabled, then the bytes are swapped.

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

unloads an integer value from the byte array. If byte swapping is enabled, then the bytes are swapped.

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

unloads a complex SimpleSerialize value from the byte array

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

Definition at line 253 of file byte_array.cpp.

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:
valuevalue to unload
Returns:
true on success, false otherwise (array is empty)
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. WARNING: Byte swapping is not performed in this function.

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

unloads a double value from the beginning of the byte array. If byte swapping is enabled, then the bytes are swapped. WARNING: This method performs a memmove every time it is called (this is expensive).

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

Definition at line 336 of file byte_array.cpp.

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

unloads an integer value from the beginning of the byte array. If byte swapping is enabled, then the bytes are swapped WARNING: This method performs a memmove every time it is called (this is expensive).

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

Definition at line 348 of file byte_array.cpp.

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). WARNING: Byte swapping is not performed in this function.

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

Definition at line 359 of file byte_array.cpp.


Friends And Related Function Documentation

friend class SimpleSerialize [friend]

Definition at line 88 of file byte_array.h.


Member Data Documentation

internal data buffer

Definition at line 351 of file byte_array.h.

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

current buffer size

Definition at line 356 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 346 of file byte_array.h.


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


simple_message
Author(s): Shaun Edwards
autogenerated on Mon Oct 6 2014 00:54:18