further corrections -> first application compiles

This commit is contained in:
Christian Zimmermann 2017-03-15 22:54:48 +01:00
parent 0eb0f21031
commit 0066cfef54
13 changed files with 245 additions and 84 deletions

View file

@ -93,6 +93,10 @@ namespace MultiArrayTools
template <typename T, class Range, class MARange> template <typename T, class Range, class MARange>
class Slice; class Slice;
// slice.h
template <typename T, class Range, class MARange>
class ConstSlice;
// manipulator.h // manipulator.h
template <typename T> template <typename T>
class ManipulatorBase; class ManipulatorBase;

View file

@ -18,13 +18,13 @@ namespace MultiArrayTools
} }
template <typename T, class Range> template <typename T, class Range>
auto MultiArrayBase<T,Range>::begin() -> decltype(Range().begin()) auto MultiArrayBase<T,Range>::begin() const -> decltype(Range().begin())
{ {
return mRange->begin(); return mRange->begin();
} }
template <typename T, class Range> template <typename T, class Range>
auto MultiArrayBase<T,Range>::end() -> decltype(Range().end()) auto MultiArrayBase<T,Range>::end() const -> decltype(Range().end())
{ {
return mRange->end(); return mRange->end();
} }
@ -119,6 +119,7 @@ namespace MultiArrayTools
mCont.insert(mCont.end(), in[i].mCont.begin(), in[i].mCont.end()); mCont.insert(mCont.end(), in[i].mCont.begin(), in[i].mCont.end());
} }
assert(mCont.size() == MAB::mRange->size()); assert(mCont.size() == MAB::mRange->size());
return *this;
} }
template <typename T, class Range> template <typename T, class Range>

View file

@ -33,8 +33,8 @@ namespace MultiArrayTools
virtual size_t size() const; virtual size_t size() const;
virtual bool isSlice() const = 0; virtual bool isSlice() const = 0;
virtual auto begin() -> decltype(Range().begin()); virtual auto begin() const -> decltype(Range().begin());
virtual auto end() -> decltype(Range().end()); virtual auto end() const -> decltype(Range().end());
virtual const Range& range() const; virtual const Range& range() const;

View file

@ -16,7 +16,7 @@ namespace MultiArrayTools
} }
template <typename T> template <typename T>
IndefinitIndexBase& MultiArrayOperationBase<T>::index() const IndefinitIndexBase& MultiArrayOperationBase<T>::index() const
{ {
return *mIibPtr; return *mIibPtr;
} }
@ -43,10 +43,23 @@ namespace MultiArrayTools
MultiArrayOperationRoot<T,Range>::makeSlice(MultiArrayOperationRoot<T,RangeX>& in) MultiArrayOperationRoot<T,Range>::makeSlice(MultiArrayOperationRoot<T,RangeX>& in)
{ {
Slice<T,Range,RangeX>& sl = dynamic_cast<Slice<T,Range,RangeX>&>( mArrayRef ); Slice<T,Range,RangeX>& sl = dynamic_cast<Slice<T,Range,RangeX>&>( mArrayRef );
sl.set(in.mArrayRef, name(), dynamic_cast<typename RangeX::IndexType&>( in.index() ), in.name()); sl.set(in.mArrayRef, name(), dynamic_cast<const typename RangeX::IndexType&>( in.index() ), in.name());
return *this; return *this;
} }
template <typename T, class Range>
template <class RangeX>
const MultiArrayOperationRoot<T,Range>&
MultiArrayOperationRoot<T,Range>::makeConstSlice(const MultiArrayOperationRoot<T,RangeX>& in)
{
ConstSlice<T,Range,RangeX>& sl = dynamic_cast<ConstSlice<T,Range,RangeX>&>( mArrayRef );
sl.set(in.mArrayRef, name(), dynamic_cast<const typename RangeX::IndexType&>( in.index() ), in.name());
return *this;
}
// CONST SLICE !!!!!
template <typename T, class Range> template <typename T, class Range>
MultiArrayOperationRoot<T,Range>:: MultiArrayOperationRoot<T,Range>::
MultiArrayOperationRoot(MultiArrayBase<T,Range>& ma, MultiArrayOperationRoot(MultiArrayBase<T,Range>& ma,
@ -93,6 +106,18 @@ namespace MultiArrayTools
return *this; return *this;
} }
template <typename T, class Range>
template <class Range2>
const MultiArrayOperationRoot<T,Range>&
MultiArrayOperationRoot<T,Range>::operator=(const MultiArrayOperationRoot<T,Range2>& in)
{
if(mArrayRef.isSlice() and not mArrayRef.isInit()){
return makeConstSlice(in);
}
performAssignment(in);
return *this;
}
template <typename T, class Range> template <typename T, class Range>
template <class Operation, class... MAOps> template <class Operation, class... MAOps>
MultiArrayOperationRoot<T,Range>& MultiArrayOperationRoot<T,Range>&
@ -107,18 +132,18 @@ namespace MultiArrayTools
return *this; return *this;
} }
template <typename T, class Range> /* template <typename T, class Range>
template <class Operation, class... MAOps> template <class Operation, class... MAOps>
MultiArrayOperation<T,Operation,MultiArrayOperationRoot<T,Range>, MAOps...> MultiArrayOperation<T,Operation,MultiArrayOperationRoot<T,Range>, MAOps...>
MultiArrayOperationRoot<T,Range>::operator()(Operation& op, const MAOps&... secs) MultiArrayOperationRoot<T,Range>::operator()(Operation& op, const MAOps&... secs) const
{ {
return MultiArrayOperation<T,Operation,MultiArrayOperationRoot<T,Range>, MAOps...>(op, *this, secs...); return MultiArrayOperation<T,Operation,MultiArrayOperationRoot<T,Range>, MAOps...>(op, *this, secs...);
} }*/
template <typename T, class Range> template <typename T, class Range>
template <class Operation, class... MAOps> template <class Operation, class... MAOps>
MultiArrayOperation<T,Operation,MultiArrayOperationRoot<T,Range>, MAOps...> MultiArrayOperation<T,Operation,MultiArrayOperationRoot<T,Range>, MAOps...>
MultiArrayOperationRoot<T,Range>::operator()(const Operation& op, const MAOps&... secs) MultiArrayOperationRoot<T,Range>::operator()(const Operation& op, const MAOps&... secs) const
{ {
return MultiArrayOperation<T,Operation,MultiArrayOperationRoot<T,Range>, MAOps...>(op, *this, secs...); return MultiArrayOperation<T,Operation,MultiArrayOperationRoot<T,Range>, MAOps...>(op, *this, secs...);
} }
@ -193,6 +218,18 @@ namespace MultiArrayTools
return (*this) = copyThis() / sec; return (*this) = copyThis() / sec;
} }
template <typename T, class Range>
const MultiArrayBase<T,Range>& MultiArrayOperationRoot<T,Range>::operator*() const
{
return mArrayRef;
}
template <typename T, class Range>
MultiArrayBase<T,Range> const* MultiArrayOperationRoot<T,Range>::operator->() const
{
return &mArrayRef;
}
template <typename T, class Range> template <typename T, class Range>
size_t MultiArrayOperationRoot<T,Range>::argNum() const size_t MultiArrayOperationRoot<T,Range>::argNum() const
{ {
@ -232,6 +269,13 @@ namespace MultiArrayTools
return *this; return *this;
} }
template <typename T, class Range>
const MultiArrayOperationRoot<T,Range>& MultiArrayOperationRoot<T,Range>::operator[](const IndexType& ind) const
{
mIndex.copyPos(ind);
return *this;
}
/***************************** /*****************************
* MultiArrayOperation * * MultiArrayOperation *
*****************************/ *****************************/
@ -308,7 +352,7 @@ namespace MultiArrayTools
template <typename T, class Operation, class... MAOps> template <typename T, class Operation, class... MAOps>
template <class Operation2, class... MAOps2> template <class Operation2, class... MAOps2>
MultiArrayOperation<T,Operation2,MultiArrayOperation<T,Operation,MAOps...>,MAOps2...> MultiArrayOperation<T,Operation2,MultiArrayOperation<T,Operation,MAOps...>,MAOps2...>
MultiArrayOperation<T,Operation,MAOps...>::operator()(Operation2& op, const MAOps2&... secs) MultiArrayOperation<T,Operation,MAOps...>::operator()(Operation2& op, const MAOps2&... secs) const
{ {
return MultiArrayOperation<T,Operation2,MultiArrayOperation<T,Operation,MAOps...>, return MultiArrayOperation<T,Operation2,MultiArrayOperation<T,Operation,MAOps...>,
MAOps2...>(op, *this, secs...); MAOps2...>(op, *this, secs...);
@ -317,7 +361,7 @@ namespace MultiArrayTools
template <typename T, class Operation, class... MAOps> template <typename T, class Operation, class... MAOps>
template <class Operation2, class... MAOps2> template <class Operation2, class... MAOps2>
MultiArrayOperation<T,Operation2,MultiArrayOperation<T,Operation,MAOps...>,MAOps2...> MultiArrayOperation<T,Operation2,MultiArrayOperation<T,Operation,MAOps...>,MAOps2...>
MultiArrayOperation<T,Operation,MAOps...>::operator()(const Operation2& op, const MAOps2&... secs) MultiArrayOperation<T,Operation,MAOps...>::operator()(const Operation2& op, const MAOps2&... secs) const
{ {
return MultiArrayOperation<T,Operation2,MultiArrayOperation<T,Operation,MAOps...>, return MultiArrayOperation<T,Operation2,MultiArrayOperation<T,Operation,MAOps...>,
MAOps2...>(op, *this, secs...); MAOps2...>(op, *this, secs...);

View file

@ -21,7 +21,7 @@ namespace MultiArrayTools
virtual ~MultiArrayOperationBase(); virtual ~MultiArrayOperationBase();
virtual size_t argNum() const = 0; virtual size_t argNum() const = 0;
IndefinitIndexBase& index(); const IndefinitIndexBase& index() const;
virtual void linkIndicesTo(IndefinitIndexBase* target) const = 0; virtual void linkIndicesTo(IndefinitIndexBase* target) const = 0;
virtual T& get() = 0; virtual T& get() = 0;
@ -37,7 +37,8 @@ namespace MultiArrayTools
public: public:
typedef MultiArrayOperationBase<T> MAOB; typedef MultiArrayOperationBase<T> MAOB;
typedef decltype(MultiArray<T,Range>().begin()) IndexType; typedef typename Range::IndexType IndexType;
//typedef decltype(MultiArray<T,Range>().begin()) IndexType;
MultiArrayOperationRoot(MultiArrayBase<T,Range>& ma, const Name& nm); MultiArrayOperationRoot(MultiArrayBase<T,Range>& ma, const Name& nm);
MultiArrayOperationRoot& operator=(const MultiArrayOperationRoot& in); MultiArrayOperationRoot& operator=(const MultiArrayOperationRoot& in);
@ -47,16 +48,19 @@ namespace MultiArrayTools
template <class Range2> template <class Range2>
MultiArrayOperationRoot& operator=(MultiArrayOperationRoot<T,Range2>& in); MultiArrayOperationRoot& operator=(MultiArrayOperationRoot<T,Range2>& in);
template <class Range2>
const MultiArrayOperationRoot& operator=(const MultiArrayOperationRoot<T,Range2>& in);
template <class Operation, class... MAOps> template <class Operation, class... MAOps>
MultiArrayOperationRoot& operator=(const MultiArrayOperation<T,Operation,MAOps...>& in); MultiArrayOperationRoot& operator=(const MultiArrayOperation<T,Operation,MAOps...>& in);
template <class Operation, class... MAOps> //template <class Operation, class... MAOps>
MultiArrayOperation<T,Operation,MultiArrayOperationRoot<T,Range>, MAOps...> //MultiArrayOperation<T,Operation,MultiArrayOperationRoot<T,Range>, MAOps...>
operator()(Operation& op, const MAOps&... secs); //operator()(Operation& op, const MAOps&... secs) const;
template <class Operation, class... MAOps> template <class Operation, class... MAOps>
MultiArrayOperation<T,Operation,MultiArrayOperationRoot<T,Range>, MAOps...> MultiArrayOperation<T,Operation,MultiArrayOperationRoot<T,Range>, MAOps...>
operator()(const Operation& op, const MAOps&... secs); operator()(const Operation& op, const MAOps&... secs) const;
template <class MAOp> template <class MAOp>
auto operator+(const MAOp& sec) -> decltype(operator()(std::plus<T>(), sec)); auto operator+(const MAOp& sec) -> decltype(operator()(std::plus<T>(), sec));
@ -84,10 +88,14 @@ namespace MultiArrayTools
template <class MAOp> template <class MAOp>
MultiArrayOperationRoot& operator/=(const MAOp& sec); MultiArrayOperationRoot& operator/=(const MAOp& sec);
const MultiArrayBase<T,Range>& operator*() const;
MultiArrayBase<T,Range> const* operator->() const;
virtual size_t argNum() const override; virtual size_t argNum() const override;
// set index -> implement !!!!! // set index -> implement !!!!!
MultiArrayOperationRoot<T,Range>& operator[](const IndexType& ind); MultiArrayOperationRoot<T,Range>& operator[](const IndexType& ind);
const MultiArrayOperationRoot<T,Range>& operator[](const IndexType& ind) const;
virtual void linkIndicesTo(IndefinitIndexBase* target) const override; virtual void linkIndicesTo(IndefinitIndexBase* target) const override;
@ -106,6 +114,9 @@ namespace MultiArrayTools
template <class RangeX> template <class RangeX>
MultiArrayOperationRoot& makeSlice(MultiArrayOperationRoot<T,RangeX>& in); MultiArrayOperationRoot& makeSlice(MultiArrayOperationRoot<T,RangeX>& in);
template <class RangeX>
const MultiArrayOperationRoot& makeConstSlice(const MultiArrayOperationRoot<T,RangeX>& in);
MultiArrayBase<T,Range>& mArrayRef; MultiArrayBase<T,Range>& mArrayRef;
mutable IndexType mIndex; mutable IndexType mIndex;
Name mNm; Name mNm;
@ -124,11 +135,11 @@ namespace MultiArrayTools
template <class Operation2, class... MAOps2> template <class Operation2, class... MAOps2>
MultiArrayOperation<T,Operation2,MultiArrayOperation<T,Operation,MAOps...>,MAOps2...> MultiArrayOperation<T,Operation2,MultiArrayOperation<T,Operation,MAOps...>,MAOps2...>
operator()(Operation2& op, const MAOps2&... secs); operator()(Operation2& op, const MAOps2&... secs) const;
template <class Operation2, class... MAOps2> template <class Operation2, class... MAOps2>
MultiArrayOperation<T,Operation2,MultiArrayOperation<T,Operation,MAOps...>,MAOps2...> MultiArrayOperation<T,Operation2,MultiArrayOperation<T,Operation,MAOps...>,MAOps2...>
operator()(const Operation2& op, const MAOps2&... secs); operator()(const Operation2& op, const MAOps2&... secs) const;
template <class MAOp2> template <class MAOp2>
auto operator+(const MAOp2& sec) -> decltype(operator()(std::plus<T>(), sec)); auto operator+(const MAOp2& sec) -> decltype(operator()(std::plus<T>(), sec));

View file

@ -236,8 +236,8 @@ namespace MultiArrayTools
struct MetaPosGetter struct MetaPosGetter
{ {
template <class... Indices> template <class... Indices>
static void getMetaPos(typename MultiIndex<Indices...>::MetaType& target, static void getMetaPos(std::tuple<decltype(Indices().getMetaPos())...>& target,
const typename MultiIndex<Indices...>::IndexPack& source) const std::tuple<Indices...>& source)
{ {
std::get<N>(target) = std::get<N>(source).getMetaPos(); std::get<N>(target) = std::get<N>(source).getMetaPos();
MetaPosGetter<N-1>::getMetaPos(target, source); MetaPosGetter<N-1>::getMetaPos(target, source);
@ -248,8 +248,8 @@ namespace MultiArrayTools
struct MetaPosGetter<0> struct MetaPosGetter<0>
{ {
template <class... Indices> template <class... Indices>
static void getMetaPos(typename MultiIndex<Indices...>::MetaType& target, static void getMetaPos(std::tuple<decltype(Indices().getMetaPos())...>& target,
const typename MultiIndex<Indices...>::IndexPack& source) const std::tuple<Indices...>& source)
{ {
std::get<0>(target) = std::get<0>(source).getMetaPos(); std::get<0>(target) = std::get<0>(source).getMetaPos();
} }
@ -614,33 +614,26 @@ namespace MultiArrayTools
} }
template <size_t N> template <size_t N>
struct MetaTypePrinter struct TuplePrinter
{ {
template <class... Indices> template <typename... Ts>
static void print(std::ostream& os, typename MultiIndex<Indices...>::MetaType& meta) static void print(std::ostream& os, const std::tuple<Ts...>& meta)
{ {
MetaTypePrinter<N-1>::print(os, meta); TuplePrinter<N-1>::print(os, meta);
os << std::get<N>(meta) << '\t'; os << std::get<N>(meta) << '\t';
} }
}; };
template <> template <>
struct MetaTypePrinter<0> struct TuplePrinter<0>
{ {
template <class... Indices> template <typename... Ts>
static void print(std::ostream& os, typename MultiIndex<Indices...>::MetaType& meta) static void print(std::ostream& os, const std::tuple<Ts...>& meta)
{ {
os << std::get<0>(meta) << '\t'; os << std::get<0>(meta) << '\t';
} }
}; };
template <class... Indices>
std::ostream& operator<<(std::ostream& os, typename MultiIndex<Indices...>::MetaType& meta)
{
MetaTypePrinter<sizeof...(Indices)-1>::print(os, meta);
return os;
}
/****************** /******************
* MultiRange * * MultiRange *
******************/ ******************/
@ -701,3 +694,11 @@ namespace MultiArrayTools
return ++MultiIndex<typename Ranges::IndexType...>(this, is); return ++MultiIndex<typename Ranges::IndexType...>(this, is);
} }
} }
template <typename... Ts>
std::ostream& operator<<(std::ostream& os,
const std::tuple<Ts...>& meta)
{
MultiArrayTools::TuplePrinter<sizeof...(Ts)-1>::print(os, meta);
return os;
}

View file

@ -92,9 +92,6 @@ namespace MultiArrayTools
//virtual void assignRange(RangeBase<MultiIndex<Indices...> > const* range) override; //virtual void assignRange(RangeBase<MultiIndex<Indices...> > const* range) override;
}; };
template <class... Indices>
std::ostream& operator<<(std::ostream& os, typename MultiIndex<Indices...>::MetaType& meta);
/***************************** /*****************************
* IndexGetter Functions * * IndexGetter Functions *
****************************/ ****************************/
@ -106,6 +103,7 @@ namespace MultiArrayTools
public: public:
typedef std::tuple<Ranges...> SpaceType; typedef std::tuple<Ranges...> SpaceType;
typedef typename RangeBase<MultiIndex<typename Ranges::IndexType...> >::IndexType IndexType;
DEFAULT_MEMBERS(MultiRange); DEFAULT_MEMBERS(MultiRange);
@ -134,6 +132,11 @@ namespace MultiArrayTools
} }
template <typename... Ts>
std::ostream& operator<<(std::ostream& os,
const std::tuple<Ts...>& meta);
#include "multi_range.cc" #include "multi_range.cc"
#endif #endif

View file

@ -6,39 +6,40 @@ namespace MultiArrayTools
namespace namespace
{ {
struct Naming
void giveNames(std::vector<Name>& nvec)
{ {
nvec.clear(); static void giveNames(std::vector<Name>& nvec)
} {
nvec.clear();
void giveNames(std::vector<Name>& nvec, const Name& name) }
{
nvec.push_back(name);
}
template <class... NameTypes>
void giveNames(std::vector<Name>& nvec, const Name& name1, const Name& name2, const NameTypes&... names)
{
nvec.push_back(name1);
giveNames(nvec, name2, names...);
}
static void giveNames(std::vector<Name>& nvec, const Name& name)
{
nvec.push_back(name);
}
template <class... NameTypes>
static void giveNames(std::vector<Name>& nvec, const Name& name1,
const Name& name2, const NameTypes&... names)
{
nvec.push_back(name1);
giveNames(nvec, name2, names...);
}
};
} }
template <class... NameTypes> template <class... NameTypes>
Name::Name(const std::string& mainName, const NameTypes&... names) : mMain(mainName) Name::Name(const std::string& mainName, const NameTypes&... names) : mMain(mainName)
{ {
mSub.reserve(sizeof...(NameTypes)); mSub.reserve(sizeof...(NameTypes));
giveNames(mSub, names...); Naming::giveNames(mSub, names...);
} }
template <class... NameTypes> template <class... NameTypes>
Name::Name(char const* mainName, const NameTypes&... names) : mMain(mainName) Name::Name(char const* mainName, const NameTypes&... names) : mMain(mainName)
{ {
mSub.reserve(sizeof...(NameTypes)); mSub.reserve(sizeof...(NameTypes));
giveNames(mSub, names...); Naming::giveNames(mSub, names...);
} }
const std::string& Name::own() const const std::string& Name::own() const
@ -67,17 +68,18 @@ namespace MultiArrayTools
return mSub.size(); return mSub.size();
} }
std::ostream& operator<<(std::ostream& os, const Name& name)
{
if(name.size() != 0){
for(size_t i = 0; i != name.size(); ++i){
os << name.get(i) << '\t';
}
}
else {
os << name.own();
}
return os;
}
} }
std::ostream& operator<<(std::ostream& os, const MultiArrayTools::Name& name)
{
if(name.size() != 0){
for(size_t i = 0; i != name.size(); ++i){
os << name.get(i) << '\t';
}
}
else {
os << name.own();
}
return os;
}

View file

@ -34,10 +34,10 @@ namespace MultiArrayTools
std::vector<Name> mSub; std::vector<Name> mSub;
}; };
std::ostream& operator<<(std::ostream& os, const Name& name);
} }
std::ostream& operator<<(std::ostream& os, const MultiArrayTools::Name& name);
#include "name.cc" #include "name.cc"
#endif #endif

View file

@ -288,7 +288,7 @@ namespace MultiArrayTools
} }
template <typename U, RangeType TYPE> template <typename U, RangeType TYPE>
const U& SingleIndex<U,TYPE>::getMetaPos() const U SingleIndex<U,TYPE>::getMetaPos() const
{ {
return dynamic_cast<SingleRange<U,TYPE> const*>( IB::mRange )->get(IIB::pos()); return dynamic_cast<SingleRange<U,TYPE> const*>( IB::mRange )->get(IIB::pos());
} }
@ -346,6 +346,11 @@ namespace MultiArrayTools
} }
} }
std::ostream& operator<<(std::ostream& os, VET vet)
{
os << ( (vet == VET::VALUE) ? std::string("VALUE") : std::string("ERROR") );
return os;
}
/* /*
template <typename U, RangeType TYPE> template <typename U, RangeType TYPE>

View file

@ -43,7 +43,7 @@ namespace MultiArrayTools
virtual MultiRangeType rangeType() const override; virtual MultiRangeType rangeType() const override;
virtual const U& getMetaPos() const; virtual U getMetaPos() const;
virtual SingleIndex& atMeta(const U& metaPos); virtual SingleIndex& atMeta(const U& metaPos);
virtual size_t dim() const override; // = 1 virtual size_t dim() const override; // = 1
@ -65,12 +65,15 @@ namespace MultiArrayTools
class SingleRange : public RangeBase<SingleIndex<U,TYPE> > class SingleRange : public RangeBase<SingleIndex<U,TYPE> >
{ {
public: public:
typedef typename RangeBase<SingleIndex<U,TYPE> >::IndexType IndexType;
DEFAULT_MEMBERS(SingleRange); DEFAULT_MEMBERS(SingleRange);
SingleRange(const std::vector<U>& space); SingleRange(const std::vector<U>& space);
virtual size_t size() const override; virtual size_t size() const override;
//U get(size_t pos) const;
const U& get(size_t pos) const; const U& get(size_t pos) const;
size_t getMeta(const U& metaPos) const; size_t getMeta(const U& metaPos) const;
@ -89,6 +92,8 @@ namespace MultiArrayTools
class SingleRange<int,RangeType::SPACE> : public RangeBase<SingleIndex<int,RangeType::SPACE> > class SingleRange<int,RangeType::SPACE> : public RangeBase<SingleIndex<int,RangeType::SPACE> >
{ {
public: public:
typedef typename RangeBase<SingleIndex<int,RangeType::SPACE> >::IndexType IndexType;
DEFAULT_MEMBERS(SingleRange); DEFAULT_MEMBERS(SingleRange);
SingleRange(int begin, int end); SingleRange(int begin, int end);
@ -112,6 +117,8 @@ namespace MultiArrayTools
class SingleRange<size_t,RangeType::ENSEMBLE> : public RangeBase<SingleIndex<size_t,RangeType::ENSEMBLE> > class SingleRange<size_t,RangeType::ENSEMBLE> : public RangeBase<SingleIndex<size_t,RangeType::ENSEMBLE> >
{ {
public: public:
typedef typename RangeBase<SingleIndex<size_t,RangeType::ENSEMBLE> >::IndexType IndexType;
DEFAULT_MEMBERS(SingleRange); DEFAULT_MEMBERS(SingleRange);
SingleRange(size_t num); SingleRange(size_t num);
@ -136,10 +143,14 @@ namespace MultiArrayTools
ERROR = 1 ERROR = 1
}; };
std::ostream& operator<<(std::ostream& os, VET vet);
template <> template <>
class SingleRange<VET,RangeType::VALUE_ERROR> : public RangeBase<SingleIndex<VET,RangeType::VALUE_ERROR> > class SingleRange<VET,RangeType::VALUE_ERROR> : public RangeBase<SingleIndex<VET,RangeType::VALUE_ERROR> >
{ {
public: public:
typedef typename RangeBase<SingleIndex<VET,RangeType::VALUE_ERROR> >::IndexType IndexType;
DEFAULT_MEMBERS(SingleRange); DEFAULT_MEMBERS(SingleRange);
virtual size_t size() const override; virtual size_t size() const override;
@ -157,6 +168,8 @@ namespace MultiArrayTools
class SingleRange<size_t,RangeType::LORENTZ> : public RangeBase<SingleIndex<size_t,RangeType::LORENTZ> > class SingleRange<size_t,RangeType::LORENTZ> : public RangeBase<SingleIndex<size_t,RangeType::LORENTZ> >
{ {
public: public:
typedef typename RangeBase<SingleIndex<size_t,RangeType::LORENTZ> >::IndexType IndexType;
DEFAULT_MEMBERS(SingleRange); DEFAULT_MEMBERS(SingleRange);
virtual size_t size() const override; virtual size_t size() const override;

View file

@ -32,13 +32,13 @@ namespace MultiArrayTools
} }
template <typename T, class Range, class MARange> template <typename T, class Range, class MARange>
auto Slice<T,Range,MARange>::begin() -> decltype(Range().begin()) auto Slice<T,Range,MARange>::begin() const -> decltype(Range().begin())
{ {
return MAB::mRange->begin(); return MAB::mRange->begin();
} }
template <typename T, class Range, class MARange> template <typename T, class Range, class MARange>
auto Slice<T,Range,MARange>::end() -> decltype(Range().end()) auto Slice<T,Range,MARange>::end() const -> decltype(Range().end())
{ {
return MAB::mRange->end(); return MAB::mRange->end();
} }
@ -58,4 +58,50 @@ namespace MultiArrayTools
//mOwnIdx = i.pos(); //mOwnIdx = i.pos();
return (*mMultiArrayPtr)[ mMAIdx ]; return (*mMultiArrayPtr)[ mMAIdx ];
} }
template <typename T, class Range, class MARange>
ConstSlice<T,Range,MARange>::
ConstSlice(const Range& range) :
MultiArrayBase<T,Range>(range) {}
template <typename T, class Range, class MARange>
bool ConstSlice<T,Range,MARange>::isSlice() const
{
return true;
}
template <typename T, class Range, class MARange>
void ConstSlice<T,Range,MARange>::set(const MultiArrayBase<T,MARange>& multiArrayRef,
const Name& ownNm, // for correct linkage
const typename MARange::IndexType& MAIdx, // for desired slice position
const Name& MANm) // for correct linkage)
{
MAB::mInit = true;
mMultiArrayPtr = &multiArrayRef;
mMAIdx = MAIdx;
mOwnIdx = MAB::mRange->begin();
mMAIdx.name(MANm);
mOwnIdx.name(ownNm);
mMAIdx.linkTo(&mOwnIdx);
}
template <typename T, class Range, class MARange>
auto ConstSlice<T,Range,MARange>::begin() const -> decltype(Range().begin())
{
return MAB::mRange->begin();
}
template <typename T, class Range, class MARange>
auto ConstSlice<T,Range,MARange>::end() const -> decltype(Range().end())
{
return MAB::mRange->end();
}
template <typename T, class Range, class MARange>
const T& ConstSlice<T,Range,MARange>::operator[](const typename Range::IndexType& i) const
{
mOwnIdx.copyPos(i);
//mOwnIdx = i.pos();
return (*mMultiArrayPtr)[ mMAIdx ];
}
} }

View file

@ -29,8 +29,8 @@ namespace MultiArrayTools
//Slice& setSlicePos(const Index& slicePos); //Slice& setSlicePos(const Index& slicePos);
// link given Index to mMAPtr which is index of total array // link given Index to mMAPtr which is index of total array
virtual auto begin() -> decltype(Range().begin()) override; virtual auto begin() const -> decltype(Range().begin()) override;
virtual auto end() -> decltype(Range().end()) override; virtual auto end() const -> decltype(Range().end()) override;
virtual bool isSlice() const override; virtual bool isSlice() const override;
@ -46,6 +46,37 @@ namespace MultiArrayTools
mutable typename MARange::IndexType mMAIdx; mutable typename MARange::IndexType mMAIdx;
}; };
template <typename T, class Range, class MARange/*, class Index*/>
class ConstSlice : public MultiArrayBase<T,Range> // yes, 'Range' is correct !!!
{
public:
typedef MultiArrayBase<T,Range> MAB;
ConstSlice(const Range& range);
virtual const T& operator[](const typename Range::IndexType& i) const override;
//Slice& setSlicePos(const Index& slicePos);
// link given Index to mMAPtr which is index of total array
virtual auto begin() const -> decltype(Range().begin()) override;
virtual auto end() const -> decltype(Range().end()) override;
virtual bool isSlice() const override;
void set(const MultiArrayBase<T,MARange>& multiArrayRef,
const Name& ownNm,
const typename MARange::IndexType& MAIdx,
const Name& MANm);
private:
MultiArrayBase<T,MARange> const* mMultiArrayPtr = nullptr;
mutable typename Range::IndexType mOwnIdx;
mutable typename MARange::IndexType mMAIdx;
};
} }