Commit c3ad0e3e authored by Jason Swails's avatar Jason Swails
Browse files

- Make the TabulatedFunction::Copy method a pure virtual.

- Don't make a Copy method on FunctionInfo
- Have the Copy() methods on the TabulatedFunction subclasses return a pointer
parent 4517491d
...@@ -552,10 +552,6 @@ public: ...@@ -552,10 +552,6 @@ public:
} }
FunctionInfo(const std::string& name, TabulatedFunction* function) : name(name), function(function) { FunctionInfo(const std::string& name, TabulatedFunction* function) : name(name), function(function) {
} }
FunctionInfo Copy() const {
TabulatedFunction new_func = function->Copy();
return FunctionInfo(name, &new_func);
}
}; };
/** /**
......
...@@ -59,9 +59,7 @@ class OPENMM_EXPORT TabulatedFunction { ...@@ -59,9 +59,7 @@ class OPENMM_EXPORT TabulatedFunction {
public: public:
virtual ~TabulatedFunction() { virtual ~TabulatedFunction() {
} }
TabulatedFunction Copy() const { virtual TabulatedFunction* Copy() const = 0;
return TabulatedFunction();
}
}; };
/** /**
...@@ -102,7 +100,7 @@ public: ...@@ -102,7 +100,7 @@ public:
/** /**
* Create a deep copy of the tabulated function. * Create a deep copy of the tabulated function.
*/ */
Continuous1DFunction Copy() const; Continuous1DFunction* Copy() const;
private: private:
std::vector<double> values; std::vector<double> values;
double min, max; double min, max;
...@@ -161,7 +159,7 @@ public: ...@@ -161,7 +159,7 @@ public:
/** /**
* Create a deep copy of the tabulated function * Create a deep copy of the tabulated function
*/ */
Continuous2DFunction Copy() const; Continuous2DFunction* Copy() const;
private: private:
std::vector<double> values; std::vector<double> values;
int xsize, ysize; int xsize, ysize;
...@@ -236,7 +234,7 @@ public: ...@@ -236,7 +234,7 @@ public:
/** /**
* Create a deep copy of the tabulated function * Create a deep copy of the tabulated function
*/ */
Continuous3DFunction Copy() const; Continuous3DFunction* Copy() const;
private: private:
std::vector<double> values; std::vector<double> values;
int xsize, ysize, zsize; int xsize, ysize, zsize;
...@@ -271,7 +269,7 @@ public: ...@@ -271,7 +269,7 @@ public:
/** /**
* Create a deep copy of the tabulated function * Create a deep copy of the tabulated function
*/ */
Discrete1DFunction Copy() const; Discrete1DFunction* Copy() const;
private: private:
std::vector<double> values; std::vector<double> values;
}; };
...@@ -313,7 +311,7 @@ public: ...@@ -313,7 +311,7 @@ public:
/** /**
* Create a deep copy of the tabulated function * Create a deep copy of the tabulated function
*/ */
Discrete2DFunction Copy() const; Discrete2DFunction* Copy() const;
private: private:
int xsize, ysize; int xsize, ysize;
std::vector<double> values; std::vector<double> values;
...@@ -359,7 +357,7 @@ public: ...@@ -359,7 +357,7 @@ public:
/** /**
* Create a deep copy of the tabulated function * Create a deep copy of the tabulated function
*/ */
Discrete3DFunction Copy() const; Discrete3DFunction* Copy() const;
private: private:
int xsize, ysize, zsize; int xsize, ysize, zsize;
std::vector<double> values; std::vector<double> values;
......
...@@ -65,7 +65,7 @@ CustomNonbondedForce::CustomNonbondedForce(const CustomNonbondedForce& rhs) { ...@@ -65,7 +65,7 @@ CustomNonbondedForce::CustomNonbondedForce(const CustomNonbondedForce& rhs) {
exclusions = rhs.exclusions; exclusions = rhs.exclusions;
interactionGroups = rhs.interactionGroups; interactionGroups = rhs.interactionGroups;
for (vector<FunctionInfo>::const_iterator it = rhs.functions.begin(); it != rhs.functions.end(); it++) for (vector<FunctionInfo>::const_iterator it = rhs.functions.begin(); it != rhs.functions.end(); it++)
functions.push_back(it->Copy()); functions.push_back(FunctionInfo(it->name, it->function->Copy()));
} }
CustomNonbondedForce::~CustomNonbondedForce() { CustomNonbondedForce::~CustomNonbondedForce() {
......
...@@ -61,11 +61,11 @@ void Continuous1DFunction::setFunctionParameters(const vector<double>& values, d ...@@ -61,11 +61,11 @@ void Continuous1DFunction::setFunctionParameters(const vector<double>& values, d
this->max = max; this->max = max;
} }
Continuous1DFunction Continuous1DFunction::Copy() const { Continuous1DFunction* Continuous1DFunction::Copy() const {
vector<double> new_vec(values.size()); vector<double> new_vec(values.size());
for (size_t i = 0; i < values.size(); i++) for (size_t i = 0; i < values.size(); i++)
new_vec[i] = values[i]; new_vec[i] = values[i];
return Continuous1DFunction(new_vec, min, max); return new Continuous1DFunction(new_vec, min, max);
} }
Continuous2DFunction::Continuous2DFunction(int xsize, int ysize, const vector<double>& values, double xmin, double xmax, double ymin, double ymax) { Continuous2DFunction::Continuous2DFunction(int xsize, int ysize, const vector<double>& values, double xmin, double xmax, double ymin, double ymax) {
...@@ -114,11 +114,11 @@ void Continuous2DFunction::setFunctionParameters(int xsize, int ysize, const vec ...@@ -114,11 +114,11 @@ void Continuous2DFunction::setFunctionParameters(int xsize, int ysize, const vec
this->ymax = ymax; this->ymax = ymax;
} }
Continuous2DFunction Continuous2DFunction::Copy() const { Continuous2DFunction* Continuous2DFunction::Copy() const {
vector<double> new_vec(values.size()); vector<double> new_vec(values.size());
for (size_t i = 0; i < values.size(); i++) for (size_t i = 0; i < values.size(); i++)
new_vec[i] = values[i]; new_vec[i] = values[i];
return Continuous2DFunction(xsize, ysize, new_vec, xmin, xmax, ymin, ymax); return new Continuous2DFunction(xsize, ysize, new_vec, xmin, xmax, ymin, ymax);
} }
Continuous3DFunction::Continuous3DFunction(int xsize, int ysize, int zsize, const vector<double>& values, double xmin, double xmax, double ymin, double ymax, double zmin, double zmax) { Continuous3DFunction::Continuous3DFunction(int xsize, int ysize, int zsize, const vector<double>& values, double xmin, double xmax, double ymin, double ymax, double zmin, double zmax) {
...@@ -180,11 +180,11 @@ void Continuous3DFunction::setFunctionParameters(int xsize, int ysize, int zsize ...@@ -180,11 +180,11 @@ void Continuous3DFunction::setFunctionParameters(int xsize, int ysize, int zsize
this->zmax = zmax; this->zmax = zmax;
} }
Continuous3DFunction Continuous3DFunction::Copy() const { Continuous3DFunction* Continuous3DFunction::Copy() const {
vector<double> new_vec(values.size()); vector<double> new_vec(values.size());
for (size_t i = 0; i < values.size(); i++) for (size_t i = 0; i < values.size(); i++)
new_vec[i] = values[i]; new_vec[i] = values[i];
return Continuous3DFunction(xsize, ysize, zsize, new_vec, xmin, xmax, ymin, ymax, zmin, zmax); return new Continuous3DFunction(xsize, ysize, zsize, new_vec, xmin, xmax, ymin, ymax, zmin, zmax);
} }
...@@ -200,11 +200,11 @@ void Discrete1DFunction::setFunctionParameters(const vector<double>& values) { ...@@ -200,11 +200,11 @@ void Discrete1DFunction::setFunctionParameters(const vector<double>& values) {
this->values = values; this->values = values;
} }
Discrete1DFunction Discrete1DFunction::Copy() const { Discrete1DFunction* Discrete1DFunction::Copy() const {
vector<double> new_vec(values.size()); vector<double> new_vec(values.size());
for (size_t i = 0; i < values.size(); i++) for (size_t i = 0; i < values.size(); i++)
new_vec[i] = values[i]; new_vec[i] = values[i];
return Discrete1DFunction(new_vec); return new Discrete1DFunction(new_vec);
} }
Discrete2DFunction::Discrete2DFunction(int xsize, int ysize, const vector<double>& values) { Discrete2DFunction::Discrete2DFunction(int xsize, int ysize, const vector<double>& values) {
...@@ -229,11 +229,11 @@ void Discrete2DFunction::setFunctionParameters(int xsize, int ysize, const vecto ...@@ -229,11 +229,11 @@ void Discrete2DFunction::setFunctionParameters(int xsize, int ysize, const vecto
this->values = values; this->values = values;
} }
Discrete2DFunction Discrete2DFunction::Copy() const { Discrete2DFunction* Discrete2DFunction::Copy() const {
vector<double> new_vec(values.size()); vector<double> new_vec(values.size());
for (size_t i = 0; i < values.size(); i++) for (size_t i = 0; i < values.size(); i++)
new_vec[i] = values[i]; new_vec[i] = values[i];
return Discrete2DFunction(xsize, ysize, new_vec); return new Discrete2DFunction(xsize, ysize, new_vec);
} }
Discrete3DFunction::Discrete3DFunction(int xsize, int ysize, int zsize, const vector<double>& values) { Discrete3DFunction::Discrete3DFunction(int xsize, int ysize, int zsize, const vector<double>& values) {
...@@ -261,9 +261,9 @@ void Discrete3DFunction::setFunctionParameters(int xsize, int ysize, int zsize, ...@@ -261,9 +261,9 @@ void Discrete3DFunction::setFunctionParameters(int xsize, int ysize, int zsize,
this->values = values; this->values = values;
} }
Discrete3DFunction Discrete3DFunction::Copy() const { Discrete3DFunction* Discrete3DFunction::Copy() const {
vector<double> new_vec(values.size()); vector<double> new_vec(values.size());
for (size_t i = 0; i < values.size(); i++) for (size_t i = 0; i < values.size(); i++)
new_vec[i] = values[i]; new_vec[i] = values[i];
return Discrete3DFunction(xsize, ysize, zsize, new_vec); return new Discrete3DFunction(xsize, ysize, zsize, new_vec);
} }
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