cnorxz/src/multi_array_operation.h

157 lines
3.6 KiB
C
Raw Normal View History

2017-02-16 11:20:40 +01:00
// -*- C++ -*-
#ifndef __multi_array_operation_h__
#define __multi_array_operation_h__
#include <cstdlib>
#include <tuple>
2017-03-22 21:51:54 +01:00
#include <cmath>
2017-02-16 11:20:40 +01:00
#include "base_def.h"
#include "index_base.h"
namespace MultiArrayTools
{
2017-08-10 15:12:26 +02:00
/*
* OperationBase
* MutableOperationBase
*
* OperationMaster : MutableOperationBase
*
* OperationTemplate<...>
* ConstOperationRoot : OperationBase, OperationTemplate<...>
* OperationRoot : MutableOperationBase,
* OperationTemplate<...>
*
*/
typedef std::map<Name,std::shared_ptr<IndexBase> > IndexList;
2017-05-22 18:21:14 +02:00
template <typename T>
2017-08-10 15:12:26 +02:00
class OperationBase
2017-02-16 11:20:40 +01:00
{
public:
2017-02-24 20:50:58 +01:00
typedef T value_type;
2017-08-10 15:12:26 +02:00
OperationBase() = default;
virtual ~OperationBase();
2017-08-10 15:12:26 +02:00
//virtual size_t argNum() const = 0;
virtual const T& get() const = 0;
};
2017-05-24 19:01:02 +02:00
template <typename T>
2017-08-10 15:12:26 +02:00
class MutableOperationBase : public OperationBase<T>
{
public:
2017-08-10 15:12:26 +02:00
MutableOperationBase() = default;
virtual T& get() = 0;
};
2017-08-11 11:30:27 +02:00
template <class OperationClass>
class OperationTemplate
{
public:
template <class Second>
Operation<OperationClass,Second> operator+(const Second& in) const;
};
2017-08-10 15:12:26 +02:00
template <typename T, class... Ranges>
class OperationMaster : public MutableOperationBase<T>
{
public:
2017-08-10 15:12:26 +02:00
typedef OperationBase<T> OB;
typedef typename MultiRange<Ranges...>::IndexType IndexType;
2017-03-08 22:53:18 +01:00
2017-08-11 11:30:27 +02:00
OperationMaster(MutableMultiArrayBase& ma, OperationBase<T>& second,
const ContainerRange<Ranges...>::IndexType& index);
virtual T& get() override;
virtual const T& get() const override;
2017-02-27 17:00:51 +01:00
2017-02-16 11:20:40 +01:00
protected:
2017-02-27 17:00:51 +01:00
2017-08-11 11:30:27 +02:00
//void performAssignment(const OperationBase<T>& in);
OperationBase<T> const& mSecond;
2017-08-10 15:12:26 +02:00
MutableMultiArrayBase<T,CRange>& mArrayRef;
2017-08-11 11:30:27 +02:00
std::shared_ptr<IndexType> mIndex;
2017-02-16 11:20:40 +01:00
};
2017-08-10 15:12:26 +02:00
2017-08-10 15:12:26 +02:00
template <typename T, class... Ranges>
class ConstOperationRoot : public OperationBase<T>,
public OperationTemplate<ConstOperationRoot<T,CRange> >
{
public:
2017-08-10 15:12:26 +02:00
typedef OperationBase<T> OB;
typedef OperationTemplate<ConstOperationRoot<T,CRange> > OT;
typedef ContainerRange<Ranges...> CRange;
typedef typename CRange::IndexType IndexType;
2017-08-10 15:12:26 +02:00
ConstOperationRoot(const MultiArrayBase<T,CRange>& ma,
const std::shared_ptr<typename Ranges::IndexType>&... indices);
virtual const T& get() const override;
protected:
2017-08-10 15:12:26 +02:00
MultiArrayBase<T,CRange> const& mArrayRef;
std::shared_ptr<IndexType> mIndex;
};
2017-02-16 11:20:40 +01:00
2017-08-10 15:12:26 +02:00
template <typename T, class... Ranges>
class OperationRoot : public MutableOperationBase<T>,
public OperationTemplate<OperationRoot<T,CRange> >
{
public:
2017-08-10 15:12:26 +02:00
typedef OperationBase<T> OB;
typedef OperationTemplate<OperationRoot<T,CRange> > OT;
typedef ContainerRange<Ranges...> CRange;
typedef typename CRange::IndexType IndexType;
2017-08-10 15:12:26 +02:00
OperationRoot(MutableMultiArrayBase<T,CRange>& ma,
const std::shared_ptr<typename Ranges::IndexType>&... indices);
2017-08-11 11:30:27 +02:00
OperationMaster<T,Ranges...> operator=(const OperationBase<T>& in);
virtual const T& get() const override;
virtual T& get() override;
2017-05-24 19:01:02 +02:00
protected:
2017-08-10 15:12:26 +02:00
MutableMultiArrayBase<T,CRange>& mArrayRef;
std::shared_ptr<IndexType> mIndex;
2017-02-16 11:20:40 +01:00
};
2017-08-10 15:12:26 +02:00
template <typename T, class OpFunction, class... Ops>
class Operation : public OperationBase<T>,
public OperationTemplate<Operation<T,OpFunction,Ops...> >
2017-03-22 11:44:33 +01:00
{
public:
2017-05-22 18:21:14 +02:00
2017-08-10 15:12:26 +02:00
typedef OperationBase<T> OB;
typedef OperationTemplate<Operation<T,OpFunction,Ops...> > OT;
typedef OpFunction F;
2017-03-22 11:44:33 +01:00
2017-08-10 15:12:26 +02:00
Operation(Ops&&... ops);
2017-03-22 11:44:33 +01:00
virtual const T& get() const override;
2017-08-10 15:12:26 +02:00
2017-03-22 11:44:33 +01:00
protected:
2017-08-10 15:12:26 +02:00
std::tuple<Ops...> mOps;
T res;
2017-03-22 11:44:33 +01:00
};
2017-08-10 15:12:26 +02:00
2017-02-16 11:20:40 +01:00
#include "multi_array_operation.cc"
2017-02-16 11:20:40 +01:00
#endif