cnorxz/src/multi_range.h

134 lines
3.5 KiB
C
Raw Normal View History

2017-02-16 11:20:40 +01:00
// -*- C++ -*-
#ifndef __multi_range_h__
#define __multi_range_h__
#include <cstdlib>
#include <tuple>
#include "base_def.h"
#include "range_base.h"
#include "index_base.h"
namespace MultiArrayTools
{
template <class... Indices>
class MultiIndex : public IndexBase<MultiIndex<Indices...> >
{
public:
typedef std::tuple<Indices...> IndexPack;
typedef IndefinitIndexBase IIB;
typedef IndexBase<MultiIndex<Indices...> > IB;
typedef std::tuple<decltype(Indices().getMetaPos())...> MetaType;
protected:
virtual bool linkLower(IndefinitIndexBase* toLink);
virtual size_t evaluate(const MultiIndex& in) const override;
IndexPack mIPack;
2017-02-16 11:20:40 +01:00
public:
2017-02-28 19:29:52 +01:00
MultiIndex() = default;
// NO DEFAULT HERE !!!
// ( have to subord sub-indices (mMajor) correctly, and not only copy their mMajor pointer to 'in'
// which is not major any more in copies!! )
MultiIndex(const MultiIndex& in);
MultiIndex& operator=(const MultiIndex& in);
MultiIndex(RangeBase<MultiIndex<Indices...> > const* range);
2017-02-21 17:41:48 +01:00
MultiIndex(RangeBase<MultiIndex<Indices...> > const* range,
Indices&&... inds);
MultiIndex(RangeBase<MultiIndex<Indices...> > const* range,
const IndexPack& ipack);
2017-02-16 11:20:40 +01:00
2017-02-28 19:29:52 +01:00
//virtual ~MultiIndex();
2017-02-16 11:20:40 +01:00
virtual MultiIndex& operator++() override;
virtual MultiIndex& operator--() override;
virtual MultiIndex& operator+=(int n) override;
virtual MultiIndex& operator-=(int n) override;
2017-02-22 00:43:38 +01:00
bool operator==(const MultiIndex& in);
bool operator!=(const MultiIndex& in);
virtual IIB& operator=(size_t pos) override;
virtual MultiRangeType rangeType() const override;
2017-02-16 11:20:40 +01:00
template <size_t N>
2017-02-21 17:41:48 +01:00
typename std::tuple_element<N, std::tuple<Indices...> >::type& getIndex();
2017-02-16 11:20:40 +01:00
template <size_t N>
2017-02-21 17:41:48 +01:00
typename std::tuple_element<N, std::tuple<Indices...> >::type const& getIndex() const;
IndefinitIndexBase& get(size_t n);
const IndefinitIndexBase& get(size_t n) const;
2017-02-16 16:06:23 +01:00
MetaType getMetaPos() const;
MultiIndex& atMeta(const MetaType& metaPos);
MultiIndex& operator()(Indices&&... inds);
2017-02-21 17:41:48 +01:00
MultiIndex& operator()(const Indices&... inds);
2017-02-16 16:06:23 +01:00
virtual void name(const Name& nm) override;
2017-02-16 11:20:40 +01:00
2017-02-16 13:12:20 +01:00
// dimension of MultiRange; includes ALL degrees of freedom
virtual size_t dim() const override;
2017-02-16 11:20:40 +01:00
virtual bool link(IndefinitIndexBase* toLink) override;
virtual void linkTo(IndefinitIndexBase* target) override;
2017-02-21 17:41:48 +01:00
virtual void copyPos(const MultiIndex<Indices...>& in) override;
2017-02-28 19:29:52 +01:00
2017-03-01 10:41:29 +01:00
//virtual void eval() override;
//virtual bool virt() const override { return false; }
2017-02-21 17:41:48 +01:00
//virtual void assignRange(RangeBase<MultiIndex<Indices...> > const* range) override;
2017-02-16 11:20:40 +01:00
};
2017-02-21 17:41:48 +01:00
/*****************************
* IndexGetter Functions *
****************************/
2017-02-16 11:20:40 +01:00
template <class... Ranges>
class MultiRange : public RangeBase<MultiIndex<typename Ranges::IndexType...> >
2017-02-16 11:20:40 +01:00
{
public:
typedef std::tuple<Ranges...> SpaceType;
2017-02-16 11:20:40 +01:00
DEFAULT_MEMBERS(MultiRange);
MultiRange(const Ranges&... rs);
2017-03-08 20:10:11 +01:00
MultiRange(const SpaceType& space);
static const size_t dim = sizeof...(Ranges);
template <size_t N>
auto getRange() -> decltype( std::get<N>(SpaceType()) );
2017-02-16 11:20:40 +01:00
template <size_t N>
auto getRange() const -> decltype( std::get<N>(SpaceType()) );
2017-02-21 17:41:48 +01:00
size_t size() const override;
2017-02-28 19:29:52 +01:00
const SpaceType& space() const;
virtual MultiRangeType type() const override;
virtual MultiIndex<typename Ranges::IndexType...> begin() const override;
virtual MultiIndex<typename Ranges::IndexType...> end() const override;
2017-02-16 11:20:40 +01:00
protected:
SpaceType mSpace;
2017-02-16 11:20:40 +01:00
};
}
#include "multi_range.cc"
#endif