votca 2024-dev
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
votca::tools::StructureParameters Class Reference

Provides a means to standardise the constructors of different classes. More...

#include <structureparameters.h>

Collaboration diagram for votca::tools::StructureParameters:
Collaboration graph
[legend]

Public Member Functions

void set (const StructureParameter parameter, boost::any value) noexcept
 
template<class T >
get (const StructureParameter parameter) const
 

Private Attributes

std::unordered_map< StructureParameter, boost::any, std::hash< int > > parameters
 

Detailed Description

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.

Member Function Documentation

◆ get()

template<class T >
T votca::tools::StructureParameters::get ( const StructureParameter  parameter) const

Definition at line 120 of file structureparameters.h.

◆ set()

void votca::tools::StructureParameters::set ( const StructureParameter  parameter,
boost::any  value 
)
noexcept

Definition at line 114 of file structureparameters.h.

Member Data Documentation

◆ parameters

std::unordered_map<StructureParameter, boost::any, std::hash<int> > votca::tools::StructureParameters::parameters
private

Definition at line 111 of file structureparameters.h.


The documentation for this class was generated from the following file: