#ifndef _libgeodecomp_misc_neighborhoodadapter_h_ #define _libgeodecomp_misc_neighborhoodadapter_h_ #include #include #include namespace LibGeoDecomp { /** * This class is most useful for interfacing meshless codes with * LibGeoDecomp. It can retrieve cells matching a certain id from the * ContainerCells in the current neighborhood. */ template class NeighborhoodAdapter { public: typedef KEY Key; typedef CARGO Cargo; NeighborhoodAdapter(NEIGHBORHOOD *_neighbors) : neighbors(_neighbors) {} const Cargo& operator[](const Key& id) { const Cargo *res = (*neighbors)[Coord()][id]; if (res) return *res; CoordBox surroundingBox(Coord::diagonal(-1), Coord::diagonal(3)); CoordBoxSequence s = surroundingBox.sequence(); while (s.hasNext()) { Coord c = s.next(); if (c != Coord()) { res = (*neighbors)[c][id]; if (res) return *res; } } throw std::logic_error("id not found"); } inline const Cargo& operator[](const Key& id) const { return (const_cast(*this))[id]; } private: NEIGHBORHOOD *neighbors; }; } #endif