cnorxz/src/block.h

149 lines
3.1 KiB
C
Raw Normal View History

// -*- C++ -*-
#ifndef __ma_block_h__
#define __ma_block_h__
#include <cstdlib>
#include <vector>
#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 <typename T, class OpFunc, class BlockClass1, class BlockClass2>
2017-09-09 19:59:09 +02:00
class BlockBinaryOp
{
public:
BlockBinaryOp() = default;
BlockResult<T> operator()(const BlockClass1& arg1, const BlockClass2& arg2);
2017-09-09 19:59:09 +02:00
};
// EVERYTHING IN HERE MUST N O T BE VITUAL !!
template <typename T>
class BlockBase
{
public:
DEFAULT_MEMBERS(BlockBase);
BlockBase(size_t size);
size_t size() const;
2017-08-27 17:52:50 +02:00
template <class OpFunction>
BlockResult<T> operate(const BlockBase& in);
2017-08-27 17:52:50 +02:00
BlockResult<T> operator+(const BlockBase& in);
BlockResult<T> operator-(const BlockBase& in);
BlockResult<T> operator*(const BlockBase& in);
BlockResult<T> operator/(const BlockBase& in);
protected:
size_t mSize;
};
2017-09-11 12:54:24 +02:00
template <typename T>
std::ostream& operator<<(std::ostream& out, const BlockBase<T>& block)
{
out << block[0];
for(size_t i = 1; i != block.size(); ++i){
out << ", " << block[i];
}
return out;
}
2017-08-30 17:56:38 +02:00
template <typename T>
class MutableBlockBase : public BlockBase<T>
{
public:
DEFAULT_MEMBERS(MutableBlockBase);
2017-08-30 17:56:38 +02:00
MutableBlockBase(size_t size);
2017-08-30 17:56:38 +02:00
};
template <typename T>
class Block : public BlockBase<T>
{
public:
DEFAULT_MEMBERS(Block);
Block(const std::vector<T>& 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;
2017-08-27 17:52:50 +02:00
protected:
2017-09-09 19:59:09 +02:00
const std::vector<T>* mData;
2017-08-27 17:52:50 +02:00
const T* mBegPtr;
size_t mStepSize;
};
2017-08-30 17:56:38 +02:00
template <typename T>
class MBlock : public MutableBlockBase<T>
{
public:
DEFAULT_MEMBERS(MBlock);
MBlock(std::vector<T>& data, size_t begPos, size_t size, size_t stepSize);
2017-08-30 17:56:38 +02:00
template <class BlockClass>
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;
2017-08-30 17:56:38 +02:00
protected:
2017-09-09 19:59:09 +02:00
std::vector<T>* mData;
T* mBegPtr;
2017-08-30 17:56:38 +02:00
size_t mStepSize;
};
2017-08-30 17:56:38 +02:00
template <typename T>
class BlockResult : public MutableBlockBase<T>
{
public:
DEFAULT_MEMBERS(BlockResult);
BlockResult(size_t size);
template <class BlockClass>
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;
2017-11-03 23:03:29 +01:00
BlockResult<T>& operator+=(const BlockBase& in);
BlockResult<T>& operator-=(const BlockBase& in);
BlockResult<T>& operator*=(const BlockBase& in);
BlockResult<T>& operator/=(const BlockBase& in);
template <class OpFunction>
BlockResult<T>& operateSelf(const BlockBase& in);
protected:
std::vector<T> mRes;
};
} // end namespace MultiArrayHelper
#include "block.cc"
#endif