// -*- C++ -*- #ifndef __ma_block_h__ #define __ma_block_h__ #include #include #include "base_def.h" namespace MultiArrayHelper { enum class BlockType { INDEF = 0, BLOCK = 1, VALUE = 2, SPLIT = 3, RESULT = 4 }; // manage vectorization in the future !! template class BlockBinaryOp { public: BlockBinaryOp() = default; BlockResult operator()(const BlockBase& arg1, const BlockBase& arg2); }; template class BlockBase { public: DEFAULT_MEMBERS(BlockBase); BlockBase(size_t size); virtual BlockType type() const = 0; virtual size_t stepSize() const = 0; virtual size_t size() const; virtual const T& operator[](size_t pos) const = 0; virtual BlockBase& set(size_t npos) = 0; template BlockResult operate(const BlockBase& in); BlockResult operator+(const BlockBase& in); BlockResult operator-(const BlockBase& in); BlockResult operator*(const BlockBase& in); BlockResult operator/(const BlockBase& in); protected: size_t mSize; }; template std::ostream& operator<<(std::ostream& out, const BlockBase& block) { out << block[0]; for(size_t i = 1; i != block.size(); ++i){ out << ", " << block[i]; } return out; } template class MutableBlockBase : public BlockBase { public: DEFAULT_MEMBERS(MutableBlockBase); MutableBlockBase(size_t size); MutableBlockBase& operator=(const BlockBase& in); virtual T& operator[](size_t pos) = 0; }; template class Block : public BlockBase { public: DEFAULT_MEMBERS(Block); Block(const std::vector& data, size_t begPos, size_t size); virtual BlockType type() const override; virtual const T& operator[](size_t pos) const override; virtual Block& set(size_t npos) override; virtual size_t stepSize() const override; protected: const std::vector* mData; const T* mBegPtr; }; template class MBlock : public MutableBlockBase { public: DEFAULT_MEMBERS(MBlock); MBlock(std::vector& data, size_t begPos, size_t size); virtual BlockType type() const override; virtual const T& operator[](size_t pos) const override; virtual T& operator[](size_t pos) override; virtual MBlock& set(size_t npos) override; virtual size_t stepSize() const override; protected: std::vector* mData; T* mBegPtr; }; template class BlockValue : public BlockBase { public: DEFAULT_MEMBERS(BlockValue); BlockValue(const std::vector& data, size_t pos, size_t size); virtual BlockType type() const override; virtual const T& operator[](size_t pos) const override; virtual BlockValue& set(size_t npos) override; virtual size_t stepSize() const override; protected: const std::vector* mData; const T* mVal; }; template class MBlockValue : public MutableBlockBase { public: DEFAULT_MEMBERS(MBlockValue); MBlockValue(std::vector& data, size_t pos, size_t size); virtual BlockType type() const override; virtual const T& operator[](size_t pos) const override; virtual T& operator[](size_t pos) override; virtual MBlockValue& set(size_t npos) override; virtual size_t stepSize() const override; protected: std::vector* mData; T* mVal; }; template class SplitBlock : public BlockBase { public: DEFAULT_MEMBERS(SplitBlock); SplitBlock(const std::vector& data, size_t begPos, size_t stepSize, size_t size); virtual BlockType type() const override; virtual const T& operator[](size_t pos) const override; virtual SplitBlock& set(size_t npos) override; virtual size_t stepSize() const override; protected: const std::vector* mData; size_t mStepSize; const T* mBegPtr; }; template class MSplitBlock : public MutableBlockBase { public: DEFAULT_MEMBERS(MSplitBlock); MSplitBlock(std::vector& data, size_t begPos, size_t stepSize, size_t size); virtual BlockType type() const override; virtual const T& operator[](size_t pos) const override; virtual T& operator[](size_t pos) override; virtual MSplitBlock& set(size_t npos) override; virtual size_t stepSize() const override; protected: std::vector* mData; size_t mStepSize; T* mBegPtr; }; template class BlockResult : public MutableBlockBase { public: DEFAULT_MEMBERS(BlockResult); BlockResult(size_t size); virtual BlockType type() const override; virtual const T& operator[](size_t pos) const override; virtual T& operator[](size_t i) override; virtual BlockResult& set(size_t npos) override; virtual size_t stepSize() const override; protected: std::vector mRes; }; } // end namespace MultiArrayHelper #include "block.cc" #endif