Unverified Commit e340fe4f authored by Christoph Junghans's avatar Christoph Junghans Committed by GitHub

Merge pull request #436 from votca/c++11_forloops

C++11 forloops
parents b9b032f1 b4548b77
Pipeline #89633485 passed with stages
in 553 minutes and 22 seconds
......@@ -43,7 +43,7 @@ class BaseBead {
/**
* destructor
*/
virtual ~BaseBead() {}
virtual ~BaseBead() = default;
/// Gets the id of the bead
int getId() const { return id_.getId(); }
......
......@@ -48,7 +48,7 @@ class Bead : public BaseBead {
/**
* destructor
*/
virtual ~Bead() {}
~Bead() override = default;
/**
* get the residu number of the bead
......@@ -274,10 +274,6 @@ class Bead : public BaseBead {
protected:
std::vector<int> parent_beads_;
// TODO: this is so far a pointer. this should change! each bead should have
// own options.
// Property *options_;
tools::byte_t symmetry_;
double charge_;
......@@ -291,7 +287,7 @@ class Bead : public BaseBead {
bool bW_;
bool bead_force_set_;
/// constructur
/// constructor
Bead(Topology *owner, int id, std::string type, tools::byte_t symmetry,
std::string name, int resnr, double m, double q)
: symmetry_(symmetry), charge_(q), residue_number_(resnr) {
......@@ -308,8 +304,6 @@ class Bead : public BaseBead {
bead_force_set_ = false;
}
// void *_userdata;
friend class Topology;
friend class Molecule;
};
......
......@@ -18,9 +18,9 @@
#ifndef _VOTCA_CSG_BEADLIST_H
#define _VOTCA_CSG_BEADLIST_H
#include "topology.h"
#include <list>
#include <string>
#include <votca/tools/eigen.h>
namespace votca {
namespace csg {
......@@ -32,6 +32,9 @@ namespace csg {
*/
class Topology;
class Bead;
class BeadList {
public:
/// \brief Select all beads of type <select>
......@@ -47,7 +50,7 @@ class BeadList {
void push_back(Bead *bead) { _beads.push_back(bead); }
typedef typename std::vector<Bead *>::iterator iterator;
using iterator = typename std::vector<Bead *>::iterator;
iterator begin() { return _beads.begin(); }
iterator end() { return _beads.end(); }
......
......@@ -119,7 +119,8 @@ class BeadMotif : public BeadStructure<BaseBead> {
undefined
};
BeadMotif(){};
BeadMotif() = default;
;
BeadMotif(const BeadStructure &structure) : BeadStructure(structure){};
......
......@@ -33,7 +33,7 @@ namespace csg {
class BeadPair {
public:
BeadPair() {}
BeadPair() = default;
BeadPair(Bead *bead1, Bead *bead2, Eigen::Vector3d r)
: _pair(std::pair<Bead *, Bead *>(bead1, bead2)),
_r(r),
......
......@@ -53,7 +53,7 @@ namespace csg {
template <class T>
class BeadStructure {
public:
~BeadStructure() {}
~BeadStructure() = default;
/**
* \brief Determine if the bead structure consists of a single connected
......
......@@ -33,7 +33,7 @@ namespace csg {
class BeadTriple : public std::tuple<Bead *, Bead *, Bead *> {
public:
BeadTriple() {}
BeadTriple() = default;
BeadTriple(Bead *bead1, Bead *bead2, Bead *bead3, Eigen::Vector3d r12,
Eigen::Vector3d r13, Eigen::Vector3d r23)
: std::tuple<Bead *, Bead *, Bead *>(bead1, bead2, bead3),
......@@ -44,7 +44,7 @@ class BeadTriple : public std::tuple<Bead *, Bead *, Bead *> {
_dist13(r13.norm()),
_dist23(r23.norm()) {}
virtual ~BeadTriple() {}
virtual ~BeadTriple() = default;
/// \brief return the beads
const Bead *bead1() { return std::get<0>(*this); }
......
......@@ -26,7 +26,8 @@ namespace csg {
class BoundaryCondition {
public:
virtual ~BoundaryCondition(){};
virtual ~BoundaryCondition() = default;
;
/**
* set the simulation box
......
......@@ -93,14 +93,17 @@ inline CGMoleculeDef *CGEngine::getMoleculeDef(std::string name) {
}
iter = _molecule_defs.find(name);
if (iter == _molecule_defs.end()) return NULL;
if (iter == _molecule_defs.end()) {
return nullptr;
}
return (*iter).second;
}
inline bool CGEngine::IsIgnored(std::string ident) {
for (std::list<std::string>::iterator iter = _ignores.begin();
iter != _ignores.end(); ++iter) {
if (tools::wildcmp(iter->c_str(), ident.c_str())) return true;
for (auto &_ignore : _ignores) {
if (tools::wildcmp(_ignore.c_str(), ident.c_str())) {
return true;
}
}
return false;
}
......
......@@ -43,7 +43,7 @@ namespace csg {
*/
class CGMoleculeDef {
public:
CGMoleculeDef() {}
CGMoleculeDef() = default;
~CGMoleculeDef();
Molecule *CreateMolecule(Topology &top);
......
......@@ -36,11 +36,12 @@ namespace csg {
class CGObserver {
public:
/// \brief called before the first frame
virtual void BeginCG(Topology *top, Topology *top_atom = 0) = 0;
virtual void BeginCG(Topology *top, Topology *top_atom = nullptr) = 0;
/// \brief called after the last frame
virtual void EndCG() = 0;
// \brief called for each frame which is mapped
virtual void EvalConfiguration(Topology *top, Topology *top_atom = 0) = 0;
virtual void EvalConfiguration(Topology *top,
Topology *top_atom = nullptr) = 0;
};
} // namespace csg
......
......@@ -31,15 +31,17 @@ namespace csg {
class CsgApplication : public tools::Application {
public:
CsgApplication(){};
virtual ~CsgApplication(){};
CsgApplication() = default;
;
~CsgApplication() override = default;
;
void Initialize();
bool EvaluateOptions();
void Initialize() override;
bool EvaluateOptions() override;
void Run(void);
void Run(void) override;
void ShowHelpText(std::ostream &out);
void ShowHelpText(std::ostream &out) override;
/// \brief overload and return true to enable mapping command line options
......@@ -57,10 +59,11 @@ class CsgApplication : public tools::Application {
/* \brief overload and return false to disable synchronized (while threaded)
* calculations */
virtual bool SynchronizeThreads(void) {
if (DoThreaded())
if (DoThreaded()) {
return true;
else
} else {
return false;
}
}
/// \brief if topology is always needed
......@@ -68,18 +71,18 @@ class CsgApplication : public tools::Application {
/// \brief called after topology was loaded
virtual bool EvaluateTopology(Topology *top, Topology *top_ref = 0) {
virtual bool EvaluateTopology(Topology *top, Topology *top_ref = nullptr) {
return true;
}
void AddObserver(CGObserver *observer);
/// \brief called before the first frame
virtual void BeginEvaluate(Topology *top, Topology *top_ref = 0);
virtual void BeginEvaluate(Topology *top, Topology *top_ref = nullptr);
/// \brief called after the last frame
virtual void EndEvaluate();
// \brief called for each frame which is mapped
virtual void EvalConfiguration(Topology *top, Topology *top_ref = 0);
virtual void EvalConfiguration(Topology *top, Topology *top_ref = nullptr);
// thread related stuff follows
......@@ -99,11 +102,13 @@ class CsgApplication : public tools::Application {
*/
class Worker : public tools::Thread {
public:
Worker(){};
~Worker();
Worker() = default;
;
~Worker() override;
/// \brief overload with the actual computation
virtual void EvalConfiguration(Topology *top, Topology *top_ref = 0) = 0;
virtual void EvalConfiguration(Topology *top,
Topology *top_ref = nullptr) = 0;
/// \brief returns worker id
int getId() { return _id; }
......@@ -114,7 +119,7 @@ class CsgApplication : public tools::Application {
TopologyMap *_map = nullptr;
int _id = -1;
void Run(void);
void Run(void) override;
void setApplication(CsgApplication *app) { _app = app; }
......
......@@ -34,7 +34,7 @@ class Bead;
class ExclusionList {
public:
ExclusionList() {}
ExclusionList() = default;
~ExclusionList() { Clear(); }
void Clear(void);
......@@ -53,7 +53,7 @@ class ExclusionList {
void CreateExclusions(Topology *top);
exclusion_t *GetExclusions(Bead *bead);
typedef std::list<exclusion_t *>::iterator iterator;
using iterator = std::list<exclusion_t *>::iterator;
iterator begin() { return _exclusions.begin(); }
iterator end() { return _exclusions.end(); }
......@@ -76,7 +76,10 @@ class ExclusionList {
inline ExclusionList::exclusion_t *ExclusionList::GetExclusions(Bead *bead) {
std::map<Bead *, exclusion_t *>::iterator iter = _excl_by_bead.find(bead);
if (iter == _excl_by_bead.end()) return nullptr;
if (iter == _excl_by_bead.end()) {
return nullptr;
}
return (*iter).second;
}
......@@ -106,11 +109,17 @@ template <typename iteratable>
inline void ExclusionList::InsertExclusion(Bead *bead1_, iteratable &l) {
for (typename iteratable::iterator i = l.begin(); i != l.end(); ++i) {
Bead *bead1 = bead1_;
;
Bead *bead2 = *i;
if (bead2->getId() < bead1->getId()) std::swap(bead1, bead2);
if (bead1 == bead2) continue;
if (IsExcluded(bead1, bead2)) continue;
if (bead2->getId() < bead1->getId()) {
std::swap(bead1, bead2);
}
if (bead1 == bead2) {
continue;
}
if (IsExcluded(bead1, bead2)) {
continue;
}
exclusion_t *e;
if ((e = GetExclusions(bead1)) == nullptr) {
e = new exclusion_t;
......@@ -124,9 +133,17 @@ inline void ExclusionList::InsertExclusion(Bead *bead1_, iteratable &l) {
// template<>
inline void ExclusionList::InsertExclusion(Bead *bead1, Bead *bead2) {
if (bead2->getId() < bead1->getId()) std::swap(bead1, bead2);
if (bead1 == bead2) return;
if (IsExcluded(bead1, bead2)) return;
if (bead2->getId() < bead1->getId()) {
std::swap(bead1, bead2);
}
if (bead1 == bead2) {
return;
}
if (IsExcluded(bead1, bead2)) {
return;
}
exclusion_t *e;
if ((e = GetExclusions(bead1)) == nullptr) {
......@@ -139,19 +156,35 @@ inline void ExclusionList::InsertExclusion(Bead *bead1, Bead *bead2) {
}
inline void ExclusionList::RemoveExclusion(Bead *bead1, Bead *bead2) {
if (bead2->getId() < bead1->getId()) std::swap(bead1, bead2);
if (bead1 == bead2) return;
if (!IsExcluded(bead1, bead2)) return;
if (bead2->getId() < bead1->getId()) {
std::swap(bead1, bead2);
}
if (bead1 == bead2) {
return;
}
if (!IsExcluded(bead1, bead2)) {
return;
}
std::list<exclusion_t *>::iterator ex;
for (ex = _exclusions.begin(); ex != _exclusions.end(); ++ex)
if ((*ex)->_atom == bead1) break;
if (ex == _exclusions.end()) return;
(*ex)->_exclude.remove(bead2);
if ((*ex)->_exclude.empty()) {
(*ex) = nullptr;
_exclusions.erase(ex);
for (ex = _exclusions.begin(); ex != _exclusions.end(); ++ex) {
if ((*ex)->_atom == bead1) {
break;
}
if (ex == _exclusions.end()) {
return;
}
(*ex)->_exclude.remove(bead2);
if ((*ex)->_exclude.empty()) {
(*ex) = nullptr;
_exclusions.erase(ex);
}
_exclusions.remove(nullptr);
}
_exclusions.remove(nullptr);
}
std::ostream &operator<<(std::ostream &out, ExclusionList &ex);
......
......@@ -30,7 +30,7 @@ namespace TOOLS = votca::tools;
template <typename T>
class FileFormatFactory : public TOOLS::ObjectFactory<std::string, T> {
public:
FileFormatFactory() {}
FileFormatFactory() = default;
T *Create(const std::string &file);
};
......@@ -46,7 +46,7 @@ T *FileFormatFactory<T>::Create(const std::string &file) {
"'" +
file + "' cannot be read or written");
}
return NULL;
return nullptr;
}
} // namespace csg
......
......@@ -23,13 +23,11 @@
#include <sstream>
#include <string>
namespace TOOLS = votca::tools;
namespace votca {
namespace csg {
/**
\brief base calss for all interactions
\brief base class for all interactions
This is the base class for all interactions.
......@@ -37,9 +35,9 @@ namespace csg {
*/
class Interaction {
public:
Interaction() : _index(-1), _group(""), _group_id(-1), _name(""), _mol(-1){};
Interaction() = default;
virtual ~Interaction() {}
virtual ~Interaction() = default;
virtual double EvaluateVar(const Topology &top) = 0;
std::string getName() const { return _name; }
......@@ -88,11 +86,11 @@ class Interaction {
}
protected:
int _index;
std::string _group;
int _group_id;
std::string _name;
int _mol;
int _index = -1;
std::string _group = "";
int _group_id = -1;
std::string _name = "";
int _mol = -1;
std::vector<int> _beads;
void RebuildName();
......@@ -100,14 +98,22 @@ class Interaction {
inline void Interaction::RebuildName() {
std::stringstream s;
if (_mol != -1) s << "molecule " << _mol;
if (_mol != -1) {
{
s << "molecule " << _mol;
}
}
if (!_group.empty()) {
s << ":" << _group;
if (_group_id != -1) {
s << " " << _group_id;
}
}
if (_index != -1) s << ":index " << _index;
if (_index != -1) {
{
s << ":index " << _index;
}
}
_name = s.str();
}
......@@ -130,8 +136,8 @@ class IBond : public Interaction {
beads.pop_front();
}
}
double EvaluateVar(const Topology &top);
Eigen::Vector3d Grad(const Topology &top, int bead);
double EvaluateVar(const Topology &top) override;
Eigen::Vector3d Grad(const Topology &top, int bead) override;
private:
};
......@@ -156,8 +162,8 @@ class IAngle : public Interaction {
}
}
double EvaluateVar(const Topology &top);
Eigen::Vector3d Grad(const Topology &top, int bead);
double EvaluateVar(const Topology &top) override;
Eigen::Vector3d Grad(const Topology &top, int bead) override;
private:
};
......@@ -183,8 +189,8 @@ class IDihedral : public Interaction {
}
}
double EvaluateVar(const Topology &top);
Eigen::Vector3d Grad(const Topology &top, int bead);
double EvaluateVar(const Topology &top) override;
Eigen::Vector3d Grad(const Topology &top, int bead) override;
private:
};
......
......@@ -49,7 +49,8 @@ class Map {
*******************************************************/
class BeadMap {
public:
virtual ~BeadMap(){};
virtual ~BeadMap() = default;
;
virtual void Apply() = 0;
virtual void Initialize(Molecule *in, Bead *out, tools::Property *opts_map,
tools::Property *opts_bead);
......@@ -75,11 +76,11 @@ inline void BeadMap::Initialize(Molecule *in, Bead *out,
*******************************************************/
class Map_Sphere : public BeadMap {
public:
Map_Sphere() {}
void Apply();
Map_Sphere() = default;
void Apply() override;
void Initialize(Molecule *in, Bead *out, tools::Property *opts_bead,
tools::Property *opts_map);
tools::Property *opts_map) override;
protected:
void AddElem(Bead *in, double weight, double force_weight);
......@@ -105,8 +106,8 @@ inline void Map_Sphere::AddElem(Bead *in, double weight, double force_weight) {
*******************************************************/
class Map_Ellipsoid : public Map_Sphere {
public:
Map_Ellipsoid() {}
void Apply();
Map_Ellipsoid() = default;
void Apply() override;
protected:
};
......
......@@ -28,8 +28,6 @@
namespace votca {
namespace csg {
namespace TOOLS = votca::tools;
class Interaction;
/**
......@@ -108,7 +106,11 @@ class Molecule : public TopologyItem {
inline int Molecule::getBeadIdByName(const std::string &name) {
int i = getBeadByName(name);
if (i < 0) return i;
if (i < 0) {
{
return i;
}
}
return _beads[i]->getId();
}
......
......@@ -27,7 +27,7 @@ class Molecule;
class MoleculeItem {
public:
virtual ~MoleculeItem() {}
virtual ~MoleculeItem() = default;
/**
* Returns the molecule the pointer points at
......
......@@ -39,7 +39,7 @@ namespace TOOLS = votca::tools;
class NBList : public PairList<Bead *, BeadPair> {
public:
NBList();
virtual ~NBList();
~NBList() override;
/// Generate the neighbour list based on two bead lists (e.g. bead types)
virtual void Generate(BeadList &list1, BeadList &list2,
......@@ -100,8 +100,7 @@ class NBList : public PairList<Bead *, BeadPair> {
return dynamic_cast<BeadPair *>(new pair_type(bead1, bead2, r));
}
typedef BeadPair *(*pair_creator_t)(Bead *bead1, Bead *bead2,
const Eigen::Vector3d &r);
using pair_creator_t = BeadPair *(*)(Bead *, Bead *, const Eigen::Vector3d &);
/// the current bead pair creator function
pair_creator_t _pair_creator;
......@@ -110,23 +109,24 @@ class NBList : public PairList<Bead *, BeadPair> {
/// functions
class Functor {
public:
Functor() {}
Functor() = default;
virtual bool operator()(Bead *, Bead *, const Eigen::Vector3d &,
const double dist) = 0;
virtual ~Functor(){};
virtual ~Functor() = default;
;
};
/// Functor for member functions
template <typename T>
class FunctorMember : public Functor {
public:
typedef bool (T::*fkt_t)(Bead *, Bead *, const Eigen::Vector3d &,
const double dist);
using fkt_t = bool (T::*)(Bead *, Bead *, const Eigen::Vector3d &,
const double);
FunctorMember(T *cls, fkt_t fkt) : _cls(cls), _fkt(fkt) {}
bool operator()(Bead *b1, Bead *b2, const Eigen::Vector3d &r,
const double dist) {
const double dist) override {
return (_cls->*_fkt)(b1, b2, r, dist);
}
......@@ -138,12 +138,12 @@ class NBList : public PairList<Bead *, BeadPair> {
/// Functor for non-member functions
class FunctorNonMember : public Functor {
public:
typedef bool (*fkt_t)(Bead *, Bead *, const Eigen::Vector3d &,
const double dist);
using fkt_t = bool (*)(Bead *, Bead *, const Eigen::Vector3d &,
const double);
FunctorNonMember(fkt_t fkt) : _fkt(fkt) {}
bool operator()(Bead *b1, Bead *b2, const Eigen::Vector3d &r,
const double dist) {
const double dist) override {
return (*_fkt)(b1, b2, r, dist);
}
......@@ -164,14 +164,18 @@ inline void NBList::SetMatchFunction(T *object,
bool (T::*fkt)(Bead *, Bead *,
const Eigen::Vector3d &,
const double)) {
if (_match_function) delete _match_function;
if (_match_function) {
delete _match_function;
}
_match_function = dynamic_cast<Functor *>(new FunctorMember<T>(object, fkt));
}
inline void NBList::SetMatchFunction(bool (*fkt)(Bead *, Bead *,
const Eigen::Vector3d &,
const double)) {
if (_match_function) delete _match_function;
if (_match_function) {
delete _match_function;
}
_match_function = dynamic_cast<Functor *>(new FunctorNonMember(fkt));
}
......
......@@ -41,7 +41,7 @@ namespace csg {
class NBList_3Body : public TripleList<Bead *, BeadTriple> {
public:
NBList_3Body();
virtual ~NBList_3Body();
~NBList_3Body() override;
/// Generate the 3body neighbour list based on three bead lists (e.g. bead
/// types)
......@@ -124,10 +124,10 @@ class NBList_3Body : public TripleList<Bead *, BeadTriple> {
new triple_type(bead1, bead2, bead3, r12, r13, r23));
}
typedef BeadTriple *(*triple_creator_t)(Bead *bead1, Bead *bead2, Bead *bead3,
const Eigen::Vector3d &r12,
const Eigen::Vector3d &r13,