Commit 4988434c authored by BRAMAS Berenger's avatar BRAMAS Berenger

Add abstract buffer and use it around

parent cb32d3d9
......@@ -16,9 +16,6 @@
#ifndef FABSTRACTSENDABLE_HPP
#define FABSTRACTSENDABLE_HPP
class FBufferReader;
class FBufferWriter;
/**
* @author Berenger Bramas (berenger.bramas@inria.fr)
* @class FAbstractSendable
......@@ -36,18 +33,30 @@ protected:
///////////////////////////////////////////////
/** Save your data */
virtual void serializeUp(FBufferWriter&) const = 0;
template <class BufferWriterClass>
void serializeUp(BufferWriterClass&) const{
static_assert(sizeof(BufferWriterClass) == 0 , "Your class should implement serializeUp");
}
/** Retrieve your data */
virtual void deserializeUp(FBufferReader&) = 0;
template <class BufferReaderClass>
void deserializeUp(BufferReaderClass&){
static_assert(sizeof(BufferWriterClass) == 0 , "Your class should implement deserializeUp");
}
///////////////////////////////////////////////
// For Downward pass
///////////////////////////////////////////////
/** Save your data */
virtual void serializeDown(FBufferWriter&) const = 0;
template <class BufferWriterClass>
void serializeDown(BufferWriterClass&) const{
static_assert(sizeof(BufferWriterClass) == 0 , "Your class should implement serializeDown");
}
/** Retrieve your data */
virtual void deserializeDown(FBufferReader&) = 0;
template <class BufferReaderClass>
void deserializeDown(BufferReaderClass&){
static_assert(sizeof(BufferWriterClass) == 0 , "Your class should implement deserializeDown");
}
};
......
......@@ -16,8 +16,6 @@
#ifndef FABSTRACTSERIALIZABLE_HPP
#define FABSTRACTSERIALIZABLE_HPP
class FBufferReader;
class FBufferWriter;
/**
* @author Berenger Bramas (berenger.bramas@inria.fr)
......@@ -29,8 +27,14 @@ class FBufferWriter;
*/
class FAbstractSerializable {
protected:
virtual void save(FBufferWriter&) const = 0;
virtual void restore(FBufferReader&) = 0;
template <class BufferWriterClass>
void save(BufferWriterClass&) const{
static_assert(sizeof(BufferWriterClass) == 0 , "Your class should implement save");
}
template <class BufferReaderClass>
void restore(BufferReaderClass&){
static_assert(sizeof(BufferReaderClass) == 0 , "Your class should implement restore");
}
};
#endif // FABSTRACTSERIALIZABLE_HPP
......@@ -16,7 +16,7 @@
#ifndef FBASICCELL_HPP
#define FBASICCELL_HPP
#include "FAbstractSerializable.hpp"
#include "../Extensions/FExtendMortonIndex.hpp"
#include "../Extensions/FExtendCoordinate.hpp"
......@@ -34,7 +34,7 @@
*
*
*/
class FBasicCell : public FExtendMortonIndex, public FExtendCoordinate {
class FBasicCell : public FExtendMortonIndex, public FExtendCoordinate, public FAbstractSerializable {
public:
/** Default destructor */
virtual ~FBasicCell(){
......
......@@ -17,6 +17,7 @@
#define FBASICPARTICLECONTAINER_HPP
#include "FAbstractParticleContainer.hpp"
#include "FAbstractSerializable.hpp"
#include "../Utils/FAlignedMemory.hpp"
#include "../Utils/FMath.hpp"
......@@ -42,7 +43,7 @@
* @code AStruct* strucs = container.getAttributes<0>();
*/
template <unsigned NbAttributesPerParticle, class AttributeClass = FReal >
class FBasicParticleContainer : public FAbstractParticleContainer {
class FBasicParticleContainer : public FAbstractParticleContainer, public FAbstractSerializable {
protected:
/** The number of particles in the container */
int nbParticles;
......@@ -252,7 +253,8 @@ public:
}
/** Save the current cell in a buffer */
void save(FBufferWriter& buffer) const{
template <class BufferWriterClass>
void save(BufferWriterClass& buffer) const{
buffer << nbParticles;
for(int idx = 0 ; idx < 3 ; ++idx){
buffer.write(positions[idx], nbParticles);
......@@ -262,7 +264,8 @@ public:
}
}
/** Restore the current cell from a buffer */
void restore(FBufferReader& buffer){
template <class BufferReaderClass>
void restore(BufferReaderClass& buffer){
buffer >> nbParticles;
if( nbParticles >= allocatedParticles ){
// allocate memory
......
#ifndef FABSTRACTBUFFER_HPP
#define FABSTRACTBUFFER_HPP
class FAbstractBufferReader {
public:
virtual ~FAbstractBufferReader(){
}
virtual char* data() = 0;
virtual const char* data() const = 0;
virtual int getSize() const = 0;
virtual void seek(const int inIndex) = 0;
virtual int tell() const = 0;
virtual void reserve(const int nbBytes) = 0;
virtual void reset() = 0;
template <class ClassType>
ClassType getValue(){
static_assert(sizeof(ClassType) == 0, "Your Buffer should implement getValue.");
return ClassType();
}
template <class ClassType>
void fillValue(ClassType* const){
static_assert(sizeof(ClassType) == 0, "Your Buffer should implement fillValue.");
}
template <class ClassType>
void fillArray(ClassType* const , const int ){
static_assert(sizeof(ClassType) == 0, "Your Buffer should implement fillArray.");
}
template <class ClassType>
FAbstractBufferReader& operator>>(ClassType& ){
static_assert(sizeof(ClassType) == 0, "Your Buffer should implement operator>>.");
return *this;
}
};
class FAbstractBufferWriter {
public:
virtual ~FAbstractBufferWriter(){
}
virtual char* data() = 0;
virtual const char* data() const = 0;
virtual int getSize() const = 0;
virtual void reset() = 0;
template <class ClassType>
void write(const ClassType& object){
static_assert(sizeof(ClassType) == 0, "Your Buffer should implement write.");
}
template <class ClassType>
void writeAt(const int position, const ClassType& object){
static_assert(sizeof(ClassType) == 0, "Your Buffer should implement writeAt.");
}
template <class ClassType>
void write(const ClassType* const objects, const int inSize){
static_assert(sizeof(ClassType) == 0, "Your Buffer should implement write.");
}
template <class ClassType>
FAbstractBufferWriter& operator<<(const ClassType& ){
static_assert(sizeof(ClassType) == 0, "Your Buffer should implement operator<<.");
return *this;
}
};
#endif // FABSTRACTBUFFER_HPP
......@@ -17,7 +17,7 @@
#define FBUFFERREADER_HPP
#include "FVector.hpp"
#include "FAbstractBuffer.hpp"
/** @author Berenger Bramas
* This class provide a fast way to manage a memory and convert
......@@ -26,7 +26,7 @@
* Specifie the needed space with reserve, then fill it with data
* finaly read and convert.
*/
class FBufferReader {
class FBufferReader : public FAbstractBufferReader {
FVector<char> buffer; //< The memory buffer
int index; //< The current index reading position
......
......@@ -17,6 +17,7 @@
#define FBUFFERWRITER_HPP
#include "FVector.hpp"
#include "FAbstractBuffer.hpp"
/** @author Berenger Bramas
* This class provide a fast way to manage a memory and fill it
......@@ -25,7 +26,7 @@
* then insert back if needed
* finaly use data pointer as you like
*/
class FBufferWriter {
class FBufferWriter : public FAbstractBufferWriter {
private:
FVector<char> buffer; //< The buffer
......
......@@ -18,6 +18,7 @@
#include <memory>
#include "../Utils/FMpi.hpp"
#include "FAbstractBuffer.hpp"
/** @author Cyrille Piacibello
......@@ -27,7 +28,7 @@
* then insert back if needed
* finally use data pointer as you like
*/
class FMpiBufferReader {
class FMpiBufferReader : public FAbstractBufferReader {
const MPI_Comm comm; //< Communicator needed by MPI_Pack functions
const int arrayCapacity; //< Allocated space
std::unique_ptr<char[]> array; //< Allocated Array
......
......@@ -18,6 +18,7 @@
#include <memory>
#include "../Utils/FMpi.hpp"
#include "FAbstractBuffer.hpp"
/** @author Cyrille Piacibello
* This class provide the same features as FBufferWriter using MPI_Pack system
......@@ -26,7 +27,7 @@
* then insert back if needed
* finally use data pointer as you like
*/
class FMpiBufferWriter {
class FMpiBufferWriter : public FAbstractBufferWriter {
const MPI_Comm mpiComm; //< Communicator needed by MPI_Pack functions
const int arrayCapacity; //< Allocated Space
std::unique_ptr<char[]> array; //< Allocated Array
......
......@@ -21,6 +21,8 @@
#include "../Utils/FGlobal.hpp"
#include "../Utils/FMath.hpp"
#include "../Components/FAbstractSerializable.hpp"
/**
* @author Berenger Bramas (berenger.bramas@inria.fr)
* @class FTreeCoordinate
......@@ -31,7 +33,7 @@
* It is directly related to morton index, as interleaves
* bits from this coordinate make the morton index
*/
class FTreeCoordinate{
class FTreeCoordinate : public FAbstractSerializable {
private:
int data[3]; //< all box-th position
......
......@@ -16,9 +16,6 @@
#ifndef FEXTENDCELLTYPE_HPP
#define FEXTENDCELLTYPE_HPP
#include "../Containers/FBufferReader.hpp"
#include "../Containers/FBufferWriter.hpp"
/**
* @author Berenger Bramas (berenger.bramas@inria.fr)
* @class FExtendCellType
......@@ -73,12 +70,14 @@ public:
public:
/** Save current object */
void save(FBufferWriter& buffer) const {
template <class BufferWriterClass>
void save(BufferWriterClass& buffer) const {
buffer << containsTargets;
buffer << containsSources;
}
/** Retrieve current object */
void restore(FBufferReader& buffer) {
template <class BufferReaderClass>
void restore(BufferReaderClass& buffer) {
buffer >> containsTargets;
buffer >> containsSources;
}
......
......@@ -80,11 +80,13 @@ public:
template <int ORDER, int NVALS = 1>
class FTypedChebCell : public FChebCell<ORDER,NVALS>, public FExtendCellType {
public:
void save(FBufferWriter& buffer) const{
template <class BufferWriterClass>
void save(BufferWriterClass& buffer) const{
FChebCell<ORDER,NVALS>::save(buffer);
FExtendCellType::save(buffer);
}
void restore(FBufferReader& buffer){
template <class BufferReaderClass>
void restore(BufferReaderClass& buffer){
FChebCell<ORDER,NVALS>::restore(buffer);
FExtendCellType::restore(buffer);
}
......
......@@ -23,8 +23,6 @@
#include "../../Components/FBasicCell.hpp"
#include "../../Containers/FBufferWriter.hpp"
#include "../../Containers/FBufferReader.hpp"
/** This class is a cell used for the rotation based kernel
* The size of the multipole and local vector are based on a template
......@@ -107,29 +105,35 @@ public:
///////////////////////////////////////////////////////
// to extend FAbstractSendable
///////////////////////////////////////////////////////
void serializeUp(FBufferWriter& buffer) const{
template <class BufferWriterClass>
void serializeUp(BufferWriterClass& buffer) const{
buffer.write(multipole_exp, MultipoleSize);
}
void deserializeUp(FBufferReader& buffer){
template <class BufferReaderClass>
void deserializeUp(BufferReaderClass& buffer){
buffer.fillArray(multipole_exp, MultipoleSize);
}
void serializeDown(FBufferWriter& buffer) const{
template <class BufferWriterClass>
void serializeDown(BufferWriterClass& buffer) const{
buffer.write(local_exp, LocalSize);
}
void deserializeDown(FBufferReader& buffer){
template <class BufferReaderClass>
void deserializeDown(BufferReaderClass& buffer){
buffer.fillArray(local_exp, LocalSize);
}
///////////////////////////////////////////////////////
// to extend Serializable
///////////////////////////////////////////////////////
void save(FBufferWriter& buffer) const{
template <class BufferWriterClass>
void save(BufferWriterClass& buffer) const{
FBasicCell::save(buffer);
buffer.write(multipole_exp, MultipoleSize);
buffer.write(local_exp, LocalSize);
}
void restore(FBufferReader& buffer){
template <class BufferReaderClass>
void restore(BufferReaderClass& buffer){
FBasicCell::restore(buffer);
buffer.fillArray(multipole_exp, MultipoleSize);
buffer.fillArray(local_exp, LocalSize);
......@@ -139,11 +143,13 @@ public:
template <int P>
class FTypedRotationCell : public FRotationCell<P>, public FExtendCellType {
public:
void save(FBufferWriter& buffer) const{
template <class BufferWriterClass>
void save(BufferWriterClass& buffer) const{
FRotationCell<P>::save(buffer);
FExtendCellType::save(buffer);
}
void restore(FBufferReader& buffer){
template <class BufferReaderClass>
void restore(BufferReaderClass& buffer){
FRotationCell<P>::restore(buffer);
FExtendCellType::restore(buffer);
}
......
......@@ -23,9 +23,6 @@
#include "../../Components/FBasicCell.hpp"
#include "../../Containers/FBufferWriter.hpp"
#include "../../Containers/FBufferReader.hpp"
/**
* @author Berenger Bramas (berenger.bramas@inria.fr)
*/
......@@ -121,29 +118,35 @@ public:
///////////////////////////////////////////////////////
// to extend FAbstractSendable
///////////////////////////////////////////////////////
void serializeUp(FBufferWriter& buffer) const{
template <class BufferWriterClass>
void serializeUp(BufferWriterClass& buffer) const{
buffer.write(multipole_exp, PoleSize);
}
void deserializeUp(FBufferReader& buffer){
template <class BufferReaderClass>
void deserializeUp(BufferReaderClass& buffer){
buffer.fillArray(multipole_exp, PoleSize);
}
void serializeDown(FBufferWriter& buffer) const{
template <class BufferWriterClass>
void serializeDown(BufferWriterClass& buffer) const{
buffer.write(local_exp, LocalSize);
}
void deserializeDown(FBufferReader& buffer){
template <class BufferReaderClass>
void deserializeDown(BufferReaderClass& buffer){
buffer.fillArray(local_exp, LocalSize);
}
///////////////////////////////////////////////////////
// to extend Serializable
///////////////////////////////////////////////////////
void save(FBufferWriter& buffer) const{
template <class BufferWriterClass>
void save(BufferWriterClass& buffer) const{
FBasicCell::save(buffer);
buffer.write(multipole_exp, PoleSize);
buffer.write(local_exp, LocalSize);
}
void restore(FBufferReader& buffer){
template <class BufferReaderClass>
void restore(BufferReaderClass& buffer){
FBasicCell::restore(buffer);
buffer.fillArray(multipole_exp, PoleSize);
buffer.fillArray(local_exp, LocalSize);
......@@ -160,11 +163,13 @@ int FSphericalCell::PoleSize(-1);
*/
class FTypedSphericalCell : public FSphericalCell, public FExtendCellType {
public:
void save(FBufferWriter& buffer) const{
template <class BufferWriterClass>
void save(BufferWriterClass& buffer) const{
FSphericalCell::save(buffer);
FExtendCellType::save(buffer);
}
void restore(FBufferReader& buffer){
template <class BufferReaderClass>
void restore(BufferReaderClass& buffer){
FSphericalCell::restore(buffer);
FExtendCellType::restore(buffer);
}
......
......@@ -86,11 +86,13 @@ public:
template <int P, int order>
class FTypedTaylorCell : public FTaylorCell<P,order>, public FExtendCellType {
public:
void save(FBufferWriter& buffer) const{
template <class BufferWriterClass>
void save(BufferWriterClass& buffer) const{
FTaylorCell<P,order>::save(buffer);
FExtendCellType::save(buffer);
}
void restore(FBufferReader& buffer){
template <class BufferReaderClass>
void restore(BufferReaderClass& buffer){
FTaylorCell<P,order>::restore(buffer);
FExtendCellType::restore(buffer);
}
......
......@@ -18,8 +18,6 @@
#include "FMath.hpp"
#include "FGlobal.hpp"
#include "../Containers/FBufferReader.hpp"
#include "../Containers/FBufferWriter.hpp"
/**
* @author Berenger Bramas (berenger.bramas@inria.fr)
......@@ -300,12 +298,14 @@ public:
return output; // for multiple << operators.
}
/** Save current object */
void save(FBufferWriter& buffer) const {
/** Save current object */
template <class BufferWriterClass>
void save(BufferWriterClass& buffer) const {
buffer << data[0] << data[1] << data[2];
}
/** Retrieve current object */
void restore(FBufferReader& buffer) {
template <class BufferReaderClass>
void restore(BufferReaderClass& buffer) {
buffer >> data[0] >> data[1] >> data[2];
}
};
......
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