diff --git a/src/include/mbase_def.h b/src/include/mbase_def.h index aad6cdf..d97e4ae 100644 --- a/src/include/mbase_def.h +++ b/src/include/mbase_def.h @@ -51,6 +51,10 @@ namespace MultiArrayTools template class ConstOperationRoot; + // multi_array_operation.h + template + class OperationPointer; + // multi_array_operation.h template class Operation; diff --git a/src/include/multi_array_operation.cc.h b/src/include/multi_array_operation.cc.h index 6096506..183bb70 100644 --- a/src/include/multi_array_operation.cc.h +++ b/src/include/multi_array_operation.cc.h @@ -134,6 +134,14 @@ namespace MultiArrayTools return Operation,OperationClass, Args...>(ll, THIS(), args...); } + template + auto OperationBase::ptr() const + -> OperationPointer + { + return OperationPointer(THIS()); + } + + /************************ * AssignmentExpr * ************************/ @@ -839,6 +847,40 @@ namespace MultiArrayTools } + /************************** + * OperationPointer * + **************************/ + + template + template + inline const T* OperationPointer::get(ET pos) const + { + return &mOp.get(pos); + } + + template + template + inline OperationPointer& OperationPointer::set(ET pos) + { + mOp.set(pos); + return *this; + } + + template + auto OperationPointer::rootSteps(std::intptr_t iPtrNum) const + -> decltype(mOp.rootSteps(0)) + { + return mOp.rootSteps(iPtrNum); + } + + template + template + auto OperationPointer::loop(Expr exp) const + -> decltype(mOp.loop(exp)) + { + return mOp.loop(exp); + } + /******************* * Operation * *******************/ diff --git a/src/include/multi_array_operation.h b/src/include/multi_array_operation.h index 871db03..01887cd 100644 --- a/src/include/multi_array_operation.h +++ b/src/include/multi_array_operation.h @@ -82,7 +82,10 @@ namespace MultiArrayTools template // Args = Operation Classes auto a(const std::shared_ptr>& ll, const Args&... args) const -> Operation,OperationClass, Args...>; - + + auto ptr() const + -> OperationPointer; + private: friend OperationClass; friend OperationTemplate; @@ -654,7 +657,43 @@ namespace MultiArrayTools T mVal; }; + template + class OperationPointer : public OperationTemplate> + { + public: + typedef T value_type; + typedef OperationTemplate> OT; + + static constexpr size_t SIZE = Op::SIZE; + static constexpr bool CONT = false; + + private: + Op mOp; + + public: + + OperationPointer(const Op& op) : mOp(op) + { + static_assert(Op::CONT, + "OperationPointer can only be applied to containing operations"); + } + + template + inline const T* get(ET pos) const; + + template + inline OperationPointer& set(ET pos); + + auto rootSteps(std::intptr_t iPtrNum = 0) const // nullptr for simple usage with decltype + -> decltype(mOp.rootSteps(0)); + + template + auto loop(Expr exp) const + -> decltype(mOp.loop(exp)); + + T const** data() const { assert(0); return nullptr; } + }; template class Operation : public OperationTemplate >