BCP_buffer Class Reference

This class describes the message buffer used for all processes of BCP. More...

#include <BCP_buffer.hpp>

Collaboration diagram for BCP_buffer:
Collaboration graph
[legend]

List of all members.

Public Member Functions

Query methods



BCP_message_tag msgtag () const
 Return the message tag of the message in the buffer.
const BCP_proc_idsender () const
 Return a const pointer to the process id of the sender of the message in the buffer.
int size () const
 Return the size of the current message in the buffer.
const char * data () const
 Return a const pointer to the data stored in the buffer.
Modifying methods



void set_position (const int pos) throw (BCP_fatal_error)
 Position the read/write head in the buffer.
void set_msgtag (const BCP_message_tag tag)
 Set the message tag on the buffer.
void set_content (const char *data, const size_t size, BCP_proc_id *sender, BCP_message_tag msgtag)
 Set the buffer to be a copy of the given data.
BCP_bufferoperator= (const BCP_buffer &buf)
 Make an exact replica of the other buffer.
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.
void clear ()
 Completely clear the buffer.
template<class T >
BCP_bufferpack (const T &value)
 Pack a single object of type T.
template<class T >
BCP_bufferunpack (T &value)
 Unpack a single object of type T.
template<class T >
BCP_bufferpack (const T *const values, const int length)
 Pack a C style array of objects of type T.
template<class T >
BCP_bufferunpack (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).
BCP_bufferpack (const BCP_string &value)
 Pack a BCP_string into the buffer.
BCP_bufferpack (BCP_string &value)
 Pack a BCP_string into the buffer.
BCP_bufferunpack (BCP_string &value)
 Unpack a BCP_string from the buffer.
template<class T >
BCP_bufferpack (const BCP_vec< T > &vec)
 Pack a BCP_vec into the buffer.
template<class T >
BCP_bufferpack (const std::vector< T > &vec)
 Pack a std::vector into the buffer.
template<class T >
BCP_bufferunpack (BCP_vec< T > &vec)
 Unpack a BCP_vec from the buffer.
template<class T >
BCP_bufferunpack (std::vector< T > &vec)
 Unpack a std::vector from the buffer.
Constructors and destructor



 BCP_buffer ()
 The default constructor creates a buffer of size 16 Kbytes with no message in it.
 BCP_buffer (const BCP_buffer &buf)
 The copy constructor makes an exact replica of the other buffer.
 ~BCP_buffer ()
 The desctructor deletes all data members (including freeing the buffer).

Public Attributes

Data members

The data members are public for efficiency reasons.

Access these fields sparingly.
THINK: maybe it's not that inefficient to access the fields thru functions...

Note that:

  1. The size of the buffer never decreases. The buffer size increases when the current size is not sufficient for the message.
  2. With normal usage for incoming messages _size stays constant while reading out the message and _pos moves forward in the buffer.
  3. With normal usage for outgoing messages _size and _pos moves forward together as the buffer is filled with the message.


BCP_message_tag _msgtag
 The message tag of the last received message.
BCP_proc_id_sender
 The process id of the sender of the last received message.
size_t _pos
 The next read/write position in the buffer.
size_t _max_size
 The amount of memory allocated for the buffer.
size_t _size
 The current size of the message (the first _size bytes of the buffer).
char * _data
 Pointer to the buffer itself.

Detailed Description

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:

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.


Constructor & Destructor Documentation

BCP_buffer::BCP_buffer (  )  [inline]

The default constructor creates a buffer of size 16 Kbytes with no message in it.

Definition at line 372 of file BCP_buffer.hpp.

BCP_buffer::BCP_buffer ( const BCP_buffer buf  )  [inline]

The copy constructor makes an exact replica of the other buffer.

Definition at line 375 of file BCP_buffer.hpp.

BCP_buffer::~BCP_buffer (  )  [inline]

The desctructor deletes all data members (including freeing the buffer).

Definition at line 382 of file BCP_buffer.hpp.


Member Function Documentation

BCP_message_tag BCP_buffer::msgtag (  )  const [inline]

Return the message tag of the message in the buffer.

Definition at line 89 of file BCP_buffer.hpp.

const BCP_proc_id* BCP_buffer::sender (  )  const [inline]

Return a const pointer to the process id of the sender of the message in the buffer.

Definition at line 92 of file BCP_buffer.hpp.

int BCP_buffer::size (  )  const [inline]

Return the size of the current message in the buffer.

Definition at line 94 of file BCP_buffer.hpp.

const char* BCP_buffer::data (  )  const [inline]

Return a const pointer to the data stored in the buffer.

Definition at line 96 of file BCP_buffer.hpp.

void BCP_buffer::set_position ( const int  pos  )  throw (BCP_fatal_error) [inline]

Position the read/write head in the buffer.

Must be between 0 and size().

Definition at line 104 of file BCP_buffer.hpp.

void BCP_buffer::set_msgtag ( const BCP_message_tag  tag  )  [inline]

Set the message tag on the buffer.

Definition at line 110 of file BCP_buffer.hpp.

void BCP_buffer::set_content ( const char *  data,
const size_t  size,
BCP_proc_id sender,
BCP_message_tag  msgtag 
) [inline]

Set the buffer to be a copy of the given data.

Use this with care!

Definition at line 113 of file BCP_buffer.hpp.

BCP_buffer& BCP_buffer::operator= ( const BCP_buffer buf  )  [inline]

Make an exact replica of the other buffer.

Definition at line 130 of file BCP_buffer.hpp.

void BCP_buffer::make_fit ( const int  add_size  )  [inline]

Reallocate the buffer if necessary so that at least add_size number of additional bytes will fit into the buffer.

Definition at line 147 of file BCP_buffer.hpp.

void BCP_buffer::clear (  )  [inline]

Completely clear the buffer.

Delete and zero out _msgtag, _size, _pos and _sender.

Definition at line 159 of file BCP_buffer.hpp.

template<class T >
BCP_buffer& BCP_buffer::pack ( const T &  value  )  [inline]

Pack a single object of type T.

Copies sizeof(T) bytes from the address of the object.

Definition at line 168 of file BCP_buffer.hpp.

template<class T >
BCP_buffer& BCP_buffer::unpack ( T &  value  )  [inline]

Unpack a single object of type T.

Copies sizeof(T) bytes to the address of the object.

Definition at line 177 of file BCP_buffer.hpp.

template<class T >
BCP_buffer& BCP_buffer::pack ( const T *const   values,
const int  length 
) [inline]

Pack a C style array of objects of type T.

Definition at line 188 of file BCP_buffer.hpp.

template<class T >
BCP_buffer& BCP_buffer::unpack ( T *&  values,
int &  length,
bool  allocate = true 
) throw (BCP_fatal_error) [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 213 of file BCP_buffer.hpp.

BCP_buffer& BCP_buffer::pack ( const BCP_string value  )  [inline]

Pack a BCP_string into the buffer.

Definition at line 259 of file BCP_buffer.hpp.

BCP_buffer& BCP_buffer::pack ( BCP_string value  )  [inline]

Pack a BCP_string into the buffer.

Definition at line 272 of file BCP_buffer.hpp.

BCP_buffer& BCP_buffer::unpack ( BCP_string value  )  [inline]

Unpack a BCP_string from the buffer.

Definition at line 285 of file BCP_buffer.hpp.

template<class T >
BCP_buffer& BCP_buffer::pack ( const BCP_vec< T > &  vec  )  [inline]

Pack a BCP_vec into the buffer.

Definition at line 295 of file BCP_buffer.hpp.

template<class T >
BCP_buffer& BCP_buffer::pack ( const std::vector< T > &  vec  )  [inline]

Pack a std::vector into the buffer.

Definition at line 309 of file BCP_buffer.hpp.

template<class T >
BCP_buffer& BCP_buffer::unpack ( BCP_vec< T > &  vec  )  [inline]

Unpack a BCP_vec from the buffer.

Definition at line 323 of file BCP_buffer.hpp.

template<class T >
BCP_buffer& BCP_buffer::unpack ( std::vector< T > &  vec  )  [inline]

Unpack a std::vector from the buffer.

Definition at line 345 of file BCP_buffer.hpp.


Member Data Documentation

The message tag of the last received message.

This member has no meaning if the buffer holds an outgoing message.

Definition at line 69 of file BCP_buffer.hpp.

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 72 of file BCP_buffer.hpp.

The next read/write position in the buffer.

Definition at line 74 of file BCP_buffer.hpp.

The amount of memory allocated for the buffer.

Definition at line 76 of file BCP_buffer.hpp.

The current size of the message (the first _size bytes of the buffer).

Definition at line 79 of file BCP_buffer.hpp.

Pointer to the buffer itself.

Definition at line 81 of file BCP_buffer.hpp.


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

Generated on 15 Mar 2015 for Coin-All by  doxygen 1.6.1