some fixes/corrections...

This commit is contained in:
Christian Zimmermann 2017-03-14 23:00:41 +01:00
parent 1c55afd55f
commit 0eb0f21031
10 changed files with 303 additions and 5 deletions

View file

@ -45,11 +45,7 @@ namespace MultiArrayTools
virtual void linkTo(IndefinitIndexBase* target) = 0; virtual void linkTo(IndefinitIndexBase* target) = 0;
virtual IndefinitIndexBase* getLinked(const std::string& name) = 0; virtual IndefinitIndexBase* getLinked(const std::string& name) = 0;
// include sub-index update routine
virtual void setPos(size_t pos); virtual void setPos(size_t pos);
// does NOT include sub-index update routine !!
// relative position to current
virtual void setPosRel(int relPos); virtual void setPosRel(int relPos);
virtual size_t max() const = 0; virtual size_t max() const = 0;

View file

@ -25,6 +25,8 @@ namespace MultiArrayTools
DEFAULT_MEMBERS(MultiArrayBase); DEFAULT_MEMBERS(MultiArrayBase);
MultiArrayBase(const Range& range); MultiArrayBase(const Range& range);
virtual ~MultiArrayBase() = default;
virtual T& operator[](const typename Range::IndexType& i) = 0; virtual T& operator[](const typename Range::IndexType& i) = 0;
virtual const T& operator[](const typename Range::IndexType& i) const = 0; virtual const T& operator[](const typename Range::IndexType& i) const = 0;

View file

@ -42,6 +42,7 @@ namespace MultiArrayTools
typedef SingleRange<size_t, RangeType::ENSEMBLE> EnsR; typedef SingleRange<size_t, RangeType::ENSEMBLE> EnsR;
typedef MultiRange<Space1dNR,Space1dNR,Space1dNR> Space3dNR; typedef MultiRange<Space1dNR,Space1dNR,Space1dNR> Space3dNR;
typedef MultiRange<Mom1dNR,Mom1dNR,Mom1dNR> Mom3dNR; typedef MultiRange<Mom1dNR,Mom1dNR,Mom1dNR> Mom3dNR;
typedef SingleRange<VET, RangeType::VALUE_ERROR> ValErrR;
// ... // ...
} }

View file

@ -613,6 +613,34 @@ namespace MultiArrayTools
} }
} }
template <size_t N>
struct MetaTypePrinter
{
template <class... Indices>
static void print(std::ostream& os, typename MultiIndex<Indices...>::MetaType& meta)
{
MetaTypePrinter<N-1>::print(os, meta);
os << std::get<N>(meta) << '\t';
}
};
template <>
struct MetaTypePrinter<0>
{
template <class... Indices>
static void print(std::ostream& os, typename MultiIndex<Indices...>::MetaType& meta)
{
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 *
******************/ ******************/

View file

@ -92,6 +92,9 @@ 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 *
****************************/ ****************************/

View file

@ -67,4 +67,17 @@ 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;
}
} }

View file

@ -5,6 +5,7 @@
#include <cstdlib> #include <cstdlib>
#include <string> #include <string>
#include <ostream>
#include "base_def.h" #include "base_def.h"
@ -33,6 +34,8 @@ namespace MultiArrayTools
std::vector<Name> mSub; std::vector<Name> mSub;
}; };
std::ostream& operator<<(std::ostream& os, const Name& name);
} }
#include "name.cc" #include "name.cc"

View file

@ -20,7 +20,8 @@ namespace MultiArrayTools
MOMENTUM = 3, MOMENTUM = 3,
LORENTZ = 4, LORENTZ = 4,
SPIN = 5, SPIN = 5,
ENSEMBLE = 6 ENSEMBLE = 6,
VALUE_ERROR = 7
}; };
class MultiRangeType class MultiRangeType
@ -59,6 +60,8 @@ namespace MultiArrayTools
public: public:
typedef Index IndexType; typedef Index IndexType;
virtual ~RangeBase() = default;
virtual size_t size() const = 0; virtual size_t size() const = 0;
virtual Index begin() const = 0; virtual Index begin() const = 0;
virtual Index end() const = 0; virtual Index end() const = 0;

View file

@ -54,6 +54,168 @@ namespace MultiArrayTools
return SingleIndex<U,TYPE>(this, mSpace.size()); return SingleIndex<U,TYPE>(this, mSpace.size());
} }
// specializations
SingleRange<int,RangeType::SPACE>::SingleRange(int begin, int end) :
RangeBase<SingleIndex<int,RangeType::SPACE> >(),
mBegin(begin), mEnd(end) {}
int SingleRange<int,RangeType::SPACE>::get(size_t pos) const
{
return mBegin + pos;
}
size_t SingleRange<int,RangeType::SPACE>::getMeta(int metaPos) const
{
return metaPos - mBegin;
}
size_t SingleRange<int,RangeType::SPACE>::size() const
{
return mEnd - mBegin;
}
MultiRangeType SingleRange<int,RangeType::SPACE>::type() const
{
return MultiRangeType(RangeType::SPACE);
}
SingleIndex<int,RangeType::SPACE> SingleRange<int,RangeType::SPACE>::begin() const
{
return SingleIndex<int,RangeType::SPACE>(this, 0);
}
SingleIndex<int,RangeType::SPACE> SingleRange<int,RangeType::SPACE>::end() const
{
return SingleIndex<int,RangeType::SPACE>(this, size());
}
//
SingleRange<size_t,RangeType::ENSEMBLE>::SingleRange(size_t num) :
RangeBase<SingleIndex<size_t,RangeType::ENSEMBLE> >(),
mNum(num) {}
size_t SingleRange<size_t,RangeType::ENSEMBLE>::get(size_t pos) const
{
return pos;
}
size_t SingleRange<size_t,RangeType::ENSEMBLE>::getMeta(size_t metaPos) const
{
return metaPos;
}
size_t SingleRange<size_t,RangeType::ENSEMBLE>::size() const
{
return mNum;
}
MultiRangeType SingleRange<size_t,RangeType::ENSEMBLE>::type() const
{
return MultiRangeType(RangeType::ENSEMBLE);
}
SingleIndex<size_t,RangeType::ENSEMBLE> SingleRange<size_t,RangeType::ENSEMBLE>::begin() const
{
return SingleIndex<size_t,RangeType::ENSEMBLE>(this, 0);
}
SingleIndex<size_t,RangeType::ENSEMBLE> SingleRange<size_t,RangeType::ENSEMBLE>::end() const
{
return SingleIndex<size_t,RangeType::ENSEMBLE>(this, size());
}
//
VET SingleRange<VET,RangeType::VALUE_ERROR>::get(size_t pos) const
{
return static_cast<VET>( pos );
}
size_t SingleRange<VET,RangeType::VALUE_ERROR>::getMeta(VET metaPos) const
{
return static_cast<size_t>( metaPos );
}
size_t SingleRange<VET,RangeType::VALUE_ERROR>::size() const
{
return 2;
}
MultiRangeType SingleRange<VET,RangeType::VALUE_ERROR>::type() const
{
return MultiRangeType(RangeType::VALUE_ERROR);
}
SingleIndex<VET,RangeType::VALUE_ERROR> SingleRange<VET,RangeType::VALUE_ERROR>::begin() const
{
return SingleIndex<VET,RangeType::VALUE_ERROR>(this, 0);
}
SingleIndex<VET,RangeType::VALUE_ERROR> SingleRange<VET,RangeType::VALUE_ERROR>::end() const
{
return SingleIndex<VET,RangeType::VALUE_ERROR>(this, size());
}
//
size_t SingleRange<size_t,RangeType::LORENTZ>::get(size_t pos) const
{
return pos;
}
size_t SingleRange<size_t,RangeType::LORENTZ>::getMeta(size_t metaPos) const
{
return metaPos;
}
size_t SingleRange<size_t,RangeType::LORENTZ>::size() const
{
#ifdef LORENTZ_DIMENSION
return LORENTZ_DIMENSION;
#else
return 4;
#endif
}
MultiRangeType SingleRange<size_t,RangeType::LORENTZ>::type() const
{
return MultiRangeType(RangeType::LORENTZ);
}
SingleIndex<size_t,RangeType::LORENTZ> SingleRange<size_t,RangeType::LORENTZ>::begin() const
{
return SingleIndex<size_t,RangeType::LORENTZ>(this, 0);
}
SingleIndex<size_t,RangeType::LORENTZ> SingleRange<size_t,RangeType::LORENTZ>::end() const
{
return SingleIndex<size_t,RangeType::LORENTZ>(this, size());
}
/****************** /******************
* SingleIndex * * SingleIndex *
******************/ ******************/

View file

@ -83,6 +83,93 @@ namespace MultiArrayTools
std::vector<U> mSpace; std::vector<U> mSpace;
}; };
// specializaions
template <>
class SingleRange<int,RangeType::SPACE> : public RangeBase<SingleIndex<int,RangeType::SPACE> >
{
public:
DEFAULT_MEMBERS(SingleRange);
SingleRange(int begin, int end);
virtual size_t size() const override;
int get(size_t pos) const;
size_t getMeta(int metaPos) const;
virtual MultiRangeType type() const override;
SingleIndex<int,RangeType::SPACE> begin() const override;
SingleIndex<int,RangeType::SPACE> end() const override;
protected:
int mBegin;
int mEnd;
};
template <>
class SingleRange<size_t,RangeType::ENSEMBLE> : public RangeBase<SingleIndex<size_t,RangeType::ENSEMBLE> >
{
public:
DEFAULT_MEMBERS(SingleRange);
SingleRange(size_t num);
virtual size_t size() const override;
size_t get(size_t pos) const;
size_t getMeta(size_t metaPos) const;
virtual MultiRangeType type() const override;
SingleIndex<size_t,RangeType::ENSEMBLE> begin() const override;
SingleIndex<size_t,RangeType::ENSEMBLE> end() const override;
protected:
size_t mNum;
};
enum class VET
{
VALUE = 0,
ERROR = 1
};
template <>
class SingleRange<VET,RangeType::VALUE_ERROR> : public RangeBase<SingleIndex<VET,RangeType::VALUE_ERROR> >
{
public:
DEFAULT_MEMBERS(SingleRange);
virtual size_t size() const override;
VET get(size_t pos) const;
size_t getMeta(VET metaPos) const;
virtual MultiRangeType type() const override;
SingleIndex<VET,RangeType::VALUE_ERROR> begin() const override;
SingleIndex<VET,RangeType::VALUE_ERROR> end() const override;
};
template <>
class SingleRange<size_t,RangeType::LORENTZ> : public RangeBase<SingleIndex<size_t,RangeType::LORENTZ> >
{
public:
DEFAULT_MEMBERS(SingleRange);
virtual size_t size() const override;
size_t get(size_t pos) const;
size_t getMeta(size_t metaPos) const;
virtual MultiRangeType type() const override;
SingleIndex<size_t,RangeType::LORENTZ> begin() const override;
SingleIndex<size_t,RangeType::LORENTZ> end() const override;
};
} }
#include "single_range.cc" #include "single_range.cc"