105 if (pos < 0 || pos >
size())
111 if (s < 0 || s >
size())
199 make_fit(
sizeof(
int) +
sizeof(T) * length );
201 _size +=
sizeof(int);
203 memcpy(
_data +
_size, values,
sizeof(T) * length);
204 _size +=
sizeof(T) * length;
223 bool allocate =
true)
230 memcpy(&length,
_data +
_pos,
sizeof(
int));
237 values =
new T[length];
238 memcpy(values,
_data +
_pos,
sizeof(T)*length);
239 _pos +=
sizeof(T) * length;
258 memcpy(values,
_data +
_pos,
sizeof(T)*length);
259 _pos +=
sizeof(T) * length;
273 _size +=
sizeof(int);
286 _size +=
sizeof(int);
305 int objnum = vec.
size();
306 int new_bytes = objnum *
sizeof(T);
307 make_fit(
sizeof(
int) + new_bytes );
309 _size +=
sizeof(int);
319 int objnum = vec.size();
320 int new_bytes = objnum *
sizeof(T);
321 make_fit(
sizeof(
int) + new_bytes );
323 _size +=
sizeof(int);
338 memcpy(&objnum,
_data +
_pos,
sizeof(
int));
348 _pos += objnum *
sizeof(T);
360 memcpy(&objnum,
_data +
_pos,
sizeof(
int));
368 vec.insert(vec.end(), objnum, T());
369 memcpy(&vec[0],
_data +
_pos, objnum *
sizeof(T));
370 _pos += objnum *
sizeof(T);
BCP_message_tag
This enumerative constant describes the message tags different processes of BCP understand.
@ BCP_Msg_NoMessage
Used to indicate that there is no message in the buffer of a process.
BCP_buffer & operator=(const BCP_buffer &buf)
Make an exact replica of the other buffer.
void clear()
Completely clear the buffer.
BCP_buffer(const BCP_buffer &buf)
The copy constructor makes an exact replica of the other buffer.
BCP_buffer & pack(const BCP_vec< T > &vec)
Pack a BCP_vec into the buffer.
int size() const
Return the size of the current message in the buffer.
BCP_buffer & unpack(BCP_vec< T > &vec)
Unpack a BCP_vec from the 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...
const char * data() const
Return a const pointer to the data stored in the buffer.
size_t _pos
The next read position in the buffer.
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.
void set_size(const int s)
Cut off the end of the buffer.
int sender() const
Return a const pointer to the process id of the sender of the message in the buffer.
BCP_buffer & unpack(T *&values, int &length, bool allocate=true)
Unpack an array of objects of type T, where T must be a built-in type (ar at least something that can...
int _sender
The process id of the sender of the last received message.
BCP_buffer()
The default constructor creates a buffer of size 16 Kbytes with no message in it.
BCP_buffer & pack(const BCP_string &value)
Pack a BCP_string into the buffer.
BCP_buffer & pack(const T *const values, const int length)
Pack a C style array of objects of type T.
void set_position(const int pos)
Position the read head in the buffer.
void set_msgtag(const BCP_message_tag tag)
Set the message tag on the buffer.
BCP_buffer & unpack(BCP_string &value)
Unpack a BCP_string from the buffer.
size_t _size
The current size of the message (the first _size bytes of the buffer).
BCP_buffer & pack(const std::vector< T > &vec)
Pack a std::vector into the buffer.
BCP_buffer & pack(const T &value)
Pack a single object of type T.
BCP_message_tag msgtag() const
Return the message tag of the message in the buffer.
char * _data
Pointer to the buffer itself.
BCP_buffer & unpack(T &value)
Unpack a single object of type T.
BCP_message_tag _msgtag
The message tag of the last received message.
size_t _max_size
The amount of memory allocated for the buffer.
BCP_buffer & unpack(std::vector< T > &vec)
Unpack a std::vector from the buffer.
BCP_buffer & pack(BCP_string &value)
Pack a BCP_string into the buffer.
~BCP_buffer()
The desctructor deletes all data members (including freeing the buffer).
Currently there isn't any error handling in BCP.
This class is a very simple impelementation of a constant length string.
const char * c_str() const
BCP_string & assign(const char *source, const int len)
The class BCP_vec serves the same purpose as the vector class in the standard template library.
void clear()
Delete every entry.
iterator end()
Return an iterator to the end of the object.
size_t size() const
Return the current number of entries.
iterator begin()
Return an iterator to the beginning of the object.
void reserve(const size_t n)
Reallocate the object to make space for n entries.
void insert(iterator position, const void *first, const size_t num)
Insert num entries starting from memory location first into the vector from position pos.