add Copy Constructor + pur virtual size setter
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@2222 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
522d4d2a25
commit
bf8f7306e4
1 changed files with 151 additions and 141 deletions
|
|
@ -30,10 +30,10 @@
|
||||||
|
|
||||||
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||||
Contact: paradiseo-help@lists.gforge.inria.fr
|
Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _moGPUVector_H_
|
#ifndef __moGPUVector_H_
|
||||||
#define _moGPUVector_H_
|
#define __moGPUVector_H_
|
||||||
|
|
||||||
#include <eo>
|
#include <eo>
|
||||||
|
|
||||||
|
|
@ -43,9 +43,9 @@
|
||||||
|
|
||||||
template<class ElemT, class Fitness>
|
template<class ElemT, class Fitness>
|
||||||
|
|
||||||
class moGPUVector: public EO<Fitness> {
|
class moGPUVector: public EO<Fitness> {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define vector type corresponding to Solution
|
* Define vector type corresponding to Solution
|
||||||
|
|
@ -72,6 +72,23 @@ public:
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*Copy Constructor
|
||||||
|
*@param _vector The vector passed to the function to determine the new content.
|
||||||
|
*/
|
||||||
|
|
||||||
|
moGPUVector(const moGPUVector & _vector) {
|
||||||
|
|
||||||
|
N = _vector.N;
|
||||||
|
vect = new ElemType[N];
|
||||||
|
for (unsigned i = 0; i < N; i++)
|
||||||
|
vect[i] = _vector.vect[i];
|
||||||
|
if (!(_vector.invalid()))
|
||||||
|
fitness(_vector.fitness());
|
||||||
|
else
|
||||||
|
(*this).invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destructor.
|
* Destructor.
|
||||||
*/
|
*/
|
||||||
|
|
@ -93,9 +110,9 @@ public:
|
||||||
*@return a new vector.
|
*@return a new vector.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
virtual moGPUVector& operator=(const moGPUVector & _vector) {
|
moGPUVector& operator=(const moGPUVector & _vector) {
|
||||||
|
|
||||||
if (!(N == _vector.N) && (N >= 1)) {
|
if (!(N == _vector.N)) {
|
||||||
delete[] vect;
|
delete[] vect;
|
||||||
N = _vector.N;
|
N = _vector.N;
|
||||||
vect = new ElemType[N];
|
vect = new ElemType[N];
|
||||||
|
|
@ -117,9 +134,8 @@ public:
|
||||||
*/
|
*/
|
||||||
|
|
||||||
inline __host__ __device__ const ElemType & operator[](unsigned _i) const {
|
inline __host__ __device__ const ElemType & operator[](unsigned _i) const {
|
||||||
|
if(_i<N)
|
||||||
return vect[_i];
|
return vect[_i];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -129,9 +145,8 @@ public:
|
||||||
*/
|
*/
|
||||||
|
|
||||||
inline __host__ __device__ ElemType & operator[](unsigned _i) {
|
inline __host__ __device__ ElemType & operator[](unsigned _i) {
|
||||||
|
if(_i<N)
|
||||||
return vect[_i];
|
return vect[_i];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -150,12 +165,7 @@ public:
|
||||||
*@param _size the vector size
|
*@param _size the vector size
|
||||||
*/
|
*/
|
||||||
|
|
||||||
inline __host__ __device__ void setSize(unsigned _size) {
|
virtual inline __host__ void setSize(unsigned _size)=0;
|
||||||
|
|
||||||
N=_size;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write object. Called printOn since it prints the object _on_ a stream.
|
* Write object. Called printOn since it prints the object _on_ a stream.
|
||||||
|
|
@ -164,7 +174,7 @@ public:
|
||||||
|
|
||||||
virtual void printOn(std::ostream& os) const=0;
|
virtual void printOn(std::ostream& os) const=0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
ElemType * vect;
|
ElemType * vect;
|
||||||
unsigned N;
|
unsigned N;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue