This class describes the message buffer used for all processes of BCP. More...
#include <BCP_buffer.hpp>
Public Member Functions | |
Query methods | |
BCP_message_tag | msgtag () const |
Return the message tag of the message in the buffer. More... | |
int | sender () const |
Return a const pointer to the process id of the sender of the message in the buffer. More... | |
int | size () const |
Return the size of the current message in the buffer. More... | |
const char * | data () const |
Return a const pointer to the data stored in the buffer. More... | |
Modifying methods | |
void | set_position (const int pos) throw (BCP_fatal_error) |
Position the read head in the buffer. More... | |
void | set_size (const int s) throw (BCP_fatal_error) |
Cut off the end of the buffer. More... | |
void | set_msgtag (const BCP_message_tag tag) |
Set the message tag on the buffer. More... | |
void | set_content (const char *data, const size_t size, int sender, BCP_message_tag msgtag) |
Set the buffer to be a copy of the given data. More... | |
BCP_buffer & | operator= (const BCP_buffer &buf) |
Make an exact replica of the other buffer. More... | |
void | make_fit (const int add_size) |
Reallocate the buffer if necessary so that at least add_size number of additional bytes will fit into the buffer. More... | |
void | clear () |
Completely clear the buffer. More... | |
template<class T > | |
BCP_buffer & | pack (const T &value) |
Pack a single object of type T . More... | |
template<class T > | |
BCP_buffer & | unpack (T &value) |
Unpack a single object of type T . More... | |
template<class T > | |
BCP_buffer & | pack (const T *const values, const int length) |
Pack a C style array of objects of type T . More... | |
template<class T > | |
BCP_buffer & | unpack (T *&values, int &length, bool allocate=true) throw (BCP_fatal_error) |
Unpack an array of objects of type T , where T must be a built-in type (ar at least something that can be copied with memcpy). More... | |
BCP_buffer & | pack (const BCP_string &value) |
Pack a BCP_string into the buffer. More... | |
BCP_buffer & | pack (BCP_string &value) |
Pack a BCP_string into the buffer. More... | |
BCP_buffer & | unpack (BCP_string &value) |
Unpack a BCP_string from the buffer. More... | |
template<class T > | |
BCP_buffer & | pack (const BCP_vec< T > &vec) |
Pack a BCP_vec into the buffer. More... | |
template<class T > | |
BCP_buffer & | pack (const std::vector< T > &vec) |
Pack a std::vector into the buffer. More... | |
template<class T > | |
BCP_buffer & | unpack (BCP_vec< T > &vec) |
Unpack a BCP_vec from the buffer. More... | |
template<class T > | |
BCP_buffer & | unpack (std::vector< T > &vec) |
Unpack a std::vector from the buffer. More... | |
Constructors and destructor | |
BCP_buffer () | |
The default constructor creates a buffer of size 16 Kbytes with no message in it. More... | |
BCP_buffer (const BCP_buffer &buf) | |
The copy constructor makes an exact replica of the other buffer. More... | |
~BCP_buffer () | |
The desctructor deletes all data members (including freeing the buffer). More... | |
Public Attributes | |
Data members | |
The data members are public for efficiency reasons. Access these fields sparingly. Note that:
| |
BCP_message_tag | _msgtag |
The message tag of the last received message. More... | |
int | _sender |
The process id of the sender of the last received message. More... | |
size_t | _pos |
The next read position in the buffer. More... | |
size_t | _max_size |
The amount of memory allocated for the buffer. More... | |
size_t | _size |
The current size of the message (the first _size bytes of the buffer). More... | |
char * | _data |
Pointer to the buffer itself. More... | |
This class describes the message buffer used for all processes of BCP.
This buffer is a character array; the components of a message are simply copied into this array one after the other. Note that each process has only one buffer, which serves both for outgoing and incoming messages. This can be done since when a message arrives it is completely unpacked before anything else is done and conversely, once a message is started to be packed together it will be sent out before another message is received.
NOTE: Only the following type of objects can be packed with the various pack()
member methods:
memcpy()
, i.e., built-in non-pointer types, and structs recursively built from such types; BCP_vec
s of the above and BCP_string
s. Everything else that needs to be packed at any time must have a pack()
member method.
Definition at line 39 of file BCP_buffer.hpp.
|
inline |
The default constructor creates a buffer of size 16 Kbytes with no message in it.
Definition at line 381 of file BCP_buffer.hpp.
|
inline |
The copy constructor makes an exact replica of the other buffer.
Definition at line 385 of file BCP_buffer.hpp.
|
inline |
The desctructor deletes all data members (including freeing the buffer).
Definition at line 392 of file BCP_buffer.hpp.
|
inline |
Return the message tag of the message in the buffer.
Definition at line 90 of file BCP_buffer.hpp.
|
inline |
Return a const pointer to the process id of the sender of the message in the buffer.
Definition at line 93 of file BCP_buffer.hpp.
|
inline |
Return the size of the current message in the buffer.
Definition at line 95 of file BCP_buffer.hpp.
|
inline |
Return a const pointer to the data stored in the buffer.
Definition at line 97 of file BCP_buffer.hpp.
|
inline |
Position the read head in the buffer.
Must be between 0 and size().
Definition at line 104 of file BCP_buffer.hpp.
|
inline |
Cut off the end of the buffer.
Must be between 0 and size().
Definition at line 110 of file BCP_buffer.hpp.
|
inline |
Set the message tag on the buffer.
Definition at line 116 of file BCP_buffer.hpp.
|
inline |
Set the buffer to be a copy of the given data.
Use this with care!
Definition at line 119 of file BCP_buffer.hpp.
|
inline |
Make an exact replica of the other buffer.
Definition at line 136 of file BCP_buffer.hpp.
Reallocate the buffer if necessary so that at least add_size
number of additional bytes will fit into the buffer.
Definition at line 153 of file BCP_buffer.hpp.
|
inline |
Completely clear the buffer.
Delete and zero out _msgtag, _size, _pos
and _sender
.
Definition at line 168 of file BCP_buffer.hpp.
|
inline |
Pack a single object of type T
.
Copies sizeof(T)
bytes from the address of the object.
Definition at line 177 of file BCP_buffer.hpp.
|
inline |
Unpack a single object of type T
.
Copies sizeof(T)
bytes to the address of the object.
Definition at line 186 of file BCP_buffer.hpp.
|
inline |
Pack a C style array of objects of type T
.
Definition at line 197 of file BCP_buffer.hpp.
|
inline |
Unpack an array of objects of type T
, where T must be a built-in type (ar at least something that can be copied with memcpy).
If the third argument is true then memory is allocated for the array and the array pointer and the length of the array are returned in the arguments.
If the third argument is false then the arriving array's length is compared to length
and an exception is thrown if they are not the same. Also, the array passed as the first argument will be filled with the arriving array.
Definition at line 222 of file BCP_buffer.hpp.
|
inline |
Pack a BCP_string
into the buffer.
Definition at line 268 of file BCP_buffer.hpp.
|
inline |
Pack a BCP_string
into the buffer.
Definition at line 281 of file BCP_buffer.hpp.
|
inline |
Unpack a BCP_string
from the buffer.
Definition at line 294 of file BCP_buffer.hpp.
|
inline |
Pack a BCP_vec
into the buffer.
Definition at line 304 of file BCP_buffer.hpp.
|
inline |
Pack a std::vector
into the buffer.
Definition at line 318 of file BCP_buffer.hpp.
|
inline |
Unpack a BCP_vec
from the buffer.
Definition at line 332 of file BCP_buffer.hpp.
|
inline |
Unpack a std::vector
from the buffer.
Definition at line 354 of file BCP_buffer.hpp.
BCP_message_tag BCP_buffer::_msgtag |
The message tag of the last received message.
This member has no meaning if the buffer holds an outgoing message.
Definition at line 70 of file BCP_buffer.hpp.
int BCP_buffer::_sender |
The process id of the sender of the last received message.
This member has no meaning if the buffer holds an outgoing message.
Definition at line 73 of file BCP_buffer.hpp.
size_t BCP_buffer::_pos |
The next read position in the buffer.
Definition at line 75 of file BCP_buffer.hpp.
size_t BCP_buffer::_max_size |
The amount of memory allocated for the buffer.
Definition at line 77 of file BCP_buffer.hpp.
size_t BCP_buffer::_size |
The current size of the message (the first _size
bytes of the buffer).
Definition at line 80 of file BCP_buffer.hpp.
char* BCP_buffer::_data |
Pointer to the buffer itself.
Definition at line 82 of file BCP_buffer.hpp.