// -*- C++ -*- #ifndef __multi_array_operation_h__ #define __multi_array_operation_h__ #include #include #include #include "base_def.h" #include "index_base.h" namespace MultiArrayTools { /* * OperationBase * MutableOperationBase * * OperationMaster : MutableOperationBase * * OperationTemplate<...> * ConstOperationRoot : OperationBase, OperationTemplate<...> * OperationRoot : MutableOperationBase, * OperationTemplate<...> * */ typedef std::map > IndexList; template class OperationBase { public: typedef T value_type; OperationBase() = default; virtual ~OperationBase(); //virtual size_t argNum() const = 0; virtual const T& get() const = 0; }; template class MutableOperationBase : public OperationBase { public: MutableOperationBase() = default; virtual T& get() = 0; }; template class OperationMaster : public MutableOperationBase { public: typedef OperationBase OB; typedef typename MultiRange::IndexType IndexType; OperationMaster(OperationRoot&& root); virtual T& get() override; virtual const T& get() const override; protected: void performAssignment(const MultiArrayOperationBase& in); MutableMultiArrayBase& mArrayRef; mutable IndexType mIndex; }; template class ConstOperationRoot : public OperationBase, public OperationTemplate > { public: typedef OperationBase OB; typedef OperationTemplate > OT; typedef ContainerRange CRange; typedef typename CRange::IndexType IndexType; ConstOperationRoot(const MultiArrayBase& ma, const std::shared_ptr&... indices); virtual const T& get() const override; protected: MultiArrayBase const& mArrayRef; std::shared_ptr mIndex; }; template class OperationRoot : public MutableOperationBase, public OperationTemplate > { public: typedef OperationBase OB; typedef OperationTemplate > OT; typedef ContainerRange CRange; typedef typename CRange::IndexType IndexType; OperationRoot(MutableMultiArrayBase& ma, const std::shared_ptr&... indices); virtual const T& get() const override; virtual T& get() override; protected: MutableMultiArrayBase& mArrayRef; std::shared_ptr mIndex; }; template class Operation : public OperationBase, public OperationTemplate > { public: typedef OperationBase OB; typedef OperationTemplate > OT; typedef OpFunction F; Operation(Ops&&... ops); virtual const T& get() const override; protected: std::tuple mOps; T res; }; #include "multi_array_operation.cc" #endif