Commit e96cc656 authored by berenger-bramas's avatar berenger-bramas
Browse files

Comment the buffer vector class.

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/scalfmm/scalfmm/trunk@84 2616d619-271b-44dc-8df4-d4a8f33a7222
parent 92b728a0
......@@ -10,12 +10,26 @@
* @author Berenger Bramas (berenger.bramas@inria.fr)
* @class FBufferVector
* Please read the license
* This class is a buffer to send big data via MPI.
* It has a capacity and alloc an array only if needed.
* You have to be sure that the buffer is not full before adding any data.
* This can be done by checking :
* <code>
* if(!sendBuffer.addEnoughSpace(object->bytesToSendUp())){<br>
* app.sendData(idxReceiver,sendBuffer.getSize(),sendBuffer.getData(),globalTag);<br>
* sendBuffer.clear();<br>
* }<br>
* sendBuffer.addDataUp(tag,object);<br>
* </code>
*/
template <int Capacity>
class FBufferVector : protected FAssertable {
// the Buffer (can be null)
char* buffer;
// current ocupped size
int occuped;
// check if buffer is allocated if not does it
void checkBuffer(){
if(!buffer){
buffer = new char[Capacity];
......@@ -23,30 +37,38 @@ template <int Capacity>
}
public:
// Constructor, set buffer to null
FBufferVector() : buffer(0), occuped(0) {
assert(Capacity > 0, "Capacity has to be positive", __LINE__, __FILE__);
}
// Dealloc buffer if needed
~FBufferVector(){
if(buffer) delete(buffer);
}
// To check if there is enough free space
bool addEnoughSpace(const int neededSpace) const{
return occuped + neededSpace + sizeof(int) <= Capacity;
}
// get the capacity of the buffer
int getCapacity() const{
return Capacity;
}
// get the current size
int getSize(){
return occuped;
}
// get a pointer to the buffer
void* getData() {
return buffer;
}
// ask to an object to write himself into the buffer
// and update occuped space
template < class T >
void addDataUp(const int tag, const T& object){
checkBuffer();
......@@ -55,6 +77,8 @@ public:
occuped += object.writeUp(&buffer[occuped], Capacity - occuped);
}
// ask to an object to write himself into the buffer
// and update occuped space
template < class T >
void addDataDown(const int tag, const T& object){
checkBuffer();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment