Commit 4ccc09cb authored by COULAUD Olivier's avatar COULAUD Olivier

Add copy constructor

parent 66e764be
......@@ -2,6 +2,9 @@
#ifndef FBASIC_PARTICLE_CONTAINER_HPP_
#define FBASIC_PARTICLE_CONTAINER_HPP_
#include <array>
#include <algorithm>
#include "FAbstractParticleContainer.hpp"
#include "FAbstractSerializable.hpp"
......@@ -11,8 +14,6 @@
#include "Utils/FPoint.hpp"
#include "FParticleType.hpp"
#include <array>
/**
* @author Berenger Bramas (berenger.bramas@inria.fr)
* Please read the license
......@@ -135,7 +136,31 @@ public:
/////////////////////////////////////////////////////
/////////////////////////////////////////////////////
FBasicParticleContainer(const FBasicParticleContainer&) = delete;
// FBasicParticleContainer(const FBasicParticleContainer& leaf) = delete;
FBasicParticleContainer( FBasicParticleContainer& leaf) : nbParticles(leaf.nbParticles),allocatedParticles(leaf.allocatedParticles)
{
// allocate memory
const FSize moduloParticlesNumber = (MemoryAlignement/sizeof(FReal));
allocatedParticles = (nbParticles + moduloParticlesNumber - 1) & ~(moduloParticlesNumber-1);
// init with 0
const size_t allocatedBytes = (sizeof(FReal)*3 + sizeof(AttributeClass)*NbAttributesPerParticle)*allocatedParticles;
FReal* newData = reinterpret_cast<FReal*>(FAlignedMemory::AllocateBytes<MemoryAlignement>(allocatedBytes));
FReal * const oldData = (leaf.getWPositions()[0]);
std::copy(oldData,oldData+allocatedBytes,newData) ;
// Fill the structure
FAlignedMemory::DeallocBytes(positions[0]);
for(int idx = 0 ; idx < 3 ; ++idx){
positions[idx] = newData + (allocatedParticles * idx);
}
AttributeClass* startAddress = reinterpret_cast<AttributeClass*>(positions[2] + allocatedParticles);
for(unsigned idx = 0 ; idx < NbAttributesPerParticle ; ++idx){
attributes[idx] = startAddress + (idx * allocatedParticles);
}
}
FBasicParticleContainer& operator=(const FBasicParticleContainer&) = delete;
/////////////////////////////////////////////////////
......
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