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

@ -96,11 +96,6 @@ namespace MultiArrayTools
typedef typename RangeBase<MultiIndex<typename Ranges::IndexType...> >::IndexType typedef typename RangeBase<MultiIndex<typename Ranges::IndexType...> >::IndexType
IndexType; IndexType;
DEFAULT_MEMBERS(MultiRange);
MultiRange(const std::shared_ptr<Ranges>&... rs);
MultiRange(const SpaceType& space);
static const size_t dim = sizeof...(Ranges); static const size_t dim = sizeof...(Ranges);
template <size_t N> // !!! return ref to range, not the corresp. shared ptr 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; virtual std::shared_ptr<IndefinitIndexBase> indexInstance() const override;
protected: 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; SpaceType mSpace;
}; };

View file

@ -87,6 +87,7 @@ namespace MultiArrayTools
mType = RangeType::NIL; mType = RangeType::NIL;
} }
/****************** /******************
* RangeBase * * RangeBase *
******************/ ******************/

View file

@ -61,12 +61,17 @@ namespace MultiArrayTools
virtual ~IndefinitRangeBase() = default; virtual ~IndefinitRangeBase() = default;
static std::shared_ptr<IndefinitRangeBase> makeInstance(const MultiRangeType& mrt); // !!!
virtual size_t size() const = 0; virtual size_t size() const = 0;
virtual bool isSubRange() const = 0; virtual bool isSubRange() const = 0;
virtual MultiRangeType type() const = 0; virtual MultiRangeType type() const = 0;
virtual std::shared_ptr<IndefinitIndexBase> indexInstance() 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> template <class Index>
@ -81,6 +86,11 @@ namespace MultiArrayTools
virtual bool isSubRange() const override; virtual bool isSubRange() const override;
virtual std::shared_ptr<IndefinitIndexBase> indexInstance() 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> //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 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 * * SingleRange *
********************/ ********************/
@ -251,130 +379,4 @@ namespace MultiArrayTools
return SingleIndex<size_t,RangeType::LORENTZ>(this, size()); 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 <cstdlib>
#include <vector> #include <vector>
#include <memory>
#include "base_def.h" #include "base_def.h"
#include "index_base.h" #include "index_base.h"
@ -23,12 +24,10 @@ namespace MultiArrayTools
DEFAULT_MEMBERS(SingleIndex); DEFAULT_MEMBERS(SingleIndex);
// find better solution !!! SingleIndex(const U& upos, std::shared_ptr<const RangeBase<SingleIndex<U,TYPE> > >& rangePtr);
SingleIndex(RangeBase<SingleIndex<U,TYPE> > const* range,
const U& upos, size_t disambig);
SingleIndex(RangeBase<SingleIndex<U,TYPE> > const* range, SingleIndex(std::shared_ptr<const RangeBase<SingleIndex<U,TYPE> > >& rangePtr,
size_t pos); size_t pos = 0);
//virtual SingleIndex& operator=(const U& upos); //virtual SingleIndex& operator=(const U& upos);
@ -64,10 +63,6 @@ namespace MultiArrayTools
public: public:
typedef typename RangeBase<SingleIndex<U,TYPE> >::IndexType IndexType; 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>(); } static SingleRange<U,TYPE> oType() { return SingleRange<U,TYPE>(); }
virtual size_t size() const override; virtual size_t size() const override;
@ -82,6 +77,9 @@ namespace MultiArrayTools
SingleIndex<U,TYPE> end() const override; SingleIndex<U,TYPE> end() const override;
protected: protected:
SingleRange(const std::vector<U>& space);
std::vector<U> mSpace; std::vector<U> mSpace;
}; };
@ -93,10 +91,6 @@ namespace MultiArrayTools
public: public:
typedef typename RangeBase<SingleIndex<int,RangeType::SPACE> >::IndexType IndexType; 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>(); } static SingleRange<int,RangeType::SPACE> oType() { return SingleRange<int,RangeType::SPACE>(); }
virtual size_t size() const override; virtual size_t size() const override;
@ -110,6 +104,9 @@ namespace MultiArrayTools
SingleIndex<int,RangeType::SPACE> end() const override; SingleIndex<int,RangeType::SPACE> end() const override;
protected: protected:
SingleRange(size_t ext);
size_t mExt; size_t mExt;
}; };
@ -119,10 +116,6 @@ namespace MultiArrayTools
public: public:
typedef typename RangeBase<SingleIndex<size_t,RangeType::DISTANCE> >::IndexType IndexType; 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>(); } static SingleRange<size_t,RangeType::DISTANCE> oType() { return SingleRange<size_t,RangeType::DISTANCE>(); }
virtual size_t size() const override; virtual size_t size() const override;
@ -136,6 +129,9 @@ namespace MultiArrayTools
SingleIndex<size_t,RangeType::DISTANCE> end() const override; SingleIndex<size_t,RangeType::DISTANCE> end() const override;
protected: protected:
SingleRange(size_t ext);
size_t mExt; size_t mExt;
}; };
@ -145,10 +141,6 @@ namespace MultiArrayTools
public: public:
typedef typename RangeBase<SingleIndex<size_t,RangeType::ENSEMBLE> >::IndexType IndexType; 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>(); } static SingleRange<size_t,RangeType::ENSEMBLE> oType() { return SingleRange<size_t,RangeType::ENSEMBLE>(); }
virtual size_t size() const override; virtual size_t size() const override;
@ -162,6 +154,9 @@ namespace MultiArrayTools
SingleIndex<size_t,RangeType::ENSEMBLE> end() const override; SingleIndex<size_t,RangeType::ENSEMBLE> end() const override;
protected: protected:
SingleRange(size_t num);
size_t mNum; size_t mNum;
}; };
@ -179,8 +174,6 @@ namespace MultiArrayTools
public: public:
typedef typename RangeBase<SingleIndex<VET,RangeType::VALUE_ERROR> >::IndexType IndexType; typedef typename RangeBase<SingleIndex<VET,RangeType::VALUE_ERROR> >::IndexType IndexType;
DEFAULT_MEMBERS(SingleRange);
static SingleRange<VET,RangeType::VALUE_ERROR> oType() static SingleRange<VET,RangeType::VALUE_ERROR> oType()
{ return SingleRange<VET,RangeType::VALUE_ERROR>(); } { return SingleRange<VET,RangeType::VALUE_ERROR>(); }
@ -201,8 +194,6 @@ namespace MultiArrayTools
public: public:
typedef typename RangeBase<SingleIndex<size_t,RangeType::LORENTZ> >::IndexType IndexType; 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>(); } static SingleRange<size_t,RangeType::LORENTZ> oType() { return SingleRange<size_t,RangeType::LORENTZ>(); }
virtual size_t size() const override; virtual size_t size() const override;