/* * AtomSet.hpp * * Created on: Jul 30, 2010 * Author: crueger */ #ifndef ATOMSET_HPP_ #define ATOMSET_HPP_ #include #include #include #include #include /** * A simple mixin to give any STL conforming structure fast Vector abilities * * TODO: make this work for maps */ #include "atom.hpp" // this tests, whether we actually have a Vector template struct is_atom{}; template <> struct is_atom{ typedef void wrong_type; }; template class AtomSetMixin : public Set { // when our set carries something besides a atom* this will produce an error typedef typename is_atom::wrong_type check_for_atom; public: // typedefs for STL conforming structure typedef typename Set::iterator iterator; typedef typename Set::const_iterator const_iterator; AtomSetMixin() : Set() {} AtomSetMixin(const Set& src) : Set(src) {} virtual ~AtomSetMixin(){} /** * translate all Atoms within this set by a specified amount */ void translate(const Vector &translater); template void transformNodes(Function f); double totalTemperatureAtStep(unsigned int i) const; private: template struct workOnNodePointer { workOnNodePointer(Function &_f) : f(_f){} void operator()(atom *atom){ atom->setPosition(f(atom->getPosition())); } Function &f; }; struct temperatureSum { temperatureSum(unsigned int _step) : step(_step),value(0) {} double operator+(atom *atom){ return value + atom->getKineticEnergy(step); } double operator=(double _value){ value = _value; return value; } unsigned int step; double value; }; }; template inline void AtomSetMixin::translate(const Vector &translater){ BOOST_FOREACH(atom *atom,*this){ *(atom) += translater; } } template template inline void AtomSetMixin::transformNodes(Function f){ std::for_each(this->begin(), this->end(), AtomSetMixin::workOnNodePointer(f)); } template inline double AtomSetMixin::totalTemperatureAtStep(unsigned int step) const{ return accumulate(this->begin(),this->end(),temperatureSum(step)).value; } // allows simpler definition of AtomSets #define ATOMSET(container_type) AtomSetMixin > #endif /* ATOMSET_HPP_ */