diff --git a/src/pamm/PammObject.cpp b/src/pamm/PammObject.cpp index 54430672297d8d6c09ded516a7652f4f1f86e733..7606d7f1beb50aba419b216a9f55fccc7a1e4be2 100644 --- a/src/pamm/PammObject.cpp +++ b/src/pamm/PammObject.cpp @@ -21,6 +21,7 @@ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ #include "PammObject.h" #include "tools/IFile.h" +#include <memory> namespace PLMD { namespace pamm { @@ -65,10 +66,11 @@ void PammObject::setup( const std::string& filename, const double& reg, const st ifile.open(filename); ifile.allowIgnoredFields(); kernels.resize(0); for(unsigned k=0;; ++k) { - KernelFunctions* kk = KernelFunctions::read( &ifile, false, valnames ); + std::unique_ptr<KernelFunctions> kk = KernelFunctions::read( &ifile, false, valnames ); if( !kk ) break ; kk->normalize( pos ); - kernels.push_back( kk ); + kernels.push_back( kk.release() ); // kernels should be changed into a vector<unique_ptr>. + // meanwhile, I just release the unique_ptr herelease the unique_ptr here. GB ifile.scanField(); } ifile.close(); diff --git a/src/tools/BiasRepresentation.cpp b/src/tools/BiasRepresentation.cpp index c81524de749babb92f54e757c1b2d15a2053d7c5..bafae408da3afbd2642e5d826114955cf795ae42 100644 --- a/src/tools/BiasRepresentation.cpp +++ b/src/tools/BiasRepresentation.cpp @@ -115,24 +115,24 @@ Value* BiasRepresentation::getPtrToValue(unsigned i) { return values[i]; } -KernelFunctions* BiasRepresentation::readFromPoint(IFile *ifile) { +std::unique_ptr<KernelFunctions> BiasRepresentation::readFromPoint(IFile *ifile) { vector<double> cc( names.size() ); for(unsigned i=0; i<names.size(); ++i) { ifile->scanField(names[i],cc[i]); } double h=1.0; - return new KernelFunctions(cc,histosigma,"gaussian","DIAGONAL",h); + return std::unique_ptr<KernelFunctions>( new KernelFunctions(cc,histosigma,"gaussian","DIAGONAL",h) ); } void BiasRepresentation::pushKernel( IFile *ifile ) { std::unique_ptr<KernelFunctions> kk; // here below the reading of the kernel is completely hidden if(histosigma.size()==0) { ifile->allowIgnoredFields(); - kk.reset(KernelFunctions::read(ifile,true,names)); + kk=KernelFunctions::read(ifile,true,names); } else { // when doing histogram assume gaussian with a given diagonal sigma // and neglect all the rest - kk.reset(readFromPoint(ifile)); + kk=readFromPoint(ifile); } // the bias factor is not something about the kernels but // must be stored to keep the bias/free energy duality diff --git a/src/tools/BiasRepresentation.h b/src/tools/BiasRepresentation.h index a775a0120cdc6bde5327121529c0a060e65bf880..93c613a34654370300eee16171daffaf76669bcb 100644 --- a/src/tools/BiasRepresentation.h +++ b/src/tools/BiasRepresentation.h @@ -76,7 +76,7 @@ public: /// get the pointer to the grid Grid* getGridPtr(); /// get a new histogram point from a file - KernelFunctions* readFromPoint(IFile *ifile); + std::unique_ptr<KernelFunctions> readFromPoint(IFile *ifile); /// get an automatic min/max from the set so to know how to configure the grid void getMinMaxBin(std::vector<double> &vmin, std::vector<double> &vmax, std::vector<unsigned> &vbin); /// clear the representation (grid included) diff --git a/src/tools/KernelFunctions.cpp b/src/tools/KernelFunctions.cpp index f9f61cd375dcf36cb5463ac815df46ff7c420e2b..deea4c209c27a46d2caafb6c502e10004f4947aa 100755 --- a/src/tools/KernelFunctions.cpp +++ b/src/tools/KernelFunctions.cpp @@ -382,7 +382,7 @@ double KernelFunctions::evaluate( const std::vector<Value*>& pos, std::vector<do return kval; } -KernelFunctions* KernelFunctions::read( IFile* ifile, const bool& cholesky, const std::vector<std::string>& valnames ) { +std::unique_ptr<KernelFunctions> KernelFunctions::read( IFile* ifile, const bool& cholesky, const std::vector<std::string>& valnames ) { double h; if( !ifile->scanField("height",h) ) return NULL;; @@ -401,7 +401,7 @@ KernelFunctions* KernelFunctions::read( IFile* ifile, const bool& cholesky, cons ifile->scanField("sigma_"+valnames[i],sig[i]); if( !cholesky ) sig[i]=sqrt(sig[i]); } - return new KernelFunctions( cc, sig, ktype, "DIAGONAL", h ); + return std::unique_ptr<KernelFunctions>(new KernelFunctions( cc, sig, ktype, "DIAGONAL", h ) ); } unsigned ncv=valnames.size(); @@ -419,8 +419,8 @@ KernelFunctions* KernelFunctions::read( IFile* ifile, const bool& cholesky, cons for(unsigned i=0; i<ncv; i++) { for(unsigned j=i; j<ncv; j++) { sig[k]=invmatrix(i,j); k++; } } - if( sss=="true" ) return new KernelFunctions( cc, sig, ktype, "MULTIVARIATE", h ); - return new KernelFunctions( cc, sig, ktype, "VON-MISSES", h ); + if( sss=="true" ) return std::unique_ptr<KernelFunctions>(new KernelFunctions( cc, sig, ktype, "MULTIVARIATE", h ) ); + return std::unique_ptr<KernelFunctions>(new KernelFunctions( cc, sig, ktype, "VON-MISSES", h ) ); } } diff --git a/src/tools/KernelFunctions.h b/src/tools/KernelFunctions.h index 32966973eba45d7bdb1ce358a16705428a9dd8cd..ac26c23d33291bc8692ceff0cf9ec7d6be3241f0 100644 --- a/src/tools/KernelFunctions.h +++ b/src/tools/KernelFunctions.h @@ -26,6 +26,7 @@ #include "Matrix.h" #include "core/Value.h" #include <vector> +#include <memory> namespace PLMD { @@ -64,7 +65,7 @@ public: /// Evaluate the kernel function with constant intervals double evaluate( const std::vector<Value*>& pos, std::vector<double>& derivatives, bool usederiv=true, bool doInt=false, double lowI_=-1, double uppI_=-1 ) const; /// Read a kernel function from a file - static KernelFunctions* read( IFile* ifile, const bool& cholesky, const std::vector<std::string>& valnames ); + static std::unique_ptr<KernelFunctions> read( IFile* ifile, const bool& cholesky, const std::vector<std::string>& valnames ); }; inline