// -*- 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 BlockClass1& arg1, const BlockClass2& arg2); }; // EVERYTHING IN HERE MUST N O T BE VITUAL !! template class BlockBase { public: DEFAULT_MEMBERS(BlockBase); BlockBase(size_t size); size_t size() const; 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); }; template class Block : public BlockBase { public: DEFAULT_MEMBERS(Block); Block(const std::vector& data, size_t begPos, size_t size, size_t stepSize); BlockType type() const; const T& operator[](size_t pos) const; Block& set(size_t npos); size_t stepSize() const; protected: const std::vector* mData; const T* mBegPtr; size_t mStepSize; }; template class MBlock : public MutableBlockBase { public: DEFAULT_MEMBERS(MBlock); MBlock(std::vector& data, size_t begPos, size_t size, size_t stepSize); template MBlock& operator=(const BlockClass& in); BlockType type() const; const T& operator[](size_t pos) const; T& operator[](size_t pos); MBlock& set(size_t npos); size_t stepSize() const; protected: std::vector* mData; T* mBegPtr; size_t mStepSize; }; template class BlockResult : public MutableBlockBase { public: DEFAULT_MEMBERS(BlockResult); BlockResult(size_t size); template BlockResult& operator=(const BlockClass& in); BlockType type() const; const T& operator[](size_t pos) const; T& operator[](size_t i); BlockResult& set(size_t npos); size_t stepSize() const; BlockResult& operator+=(const BlockBase& in); BlockResult& operator-=(const BlockBase& in); BlockResult& operator*=(const BlockBase& in); BlockResult& operator/=(const BlockBase& in); template BlockResult& operateSelf(const BlockBase& in); protected: std::vector mRes; }; } // end namespace MultiArrayHelper #include "block.cc" #endif