#ifndef STAR_RUTABLE_HPP #define STAR_RUTABLE_HPP #include "StarInterpolation.hpp" #include "StarArray.hpp" #include namespace Star { template struct Storage; template struct Storage { std::vector positions; std::vector elements; template void pushDim(Position const& position, size_t dim, IndexList const& index) { starAssert(false); } template void pushElement(Position const& position, Element const& element, IndexList const& index) { positions.push_back(position); elements.push_back(element); } template Element const& get(IndexList const& index) const { return elements[index[Rank - 1]]; } }; template struct Storage { typedef Storage Stored; template void pushDim(Position const& position, size_t dim, IndexList const& index) { if (dim == Rank - StorageRank) { positions.push_back(position); elements.push_back(Stored()); } else { elements[index[Rank - StorageRank]].pushDim(position, dim, index); } } template void pushElement(Position const& position, Element const& element, IndexList const& index) { elements[index[Rank - StorageRank]].pushElement(position, element, index); } template Element const& get(IndexList const& index) const { return elements[index[Rank - StorageRank]].get(index); } std::vector positions; std::vector elements; }; template class RUTable { public: typedef ElementT Element; typedef PositionT Position; static size_t const Rank = RankN; typedef Array PositionList; typedef Array IndexList; typedef Array SizeList; RUTable() : m_curDim(0), m_curIndex(IndexList::filled(0)) {} void pushDim(Position const& position) { m_storage.pushDim(position, m_curDim, m_curIndex); ++m_curDim; } void pushElement(Position const& position, Element const& element) { m_storage.pushElement(position, element, m_curIndex); ++m_curIndex[Rank - 1]; } void popDim() { m_curIndex[m_curDim] = 0; --m_curDim; ++m_curIndex[m_curDim]; } Element const& get(IndexList const& index) const { return m_storage.get(index); } private: size_t m_curDim; IndexList m_curIndex; Storage m_storage; }; } #endif