105 if (pos < 0 || pos >
size())
111 if (s < 0 || s >
size())
131 memcpy(
_data, data, size *
sizeof(
char));
199 make_fit(
sizeof(
int) +
sizeof(T) * length );
203 memcpy(
_data +
_size, values,
sizeof(T) * length);
204 _size +=
sizeof(T) * length;
223 bool allocate =
true)
228 throw BCP_fatal_error(
"Reading over the end of buffer.\n");
230 memcpy(&length,
_data +
_pos,
sizeof(
int));
235 throw BCP_fatal_error(
"Reading over the end of buffer.\n");
237 values =
new T[length];
238 memcpy(values,
_data +
_pos,
sizeof(T)*length);
239 _pos +=
sizeof(T) * length;
247 throw BCP_fatal_error(
"Reading over the end of buffer.\n");
252 throw BCP_fatal_error(
"BCP_buffer::unpack() : bad array lentgh.\n");
256 throw BCP_fatal_error(
"Reading over the end of buffer.\n");
258 memcpy(values,
_data +
_pos,
sizeof(T)*length);
259 _pos +=
sizeof(T) * length;
305 int objnum = vec.
size();
306 int new_bytes = objnum *
sizeof(T);
307 make_fit(
sizeof(
int) + new_bytes );
319 int objnum = vec.
size();
320 int new_bytes = objnum *
sizeof(T);
321 make_fit(
sizeof(
int) + new_bytes );
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_buffer & pack(const T &value)
Pack a single object of type T.
Used to indicate that there is no message in the buffer of a process.
BCP_buffer & unpack(T &value)
Unpack a single object of type T.
BCP_buffer & unpack(std::vector< T > &vec)
Unpack a std::vector from the buffer.
BCP_buffer & pack(const std::vector< T > &vec)
Pack a std::vector into the buffer.
BCP_buffer & pack(const T *const values, const int length)
Pack a C style array of objects of type T.
BCP_buffer & pack(const BCP_string &value)
Pack a BCP_string into the buffer.
pos
position where the operator should be printed when printing the expression
void clear()
Delete every entry.
int _sender
The process id of the sender of the last received message.
const char * c_str() const
int sender() const
Return a const pointer to the process id of the sender of the message in the buffer.
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.
This class is a very simple impelementation of a constant length string.
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.
size_t _pos
The next read position in the buffer.
size_t _max_size
The amount of memory allocated for the buffer.
BCP_string & assign(const char *source, const int len)
BCP_buffer & operator=(const BCP_buffer &buf)
Make an exact replica of the other buffer.
BCP_buffer & unpack(BCP_vec< T > &vec)
Unpack a BCP_vec from the buffer.
void set_msgtag(const BCP_message_tag tag)
Set the message tag on the buffer.
void fint fint fint fint fint fint fint fint fint fint real real real real real real real real * s
~BCP_buffer()
The desctructor deletes all data members (including freeing the buffer).
char * _data
Pointer to the buffer itself.
void clear()
Completely clear the buffer.
BCP_message_tag msgtag() const
Return the message tag of the message in the buffer.
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...
BCP_buffer(const BCP_buffer &buf)
The copy constructor makes an exact replica of the other buffer.
void set_size(const int s)
Cut off the end of the buffer.
Currently there isn't any error handling in BCP.
size_t size() const
Return the current number of entries.
iterator end()
Return an iterator to the end of the object.
The class BCP_vec serves the same purpose as the vector class in the standard template library...
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...
size_t _size
The current size of the message (the first _size bytes of the buffer).
This class describes the message buffer used for all processes of BCP.
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...
BCP_buffer & pack(const BCP_vec< T > &vec)
Pack a BCP_vec into the buffer.
const char * data() const
Return a const pointer to the data stored in the buffer.
BCP_buffer()
The default constructor creates a buffer of size 16 Kbytes with no message in it. ...
void set_position(const int pos)
Position the read head in the buffer.
BCP_buffer & pack(BCP_string &value)
Pack a BCP_string into the buffer.
BCP_message_tag _msgtag
The message tag of the last received message.
BCP_buffer & unpack(BCP_string &value)
Unpack a BCP_string from the buffer.
int size() const
Return the size of the current message in the buffer.