votca 2024.2-dev
|
Provides a means to standardise the constructors of different classes. More...
#include <structureparameters.h>
Public Member Functions | |
void | set (const StructureParameter parameter, boost::any value) noexcept |
template<class T > | |
T | get (const StructureParameter parameter) const |
Private Attributes | |
std::unordered_map< StructureParameter, boost::any, std::hash< int > > | parameters |
Provides a means to standardise the constructors of different classes.
The purpose of this class is for use primarily in io readers, it provides a means to standardize the use of templated classes in the readers.
E.g. Say I have two atom classes
class Atom1 { public: Atom1(StructureParameters parameters) : id_(parameters.get<Index>(StructureParameter::BeadId)), mass_(parameters.get<double>(StructureParameter::Mass)){};
private: Index id_; double mass_; };
class Atom2 { public: Atom2(StructureParameters parameters) : id_(parameters.get<Index>(StructureParameter::BeadId)), element_(parameters.get<string>(StructureParameter::Element)){};
private: Index id_; string element_; };
Pseudo code below, our file reader has a method that creates the atoms (shown below), now because we have a standardized constructor the templated file method can be used with either class without specialization.
class FileReader {
template<class T> T CreateAtomOrBead {
string element = "C"; Index id = 1; double mass = 12.01;
StructureParameters parameters; parameters.set(StructureParameter::Element,element); parameters.set(StructureParameter::Mass,mass); parameters.set(StructureParameter::BeadId,id);
T atom_or_bead(parameters); return atom_or_bead; }
};
Definition at line 102 of file structureparameters.h.
T votca::tools::StructureParameters::get | ( | const StructureParameter | parameter | ) | const |
Definition at line 120 of file structureparameters.h.
|
noexcept |
Definition at line 114 of file structureparameters.h.
|
private |
Definition at line 111 of file structureparameters.h.