coin-Bcp
List of all members
BCP_buffer Class Reference

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_bufferoperator= (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_bufferpack (const T &value)
 Pack a single object of type T. More...
 
template<class T >
BCP_bufferunpack (T &value)
 Unpack a single object of type T. More...
 
template<class T >
BCP_bufferpack (const T *const values, const int length)
 Pack a C style array of objects of type T. More...
 
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). More...
 
BCP_bufferpack (const BCP_string &value)
 Pack a BCP_string into the buffer. More...
 
BCP_bufferpack (BCP_string &value)
 Pack a BCP_string into the buffer. More...
 
BCP_bufferunpack (BCP_string &value)
 Unpack a BCP_string from the buffer. More...
 
template<class T >
BCP_bufferpack (const BCP_vec< T > &vec)
 Pack a BCP_vec into the buffer. More...
 
template<class T >
BCP_bufferpack (const std::vector< T > &vec)
 Pack a std::vector into the buffer. More...
 
template<class T >
BCP_bufferunpack (BCP_vec< T > &vec)
 Unpack a BCP_vec from the buffer. More...
 
template<class T >
BCP_bufferunpack (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.
THINK: maybe it's not that inefficient to access the fields thru functions...

Note that:

  1. The max size of the buffer never decreases. The buffer max size increases when the current max 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. 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...
 

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

References operator=().

BCP_buffer::~BCP_buffer ( )
inline

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

Definition at line 392 of file BCP_buffer.hpp.

References _data.

Member Function Documentation

BCP_message_tag BCP_buffer::msgtag ( ) const
inline

Return the message tag of the message in the buffer.

Definition at line 90 of file BCP_buffer.hpp.

References _msgtag.

Referenced by set_content().

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

References _sender.

Referenced by set_content().

int BCP_buffer::size ( ) const
inline

Return the size of the current message in the buffer.

Definition at line 95 of file BCP_buffer.hpp.

References _size.

Referenced by pack(), set_content(), set_position(), and set_size().

const char* BCP_buffer::data ( ) const
inline

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

Definition at line 97 of file BCP_buffer.hpp.

References _data.

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

Position the read head in the buffer.

Must be between 0 and size().

Definition at line 104 of file BCP_buffer.hpp.

References _pos, and size().

void BCP_buffer::set_size ( const int  s)
throw (BCP_fatal_error
)
inline

Cut off the end of the buffer.

Must be between 0 and size().

Definition at line 110 of file BCP_buffer.hpp.

References _size, and size().

void BCP_buffer::set_msgtag ( const BCP_message_tag  tag)
inline

Set the message tag on the buffer.

Definition at line 116 of file BCP_buffer.hpp.

References _msgtag.

void BCP_buffer::set_content ( const char *  data,
const size_t  size,
int  sender,
BCP_message_tag  msgtag 
)
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.

References _data, _max_size, _msgtag, _pos, _sender, _size, msgtag(), sender(), and size().

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

Make an exact replica of the other buffer.

Definition at line 136 of file BCP_buffer.hpp.

References _data, _max_size, _msgtag, _pos, _sender, and _size.

Referenced by BCP_buffer().

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

References _data, _max_size, and _size.

Referenced by pack().

void BCP_buffer::clear ( )
inline

Completely clear the buffer.

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

Definition at line 168 of file BCP_buffer.hpp.

References _msgtag, _pos, _sender, _size, and BCP_Msg_NoMessage.

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

References _data, _size, and make_fit().

Referenced by MKC_var_pack(), CSP_packedVector::pack(), MKC_var::pack(), MKC_branching_var::pack(), CSPROBLEM::pack(), PATTERN::pack(), BCP_vec_change< char >::pack(), and BCP_parameter_set< BCP_tm_par >::pack().

template<class T >
BCP_buffer& BCP_buffer::unpack ( T &  value)
inline
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 197 of file BCP_buffer.hpp.

References _data, _size, and make_fit().

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

References _data, _pos, and _size.

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

Pack a BCP_string into the buffer.

Definition at line 268 of file BCP_buffer.hpp.

References _data, _size, BCP_string::c_str(), BCP_string::length(), and make_fit().

BCP_buffer& BCP_buffer::pack ( BCP_string value)
inline

Pack a BCP_string into the buffer.

Definition at line 281 of file BCP_buffer.hpp.

References _data, _size, BCP_string::c_str(), BCP_string::length(), and make_fit().

BCP_buffer& BCP_buffer::unpack ( BCP_string value)
inline

Unpack a BCP_string from the buffer.

Definition at line 294 of file BCP_buffer.hpp.

References _data, _pos, BCP_string::assign(), and unpack().

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

Pack a BCP_vec into the buffer.

Definition at line 304 of file BCP_buffer.hpp.

References _data, _size, BCP_vec< T >::begin(), make_fit(), and BCP_vec< T >::size().

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

Pack a std::vector into the buffer.

Definition at line 318 of file BCP_buffer.hpp.

References _data, _size, make_fit(), and size().

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

Unpack a BCP_vec from the buffer.

Definition at line 332 of file BCP_buffer.hpp.

References _data, _pos, _size, BCP_vec< T >::clear(), BCP_vec< T >::end(), BCP_vec< T >::insert(), and BCP_vec< T >::reserve().

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

Unpack a std::vector from the buffer.

Definition at line 354 of file BCP_buffer.hpp.

References _data, _pos, and _size.

Member Data Documentation

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.

Referenced by clear(), msgtag(), operator=(), set_content(), and set_msgtag().

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.

Referenced by clear(), operator=(), sender(), and set_content().

size_t BCP_buffer::_pos

The next read position in the buffer.

Definition at line 75 of file BCP_buffer.hpp.

Referenced by clear(), operator=(), set_content(), set_position(), and unpack().

size_t BCP_buffer::_max_size

The amount of memory allocated for the buffer.

Definition at line 77 of file BCP_buffer.hpp.

Referenced by make_fit(), operator=(), and set_content().

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.

Referenced by clear(), make_fit(), operator=(), pack(), set_content(), set_size(), size(), and unpack().

char* BCP_buffer::_data

Pointer to the buffer itself.

Definition at line 82 of file BCP_buffer.hpp.

Referenced by data(), make_fit(), operator=(), pack(), set_content(), unpack(), and ~BCP_buffer().


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