Commit 1e273454 authored by berenger-bramas's avatar berenger-bramas

Update the smart pointer class to have pointer or array type.

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/scalfmm/scalfmm/trunk@384 2616d619-271b-44dc-8df4-d4a8f33a7222
parent e9ebfbaa
......@@ -489,6 +489,7 @@ private:
typename ContainerClass::BasicIterator iterTarget(*targets);
while( iterTarget.hasNotFinished() ){
ParticleClass target( iterTarget.data() );
// For all the particles in the other leaf
typename ContainerClass::BasicIterator iterSource(*directNeighborsParticles[idxDirectNeighbors]);
while( iterSource.hasNotFinished() ){
......@@ -916,8 +917,7 @@ public:
* F = q * q' / r²
*/
void directInteractionMutual(ParticleClass*const FRestrict target, ParticleClass*const FRestrict source){
//TODO std::cout << "P2P Mutual between " << target->getPosition() << " and " << source->getPosition() << std::endl;//TODO delete
//TODO std::cout << target << " / " << source << std::endl;
FReal dx = -(target->getPosition().getX() - source->getPosition().getX());
FReal dy = -(target->getPosition().getY() - source->getPosition().getY());
FReal dz = -(target->getPosition().getZ() - source->getPosition().getZ());
......@@ -937,14 +937,14 @@ public:
source->incForces( (-dx), (-dy), (-dz));
source->incPotential( inv_distance * target->getPhysicalValue() );
}
/** P2P NO mutual interaction
* F = q * q' / r²
*/
void directInteraction(ParticleClass*const FRestrict target, const ParticleClass& source){
//TODO std::cout << "P2P between " << target->getPosition() << " and " << source.getPosition() << std::endl;//TODO delete
//TODO std::cout << target << " / " << &source << std::endl;
FReal dx = -(target->getPosition().getX() - source.getPosition().getX());
FReal dy = -(target->getPosition().getY() - source.getPosition().getY());
FReal dz = -(target->getPosition().getZ() - source.getPosition().getZ());
......@@ -961,6 +961,7 @@ public:
target->incForces( dx, dy, dz);
target->incPotential( inv_distance * source.getPhysicalValue() );
}
......
#ifndef FSMARTPOINTER_HPP
#define FSMARTPOINTER_HPP
enum FSmartPointerType{
FSmartArrayMemory,
FSmartPointerMemory
};
/** This class is a basic smart pointer class
*
* Use as FSmartPointer<int> array = new int[5];
* FSmartPointer<int, PointerMemory> pt = new int;
*/
template <class ClassType>
template <class ClassType, FSmartPointerType MemoryType = FSmartArrayMemory>
class FSmartPointer {
ClassType* pointer; //< The pointer to the memory area
int* counter; //< Reference counter
......@@ -63,7 +70,8 @@ public:
if(counter){
(*counter) = (*counter) - 1;
if( (*counter) == 0 ){
delete[] pointer;
if(MemoryType == FSmartArrayMemory) delete[] pointer;
else if(MemoryType == FSmartPointerMemory) delete pointer;
}
pointer = 0;
counter = 0;
......
This diff is collapsed.
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