#ifndef __JTOOLS__JMULTIGRID__ #define __JTOOLS__JMULTIGRID__ #include "JTools/JAbstractMultiMap.hh" #include "JTools/JGrid.hh" /** * \author mdejong */ namespace JTOOLS {} namespace JPP { using namespace JTOOLS; } namespace JTOOLS { /** * Simple data structure for an abstract multidimensional map of equidistant elements. * * This class implements the JAbstractMultiMap interface. */ template class JMultiGrid : public virtual JAbstractMultiMap, public JMultiGrid { public: typedef JAbscissa_t abscissa_type; typedef JMultiKey key_type; using JMultiGrid::operator(); /** * Default constructor. */ JMultiGrid() : JMultiGrid() {} /** * Constructor. * * \param bounds bounds */ JMultiGrid(const JGrid& bounds) : JMultiGrid(bounds) { this->bounds = bounds; } /** * Set bounds. * * \param index index of dimension * \param bounds bounds * \return true if correctly set; else false */ bool set(unsigned int index, const JGrid& bounds) { if (index == N - 1) { this->bounds = bounds; } else if (index < N - 1) { return static_cast&>(*this).set(index, bounds); } return false; } /** * Get abscissa values as a function of given key. * * \param key key * \return abscissa values */ virtual const JGrid& operator()(const key_type& key) const override { return bounds; } protected: JGrid bounds; }; /** * Terminator class of recursive class JMultiGrid. * This class provides for dummy implementations of interface methods. */ template class JMultiGrid<0, JAbscissa_t> { protected: typedef JAbscissa_t abscissa_type; friend class JMultiGrid<1, JAbscissa_t>; /** * Default constructor. */ JMultiGrid() {} /** * Constructor. * * \param bounds bounds */ JMultiGrid(const JGrid& bounds) {} /** * This method does nothing. * * \param index index * \param bounds bounds * \return false */ bool set(unsigned int index, const JGrid& bounds) const { return false; } /** * Dummy operator. */ void operator()() const {} }; /** * Helper method for JMultiGrid. * * \param bounds bounds * \return multidimensional grid */ template inline JMultiGrid make_multigrid(const JGrid& bounds) { return JMultiGrid(bounds); } } #endif