WIP: dynamic_operation

This commit is contained in:
Christian Zimmermann 2020-07-10 00:17:38 +02:00
parent a64291484c
commit b2f542027f
4 changed files with 151 additions and 0 deletions

View file

@ -0,0 +1,37 @@
#include "dynamic_operation.h"
namespace MultiArrayTools
{
template <typename T, class Operation>
const T& DynamicOperation<T,Operation>::get(const DExt& pos) const
{
return mOp.get(pos.expl<ET>());
}
template <typename T, class Operation>
DynamicOperationBase& DynamicOperation<T,Operation>::set(const DExt& pos)
{
mOp.set(pos.expl<ET>());
return *this;
}
template <typename T, class Operation>
DExt DynamicOperation<T,Operation>::rootSteps(std::intptr_t iPtrNum = 0) const
{
return mOp.rootSteps(iPtrNum);
}
template <typename T, class Operation>
DynamicExpression DynamicOperation<T,Operation>::loop(const DynamicExpression& exp) const
{
return mOp.loop(exp);
}
template <typename T, class Operation>
const T* DynamicOperation<T,Operation>::data() const
{
return mOp.data();
}
} // namespace MultiArrayTools

View file

@ -0,0 +1,60 @@
#ifndef __dynamic_operation_h__
#define __dynamic_operation_h__
#include "base_def.h"
#include "multi_array_operation.h"
namespace MultiArrayTools
{
template <typename T>
class DynamicOperationBase : public OperationTemplate<T,DynamicOperationBase<T>>
{
public:
typedef T value_type;
typedef OperationBase<T,DynamicOperationBase<T>> OT;
static constexpr size_t SIZE = 1;
static constexpr bool CONT = true;
DynamicOperationBase() = default;
DynamicOperationBase(const DynamicOperationBase& in) = default;
DynamicOperationBase(DynamicOperationBase&& in) = default;
DynamicOperationBase& operator=(const DynamicOperationBase& in) = default;
DynamicOperationBase& operator=(DynamicOperationBase&& in) = default;
virtual const T& get(const DExt& pos) const = 0;
virtual DynamicOperationBase& set(const DExt& pos) = 0;
virtual DExt rootSteps(std::intptr_t iPtrNum = 0) const = 0;
virtual DynamicExpression loop(const DynamicExpression& exp) const = 0;
virtual const T* data() const = 0;
};
template <typename T, class Operation>
class DynamicOperation : public DynamicOperationBase<T>
{
private:
Operation mOp;
public:
typedef decltype(std::declval<Operation>().rootSteps()) ET;
DynamicOperation() = default;
DynamicOperation(const DynamicOperation& in) = default;
DynamicOperation(DynamicOperation&& in) = default;
DynamicOperation& operator=(const DynamicOperation& in) = default;
DynamicOperation& operator=(DynamicOperation&& in) = default;
DynamicOperation(const Operation& op) : mOp(op) {}
virtual const T& get(const DExt& pos) const override final;
virtual DynamicOperationBase& set(const DExt& pos) override final;
virtual DExt rootSteps(std::intptr_t iPtrNum = 0) const override final;
virtual DynamicExpression loop(const DynamicExpression& exp) const override final;
virtual const T* data() const override final;
};
} // namespace MultiArrayTools
#endif

View file

@ -0,0 +1,46 @@
#ifndef __operation_helper_h__
#define __operation_helper_h__
#include "multi_array_operation.h"
namespace MultiArrayTools
{
template <class BaseArray, class... Ranges>
class PseudoArray
{
size_t mThreadNum;
Slice<> mSl;
mutable ConstOperationRoot<T,Range> mOp;
public:
template <class ET>
const SrcHolder<ConstOperationRoot<T,Range>> operator[](ET pos) const;
};
template <class Operation>
class SrcHolder
{
TempHolder operator+(SrcHolder in) const;
// aso
};
template <class Operation>
class TempHolder
{
TempHolder operator+(SrcHolder in) const;
TempHolder operator+(TempHolder in) const;
};
template <class Operation>
class TarHolder
{
TarHolder& operator=(TempHolder in);
};
} // namespace MultiArrayTools
#endif

View file

@ -36,6 +36,9 @@ namespace MultiArrayHelper
//virtual size_t rootSteps() const = 0; //virtual size_t rootSteps() const = 0;
virtual std::shared_ptr<ExtBase> operator+(const ExtBase& in) const = 0; virtual std::shared_ptr<ExtBase> operator+(const ExtBase& in) const = 0;
virtual std::shared_ptr<ExtBase> operator*(size_t in) const = 0; virtual std::shared_ptr<ExtBase> operator*(size_t in) const = 0;
template <class ExtType>
const ExtType& expl() const { return dynamic_cast<const ExtT<ExtType>*>(this)->ext(); }
}; };
typedef std::shared_ptr<ExtBase> DExt; typedef std::shared_ptr<ExtBase> DExt;
@ -444,6 +447,11 @@ namespace MultiArrayHelper
namespace MultiArrayHelper namespace MultiArrayHelper
{ {
template <class ExtType>
const ExtType& ExtBase::expl() const
{
return dynamic_cast<const ExtT<ExtType>*>(this)->ext();
}
/***************** /*****************
* F o r * * F o r *