/* * AtomSet.hpp * * Created on: Jul 30, 2010 * Author: crueger */ #ifndef ATOMSET_HPP_ #define ATOMSET_HPP_ #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" #include // 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); private: template struct workOnNodePointer { workOnNodePointer(Function &_f) : f(_f){} void operator()(atom *atom){ atom->setPosition(f(atom->getPosition())); } Function &f; }; }; 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)); } // allows simpler definition of AtomSets #define ATOMSET(container_type) AtomSetMixin > #endif /* ATOMSET_HPP_ */