This commit is contained in:
Christian Zimmermann 2017-06-01 13:19:27 +02:00
parent 370dc2efee
commit 30d8e5e5b2
7 changed files with 199 additions and 158 deletions

View file

@ -95,12 +95,7 @@ namespace MultiArrayTools
typedef std::tuple<std::shared_ptr<Ranges>...> SpaceType;
typedef typename RangeBase<MultiIndex<typename Ranges::IndexType...> >::IndexType
IndexType;
DEFAULT_MEMBERS(MultiRange);
MultiRange(const std::shared_ptr<Ranges>&... rs);
MultiRange(const SpaceType& space);
static const size_t dim = sizeof...(Ranges);
template <size_t N> // !!! return ref to range, not the corresp. shared ptr
@ -122,6 +117,14 @@ namespace MultiArrayTools
virtual std::shared_ptr<IndefinitIndexBase> indexInstance() const override;
protected:
MultiRange() = delete;
MultiRange(const MultiRange& in) = delete;
MultiRange& operator=(const MultiRange& in) = delete;
MultiRange(const std::shared_ptr<Ranges>&... rs);
MultiRange(const SpaceType& space);
SpaceType mSpace;
};

View file

@ -86,6 +86,7 @@ namespace MultiArrayTools
mMultiType = new std::vector<MultiRangeType>( multiType );
mType = RangeType::NIL;
}
/******************
* RangeBase *

View file

@ -61,12 +61,17 @@ namespace MultiArrayTools
virtual ~IndefinitRangeBase() = default;
static std::shared_ptr<IndefinitRangeBase> makeInstance(const MultiRangeType& mrt); // !!!
virtual size_t size() const = 0;
virtual bool isSubRange() const = 0;
virtual MultiRangeType type() const = 0;
virtual std::shared_ptr<IndefinitIndexBase> indexInstance() const = 0;
protected:
// only constructable via Factory
IndefinitRangeBase() = default;
IndefinitRangeBase(const IndefinitRangeBase& in) = delete;
IndefinitRangeBase& operator=(const IndefinitRangeBase& in) = delete;
};
template <class Index>
@ -81,6 +86,11 @@ namespace MultiArrayTools
virtual bool isSubRange() const override;
virtual std::shared_ptr<IndefinitIndexBase> indexInstance() const override;
protected:
RangeBase() = default;
RangeBase(const RangeBase& in) = delete;
RangeBase& operator=(const RangeBase& in) = delete;
};
//template <class Range>

8
src/range_factory.cc Normal file
View file

@ -0,0 +1,8 @@
// -*- C++ -*-
#include "range_factory.h"
namespace MultiArrayTools
{
} //namespace MultiArrayTools

26
src/range_factory.h Normal file
View file

@ -0,0 +1,26 @@
// -*- C++ -*-
#ifndef __range_factory_h__
#define __range_factory_h__
#include <cstdlib>
#include <memory>
#include "base_def.h"
namespace MultiArrayTools
{
class RangeFactoryBase
{
public:
DEFAULT_MEMBERS(RangeFactoryBase);
virtual std::shared_ptr<IndefinitRangeBase> create() const = 0;
};
} //namespace MultiArrayTools
#include "range_factory.cc"
#endif

View file

@ -3,6 +3,134 @@
namespace MultiArrayTools
{
/******************
* SingleIndex *
******************/
template <typename U, RangeType TYPE>
SingleIndex<U,TYPE>::SingleIndex(const U& upos,
std::shared_ptr<const RangeBase<SingleIndex<U,TYPE> > >& rangePtr) :
IndexBase<SingleIndex<U,TYPE> >(rangePtr)
{
IIB::setPos( dynamic_pointer_cast<const SingleRange<U,TYPE> >( IB::mRangePtr )->get(upos) );
}
template <typename U, RangeType TYPE>
SingleIndex<U,TYPE>::SingleIndex(std::shared_ptr<const RangeBase<SingleIndex<U,TYPE> > >& rangePtr,
size_t pos) : IndexBase<SingleIndex<U,TYPE> >(range)
{
IIB::setPos( pos );
}
template <typename U, RangeType TYPE>
SingleIndex<U,TYPE>& SingleIndex<U,TYPE>::operator=(size_t pos)
{
IIB::setPos( pos );
return *this;
}
template <typename U, RangeType TYPE>
SingleIndex<U,TYPE>& SingleIndex<U,TYPE>::operator++()
{
IIB::setPos( IIB::pos() + 1 );
return *this;
}
template <typename U, RangeType TYPE>
SingleIndex<U,TYPE>& SingleIndex<U,TYPE>::operator--()
{
IIB::setPos( IIB::pos() - 1 );
return *this;
}
template <typename U, RangeType TYPE>
SingleIndex<U,TYPE>& SingleIndex<U,TYPE>::operator+=(int n)
{
IIB::setPos( IIB::pos() + n );
return *this;
}
template <typename U, RangeType TYPE>
SingleIndex<U,TYPE>& SingleIndex<U,TYPE>::operator-=(int n)
{
IIB::setPos( IIB::pos() - n );
return *this;
}
template <typename U, RangeType TYPE>
bool SingleIndex<U,TYPE>::operator==(const SingleIndex<U,TYPE>& i)
{
return IB::mRange == i.mRange and IIB::pos() == static_cast<size_t>( i.mPos );
}
template <typename U, RangeType TYPE>
bool SingleIndex<U,TYPE>::operator!=(const SingleIndex<U,TYPE>& i)
{
return IB::mRange != i.mRange or IIB::pos() != static_cast<size_t>( i.mPos );
}
template <typename U, RangeType TYPE>
MultiRangeType SingleIndex<U,TYPE>::rangeType() const
{
return MultiRangeType(TYPE);
}
template <typename U, RangeType TYPE>
U SingleIndex<U,TYPE>::getMetaPos() const
{
return dynamic_cast<SingleRange<U,TYPE> const*>( IB::mRange )->get(IIB::pos());
}
template <typename U, RangeType TYPE>
SingleIndex<U,TYPE>& SingleIndex<U,TYPE>::atMeta(const U& metaPos)
{
operator=( dynamic_cast<SingleRange<U,TYPE> const*>( IB::mRange )->getMeta(metaPos) );
return *this;
}
template <typename U, RangeType TYPE>
size_t SingleIndex<U,TYPE>::dim() const
{
return 1;
}
template <typename U, RangeType TYPE>
size_t SingleIndex<U,TYPE>::evaluate(const SingleIndex<U,TYPE>& in) const
{
return in.pos();
}
template <typename U, RangeType TYPE>
void SingleIndex<U,TYPE>::copyPos(const SingleIndex<U,TYPE>& in)
{
IIB::setPos(in.pos());
}
template <typename U, RangeType TYPE>
size_t SingleIndex<U,TYPE>::giveSubStepSize(IndefinitIndexBase* subIndex)
{
if(subIndex == this){
return 1;
}
else {
return 0;
}
}
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>
void SingleIndex<U,TYPE>::eval()
{
IIB::setPos( evaluate( *this ) );
}
*/
/********************
* SingleRange *
********************/
@ -251,130 +379,4 @@ namespace MultiArrayTools
return SingleIndex<size_t,RangeType::LORENTZ>(this, size());
}
/******************
* SingleIndex *
******************/
template <typename U, RangeType TYPE>
SingleIndex<U,TYPE>::SingleIndex(RangeBase<SingleIndex<U,TYPE> > const* range,
const U& upos, size_t disambig) : IndexBase<SingleIndex<U,TYPE> >(range)
{
IIB::setPos( dynamic_cast<SingleRange<U,TYPE> const*>( IB::mRange )->get(upos) );
}
template <typename U, RangeType TYPE>
SingleIndex<U,TYPE>::SingleIndex(RangeBase<SingleIndex<U,TYPE> > const* range,
size_t pos) : IndexBase<SingleIndex<U,TYPE> >(range)
{
IIB::setPos( pos );
}
template <typename U, RangeType TYPE>
SingleIndex<U,TYPE>& SingleIndex<U,TYPE>::operator=(size_t pos)
{
IIB::setPos( pos );
return *this;
}
template <typename U, RangeType TYPE>
SingleIndex<U,TYPE>& SingleIndex<U,TYPE>::operator++()
{
IIB::setPos( IIB::pos() + 1 );
return *this;
}
template <typename U, RangeType TYPE>
SingleIndex<U,TYPE>& SingleIndex<U,TYPE>::operator--()
{
IIB::setPos( IIB::pos() - 1 );
return *this;
}
template <typename U, RangeType TYPE>
SingleIndex<U,TYPE>& SingleIndex<U,TYPE>::operator+=(int n)
{
IIB::setPos( IIB::pos() + n );
return *this;
}
template <typename U, RangeType TYPE>
SingleIndex<U,TYPE>& SingleIndex<U,TYPE>::operator-=(int n)
{
IIB::setPos( IIB::pos() - n );
return *this;
}
template <typename U, RangeType TYPE>
bool SingleIndex<U,TYPE>::operator==(const SingleIndex<U,TYPE>& i)
{
return IB::mRange == i.mRange and IIB::pos() == static_cast<size_t>( i.mPos );
}
template <typename U, RangeType TYPE>
bool SingleIndex<U,TYPE>::operator!=(const SingleIndex<U,TYPE>& i)
{
return IB::mRange != i.mRange or IIB::pos() != static_cast<size_t>( i.mPos );
}
template <typename U, RangeType TYPE>
MultiRangeType SingleIndex<U,TYPE>::rangeType() const
{
return MultiRangeType(TYPE);
}
template <typename U, RangeType TYPE>
U SingleIndex<U,TYPE>::getMetaPos() const
{
return dynamic_cast<SingleRange<U,TYPE> const*>( IB::mRange )->get(IIB::pos());
}
template <typename U, RangeType TYPE>
SingleIndex<U,TYPE>& SingleIndex<U,TYPE>::atMeta(const U& metaPos)
{
operator=( dynamic_cast<SingleRange<U,TYPE> const*>( IB::mRange )->getMeta(metaPos) );
return *this;
}
template <typename U, RangeType TYPE>
size_t SingleIndex<U,TYPE>::dim() const
{
return 1;
}
template <typename U, RangeType TYPE>
size_t SingleIndex<U,TYPE>::evaluate(const SingleIndex<U,TYPE>& in) const
{
return in.pos();
}
template <typename U, RangeType TYPE>
void SingleIndex<U,TYPE>::copyPos(const SingleIndex<U,TYPE>& in)
{
IIB::setPos(in.pos());
}
template <typename U, RangeType TYPE>
size_t SingleIndex<U,TYPE>::giveSubStepSize(IndefinitIndexBase* subIndex)
{
if(subIndex == this){
return 1;
}
else {
return 0;
}
}
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>
void SingleIndex<U,TYPE>::eval()
{
IIB::setPos( evaluate( *this ) );
}
*/
}

View file

@ -5,6 +5,7 @@
#include <cstdlib>
#include <vector>
#include <memory>
#include "base_def.h"
#include "index_base.h"
@ -23,12 +24,10 @@ namespace MultiArrayTools
DEFAULT_MEMBERS(SingleIndex);
// find better solution !!!
SingleIndex(RangeBase<SingleIndex<U,TYPE> > const* range,
const U& upos, size_t disambig);
SingleIndex(const U& upos, std::shared_ptr<const RangeBase<SingleIndex<U,TYPE> > >& rangePtr);
SingleIndex(RangeBase<SingleIndex<U,TYPE> > const* range,
size_t pos);
SingleIndex(std::shared_ptr<const RangeBase<SingleIndex<U,TYPE> > >& rangePtr,
size_t pos = 0);
//virtual SingleIndex& operator=(const U& upos);
@ -63,10 +62,6 @@ namespace MultiArrayTools
{
public:
typedef typename RangeBase<SingleIndex<U,TYPE> >::IndexType IndexType;
DEFAULT_MEMBERS(SingleRange);
SingleRange(const std::vector<U>& space);
static SingleRange<U,TYPE> oType() { return SingleRange<U,TYPE>(); }
@ -82,6 +77,9 @@ namespace MultiArrayTools
SingleIndex<U,TYPE> end() const override;
protected:
SingleRange(const std::vector<U>& space);
std::vector<U> mSpace;
};
@ -92,10 +90,6 @@ namespace MultiArrayTools
{
public:
typedef typename RangeBase<SingleIndex<int,RangeType::SPACE> >::IndexType IndexType;
DEFAULT_MEMBERS(SingleRange);
SingleRange(size_t ext);
static SingleRange<int,RangeType::SPACE> oType() { return SingleRange<int,RangeType::SPACE>(); }
@ -110,6 +104,9 @@ namespace MultiArrayTools
SingleIndex<int,RangeType::SPACE> end() const override;
protected:
SingleRange(size_t ext);
size_t mExt;
};
@ -118,10 +115,6 @@ namespace MultiArrayTools
{
public:
typedef typename RangeBase<SingleIndex<size_t,RangeType::DISTANCE> >::IndexType IndexType;
DEFAULT_MEMBERS(SingleRange);
SingleRange(size_t ext);
static SingleRange<size_t,RangeType::DISTANCE> oType() { return SingleRange<size_t,RangeType::DISTANCE>(); }
@ -136,6 +129,9 @@ namespace MultiArrayTools
SingleIndex<size_t,RangeType::DISTANCE> end() const override;
protected:
SingleRange(size_t ext);
size_t mExt;
};
@ -144,10 +140,6 @@ namespace MultiArrayTools
{
public:
typedef typename RangeBase<SingleIndex<size_t,RangeType::ENSEMBLE> >::IndexType IndexType;
DEFAULT_MEMBERS(SingleRange);
SingleRange(size_t num);
static SingleRange<size_t,RangeType::ENSEMBLE> oType() { return SingleRange<size_t,RangeType::ENSEMBLE>(); }
@ -162,6 +154,9 @@ namespace MultiArrayTools
SingleIndex<size_t,RangeType::ENSEMBLE> end() const override;
protected:
SingleRange(size_t num);
size_t mNum;
};
@ -178,8 +173,6 @@ namespace MultiArrayTools
{
public:
typedef typename RangeBase<SingleIndex<VET,RangeType::VALUE_ERROR> >::IndexType IndexType;
DEFAULT_MEMBERS(SingleRange);
static SingleRange<VET,RangeType::VALUE_ERROR> oType()
{ return SingleRange<VET,RangeType::VALUE_ERROR>(); }
@ -200,8 +193,6 @@ namespace MultiArrayTools
{
public:
typedef typename RangeBase<SingleIndex<size_t,RangeType::LORENTZ> >::IndexType IndexType;
DEFAULT_MEMBERS(SingleRange);
static SingleRange<size_t,RangeType::LORENTZ> oType() { return SingleRange<size_t,RangeType::LORENTZ>(); }