#include <BCP_buffer.hpp>
Public Member Functions | |
Query methods | |
BCP_message_tag | msgtag () const |
const BCP_proc_id * | sender () const |
int | size () const |
const char * | data () const |
Modifying methods | |
void | set_position (const int pos) throw (BCP_fatal_error) |
void | set_msgtag (const BCP_message_tag tag) |
void | set_content (const char *data, const size_t size, BCP_proc_id *sender, BCP_message_tag msgtag) |
BCP_buffer & | operator= (const BCP_buffer &buf) |
void | make_fit (const int add_size) |
void | clear () |
template<class T> BCP_buffer & | pack (const T &value) |
template<class T> BCP_buffer & | unpack (T &value) |
template<class T> BCP_buffer & | pack (const T *const values, const int length) |
template<class T> BCP_buffer & | unpack (T *&values, int &length, bool allocate=true) throw (BCP_fatal_error) |
BCP_buffer & | pack (const BCP_string &value) |
BCP_buffer & | pack (BCP_string &value) |
BCP_buffer & | unpack (BCP_string &value) |
template<class T> BCP_buffer & | pack (const BCP_vec< T > &vec) |
template<class T> BCP_buffer & | pack (const typename std::vector< T > &vec) |
template<class T> BCP_buffer & | unpack (BCP_vec< T > &vec) |
template<class T> BCP_buffer & | unpack (typename std::vector< T > &vec) |
Constructors and destructor | |
BCP_buffer () | |
BCP_buffer (const BCP_buffer &buf) | |
~BCP_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:
| |
BCP_message_tag | _msgtag |
BCP_proc_id * | _sender |
size_t | _pos |
size_t | _max_size |
size_t | _size |
char * | _data |
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. pack()
member method.
Definition at line 39 of file BCP_buffer.hpp.
|
The default constructor creates a buffer of size 16 Kbytes with no message in it. Definition at line 372 of file BCP_buffer.hpp. References _data, _max_size, _msgtag, _pos, _sender, and _size.
|
|
The copy constructor makes an exact replica of the other buffer. Definition at line 375 of file BCP_buffer.hpp. References _data, _max_size, _msgtag, _pos, _sender, _size, and operator=().
|
|
The desctructor deletes all data members (including freeing the buffer). Definition at line 382 of file BCP_buffer.hpp. References _data, and _sender.
|
|
Completely clear the buffer. Delete and zero out Definition at line 159 of file BCP_buffer.hpp. References _msgtag, _pos, _sender, and _size. Referenced by BCP_cg_user::send_cut(), and BCP_vg_user::send_var().
|
|
Return a const pointer to the data stored in the buffer. Definition at line 96 of file BCP_buffer.hpp. References _data.
00096 { return _data; } |
|
Reallocate the buffer if necessary so that at least Definition at line 147 of file BCP_buffer.hpp. References _data, _max_size, and _size. Referenced by pack().
|
|
Return the message tag of the message in the buffer. Definition at line 89 of file BCP_buffer.hpp. References _msgtag. Referenced by BCP_vg_user::unpack_dual_solution(), and BCP_cg_user::unpack_primal_solution().
00089 { return _msgtag; } |
|
Make an exact replica of the other buffer. Definition at line 130 of file BCP_buffer.hpp. References _data, _max_size, _msgtag, _pos, _sender, _size, and BCP_proc_id::clone(). Referenced by BCP_buffer().
00130 { 00131 _msgtag = buf._msgtag; 00132 _sender = buf._sender ? buf._sender->clone() : 0; 00133 _pos = buf._pos; 00134 if (_max_size < buf._max_size) { 00135 delete[] _data; 00136 _data = new char[buf._max_size]; 00137 _max_size = buf._max_size; 00138 } 00139 _size = buf._size; 00140 if (_size) 00141 memcpy(_data, buf._data, _size * sizeof(char)); 00142 return *this; 00143 } |
|
Pack a Definition at line 309 of file BCP_buffer.hpp. References _data, _size, make_fit(), and size().
00309 { 00310 int objnum = vec.size(); 00311 int new_bytes = objnum * sizeof(T); 00312 make_fit( sizeof(int) + new_bytes ); 00313 memcpy(_data + _size, &objnum, sizeof(int)); 00314 _size += sizeof(int); 00315 if (objnum > 0){ 00316 memcpy(_data + _size, &vec[0], new_bytes); 00317 _size += new_bytes; 00318 } 00319 return *this; 00320 } |
|
Pack a Definition at line 295 of file BCP_buffer.hpp. References _data, _size, BCP_vec< T >::begin(), make_fit(), and BCP_vec< T >::size().
00295 { 00296 int objnum = vec.size(); 00297 int new_bytes = objnum * sizeof(T); 00298 make_fit( sizeof(int) + new_bytes ); 00299 memcpy(_data + _size, &objnum, sizeof(int)); 00300 _size += sizeof(int); 00301 if (objnum > 0){ 00302 memcpy(_data + _size, vec.begin(), new_bytes); 00303 _size += new_bytes; 00304 } 00305 return *this; 00306 } |
|
Pack a Definition at line 272 of file BCP_buffer.hpp. References _data, _size, BCP_string::c_str(), BCP_string::length(), and make_fit().
00272 { 00273 // must define here, 'cos in BCP_message.C we have only templated members 00274 int len = value.length(); 00275 make_fit( sizeof(int) + len ); 00276 memcpy(_data + _size, &len, sizeof(int)); 00277 _size += sizeof(int); 00278 if (len > 0){ 00279 memcpy(_data + _size, value.c_str(), len); 00280 _size += len; 00281 } 00282 return *this; 00283 } |
|
Pack a Definition at line 259 of file BCP_buffer.hpp. References _data, _size, BCP_string::c_str(), BCP_string::length(), and make_fit().
00259 { 00260 // must define here, 'cos in BCP_message.C we have only templated members 00261 int len = value.length(); 00262 make_fit( sizeof(int) + len ); 00263 memcpy(_data + _size, &len, sizeof(int)); 00264 _size += sizeof(int); 00265 if (len > 0){ 00266 memcpy(_data + _size, value.c_str(), len); 00267 _size += len; 00268 } 00269 return *this; 00270 } |
|
Pack a C style array of objects of type Definition at line 188 of file BCP_buffer.hpp. References _data, _size, and make_fit().
00189 { 00190 make_fit( sizeof(int) + sizeof(T) * length ); 00191 memcpy(_data + _size, &length, sizeof(int)); 00192 _size += sizeof(int); 00193 if (length > 0){ 00194 memcpy(_data + _size, values, sizeof(T) * length); 00195 _size += sizeof(T) * length; 00196 } 00197 return *this; 00198 } |
|
Pack a single object of type Definition at line 168 of file BCP_buffer.hpp. References _data, _size, and make_fit(). Referenced by BCP_vec_change< char >::pack(), BCP_problem_core_change::pack(), BCP_problem_core::pack(), BCP_parameter_set< BCP_tm_par >::pack(), BCP_lp_relax::pack(), BCP_internal_brobj::pack(), BCP_lp_user::pack_dual_solution(), BCP_lp_user::pack_feasible_solution(), BCP_lp_user::pack_primal_solution(), BCP_cg_user::send_cut(), and BCP_vg_user::send_var().
00168 { 00169 make_fit( sizeof(T) ); 00170 memcpy(_data + _size, &value, sizeof(T)); 00171 _size += sizeof(T); 00172 return *this; 00173 } |
|
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. References _sender.
00092 { return _sender; } |
|
Set the buffer to be a copy of the given data. Use this with care! Definition at line 113 of file BCP_buffer.hpp. References _data, _max_size, _msgtag, _pos, _sender, and _size.
|
|
Set the message tag on the buffer Definition at line 110 of file BCP_buffer.hpp. References _msgtag. Referenced by BCP_lp_user::pack_dual_solution(), and BCP_lp_user::pack_primal_solution().
00110 { _msgtag = tag; } |
|
Position the read/write head in the buffer. Must be between 0 and size(). Definition at line 104 of file BCP_buffer.hpp.
00104 { 00105 if (pos < 0 || pos >= size()) 00106 throw BCP_fatal_error("Incorrest buffer position setting.\n"); 00107 _pos = pos; 00108 } |
|
Return the size of the current message in the buffer. Definition at line 94 of file BCP_buffer.hpp. References _size. Referenced by pack(), and set_position().
00094 { return _size; } |
|
Unpack a Definition at line 345 of file BCP_buffer.hpp. References _data, _pos, and _size.
00345 { 00346 int objnum; 00347 #ifdef PARANOID 00348 if (_pos + sizeof(int) > _size) 00349 throw BCP_fatal_error("Reading over the end of buffer.\n"); 00350 #endif 00351 memcpy(&objnum, _data + _pos, sizeof(int)); 00352 _pos += sizeof(int); 00353 vec.clear(); 00354 if (objnum > 0){ 00355 #ifdef PARANOID 00356 if (_pos + sizeof(T)*objnum > _size) 00357 throw BCP_fatal_error("Reading over the end of buffer.\n"); 00358 #endif 00359 vec.insert(vec.end(), objnum, T()); 00360 memcpy(&vec[0], _data + _pos, objnum * sizeof(T)); 00361 _pos += objnum * sizeof(T); 00362 } 00363 return *this; 00364 } |
|
Unpack a Definition at line 323 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().
00323 { 00324 int objnum; 00325 #ifdef PARANOID 00326 if (_pos + sizeof(int) > _size) 00327 throw BCP_fatal_error("Reading over the end of buffer.\n"); 00328 #endif 00329 memcpy(&objnum, _data + _pos, sizeof(int)); 00330 _pos += sizeof(int); 00331 vec.clear(); 00332 if (objnum > 0){ 00333 #ifdef PARANOID 00334 if (_pos + sizeof(T)*objnum > _size) 00335 throw BCP_fatal_error("Reading over the end of buffer.\n"); 00336 #endif 00337 vec.reserve(objnum); 00338 vec.insert(vec.end(), _data + _pos, objnum); 00339 _pos += objnum * sizeof(T); 00340 } 00341 return *this; 00342 } |
|
Unpack a Definition at line 285 of file BCP_buffer.hpp. References _data, _pos, BCP_string::assign(), and unpack().
|
|
Unpack an array of objects of type 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 Definition at line 213 of file BCP_buffer.hpp. References _data, _pos, and _size.
00215 { 00216 if (allocate) { 00217 #ifdef PARANOID 00218 if (_pos + sizeof(int) > _size) 00219 throw BCP_fatal_error("Reading over the end of buffer.\n"); 00220 #endif 00221 memcpy(&length, _data + _pos, sizeof(int)); 00222 _pos += sizeof(int); 00223 if (length > 0){ 00224 #ifdef PARANOID 00225 if (_pos + sizeof(T)*length > _size) 00226 throw BCP_fatal_error("Reading over the end of buffer.\n"); 00227 #endif 00228 values = new T[length]; 00229 memcpy(values, _data + _pos, sizeof(T)*length); 00230 _pos += sizeof(T) * length; 00231 } 00232 00233 } else { /* ! allocate */ 00234 00235 int l; 00236 #ifdef PARANOID 00237 if (_pos + sizeof(int) > _size) 00238 throw BCP_fatal_error("Reading over the end of buffer.\n"); 00239 #endif 00240 memcpy(&l, _data + _pos, sizeof(int)); 00241 _pos += sizeof(int); 00242 if (l != length) 00243 throw BCP_fatal_error("BCP_buffer::unpack() : bad array lentgh.\n"); 00244 if (length > 0){ 00245 #ifdef PARANOID 00246 if (_pos + sizeof(T)*length > _size) 00247 throw BCP_fatal_error("Reading over the end of buffer.\n"); 00248 #endif 00249 memcpy(values, _data + _pos, sizeof(T)*length); 00250 _pos += sizeof(T) * length; 00251 } 00252 00253 } 00254 00255 return *this; 00256 } |
|
Unpack a single object of type Definition at line 177 of file BCP_buffer.hpp. References _data, _pos, and _size. Referenced by BCP_vg_prob::probe_messages(), BCP_cg_prob::probe_messages(), BCP_vec_change< char >::unpack(), BCP_problem_core_change::unpack(), BCP_problem_core::unpack(), BCP_parameter_set< BCP_tm_par >::unpack(), BCP_lp_relax::unpack(), unpack(), BCP_internal_brobj::unpack(), BCP_vg_prob::unpack_cut(), BCP_vg_user::unpack_dual_solution(), BCP_tm_user::unpack_feasible_solution(), BCP_cg_user::unpack_primal_solution(), and BCP_cg_prob::unpack_var().
00177 { 00178 #ifdef PARANOID 00179 if (_pos + sizeof(T) > _size) 00180 throw BCP_fatal_error("Reading over the end of buffer.\n"); 00181 #endif 00182 memcpy(&value, _data + _pos, sizeof(T)); 00183 _pos += sizeof(T); 00184 return *this; 00185 } |
|
Pointer to the buffer itself. Definition at line 81 of file BCP_buffer.hpp. Referenced by BCP_buffer(), data(), make_fit(), operator=(), pack(), set_content(), unpack(), and ~BCP_buffer(). |
|
The amount of memory allocated for the buffer. Definition at line 76 of file BCP_buffer.hpp. Referenced by BCP_buffer(), make_fit(), operator=(), and set_content(). |
|
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. Referenced by BCP_buffer(), clear(), msgtag(), operator=(), set_content(), and set_msgtag(). |
|
The next read/write position in the buffer. Definition at line 74 of file BCP_buffer.hpp. Referenced by BCP_buffer(), clear(), operator=(), set_content(), set_position(), and unpack(). |
|
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. Referenced by BCP_buffer(), clear(), operator=(), sender(), set_content(), and ~BCP_buffer(). |
|
The current size of the message (the first Definition at line 79 of file BCP_buffer.hpp. Referenced by BCP_buffer(), clear(), make_fit(), operator=(), pack(), set_content(), size(), and unpack(). |