// -*- C++ -*- #ifndef __block_h__ #define __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 BlockBase { public: BlockBase() = default; BlockBase(size_t size); virtual BlockType type() const = 0; virtual size_t size() const; virtual const T& operator[](size_t pos) const = 0; virtual BlockBase& set(const T* nbeg) = 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 class MutableBlockBase : public BlockBase { public: MutableBlockBase() = default; MutableBlockBase(size_t size); virtual T& operator[](size_t pos) override; }; template class Block : public BlockBase { public: Block() = default; 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(const T* nbeg) override; protected: const T* mBegPtr; }; template class MBlock : public MutableBlockBase { public: MBlock() = default; 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 Block& set(const T* nbeg) override; protected: T* mBegPtr; }; template class BlockValue : public BlockBase { public: BlockValue() = default; BlockValue(const T& val, size_t size); virtual BlockType type() const override; virtual const T& operator[](size_t pos) const override; virtual BlockValue& set(const T* nbeg) override; protected: T mVal; }; template class MBlockValue : public MutableBlockBase { public: MBlockValue() = default; MBlockValue(T& val, 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 BlockValue& set(const T* nbeg) override; protected: T& mVal; }; template class SplitBlock : public BlockBase { public: SplitBlock() = default; 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(const T* nbeg) override; protected: size_t mStepSize; const T* mBegPtr; }; template class MSplitBlock : public MutableBlockBase { public: MSplitBlock() = default; 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 SplitBlock& set(const T* nbeg) override; protected: size_t mStepSize; T* mBegPtr; }; template class BlockResult : public MutableBlockBase { public: BlockResult() = default; 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(const T* nbeg) override; protected: std::vector mRes; }; } // end namespace MultiArrayHelper #include "block.cc" #endif