From 0eb0f21031058f78e9a6f3b593b3ec3079a027b2 Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Tue, 14 Mar 2017 23:00:41 +0100 Subject: [PATCH] some fixes/corrections... --- src/index_base.h | 4 - src/multi_array.h | 2 + src/multi_array_header.h | 1 + src/multi_range.cc | 28 +++++++ src/multi_range.h | 3 + src/name.cc | 13 ++++ src/name.h | 3 + src/range_base.h | 5 +- src/single_range.cc | 162 +++++++++++++++++++++++++++++++++++++++ src/single_range.h | 87 +++++++++++++++++++++ 10 files changed, 303 insertions(+), 5 deletions(-) diff --git a/src/index_base.h b/src/index_base.h index 41e644d..680c298 100644 --- a/src/index_base.h +++ b/src/index_base.h @@ -45,11 +45,7 @@ namespace MultiArrayTools virtual void linkTo(IndefinitIndexBase* target) = 0; virtual IndefinitIndexBase* getLinked(const std::string& name) = 0; - // include sub-index update routine virtual void setPos(size_t pos); - - // does NOT include sub-index update routine !! - // relative position to current virtual void setPosRel(int relPos); virtual size_t max() const = 0; diff --git a/src/multi_array.h b/src/multi_array.h index 81dac14..6631971 100644 --- a/src/multi_array.h +++ b/src/multi_array.h @@ -24,6 +24,8 @@ namespace MultiArrayTools DEFAULT_MEMBERS(MultiArrayBase); MultiArrayBase(const Range& range); + + virtual ~MultiArrayBase() = default; virtual T& operator[](const typename Range::IndexType& i) = 0; virtual const T& operator[](const typename Range::IndexType& i) const = 0; diff --git a/src/multi_array_header.h b/src/multi_array_header.h index 8bb14cf..bcac116 100644 --- a/src/multi_array_header.h +++ b/src/multi_array_header.h @@ -42,6 +42,7 @@ namespace MultiArrayTools typedef SingleRange EnsR; typedef MultiRange Space3dNR; typedef MultiRange Mom3dNR; + typedef SingleRange ValErrR; // ... } diff --git a/src/multi_range.cc b/src/multi_range.cc index 3bb4a0e..cc1ceac 100644 --- a/src/multi_range.cc +++ b/src/multi_range.cc @@ -612,6 +612,34 @@ namespace MultiArrayTools return 0; } } + + template + struct MetaTypePrinter + { + template + static void print(std::ostream& os, typename MultiIndex::MetaType& meta) + { + MetaTypePrinter::print(os, meta); + os << std::get(meta) << '\t'; + } + }; + + template <> + struct MetaTypePrinter<0> + { + template + static void print(std::ostream& os, typename MultiIndex::MetaType& meta) + { + os << std::get<0>(meta) << '\t'; + } + }; + + template + std::ostream& operator<<(std::ostream& os, typename MultiIndex::MetaType& meta) + { + MetaTypePrinter::print(os, meta); + return os; + } /****************** * MultiRange * diff --git a/src/multi_range.h b/src/multi_range.h index 82f2ab5..722d88b 100644 --- a/src/multi_range.h +++ b/src/multi_range.h @@ -92,6 +92,9 @@ namespace MultiArrayTools //virtual void assignRange(RangeBase > const* range) override; }; + template + std::ostream& operator<<(std::ostream& os, typename MultiIndex::MetaType& meta); + /***************************** * IndexGetter Functions * ****************************/ diff --git a/src/name.cc b/src/name.cc index 8ba778d..2f3d710 100644 --- a/src/name.cc +++ b/src/name.cc @@ -66,5 +66,18 @@ namespace MultiArrayTools { 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; + } } diff --git a/src/name.h b/src/name.h index c3eb9ce..0e466de 100644 --- a/src/name.h +++ b/src/name.h @@ -5,6 +5,7 @@ #include #include +#include #include "base_def.h" @@ -33,6 +34,8 @@ namespace MultiArrayTools std::vector mSub; }; + std::ostream& operator<<(std::ostream& os, const Name& name); + } #include "name.cc" diff --git a/src/range_base.h b/src/range_base.h index e93d13c..a96c88d 100644 --- a/src/range_base.h +++ b/src/range_base.h @@ -20,7 +20,8 @@ namespace MultiArrayTools MOMENTUM = 3, LORENTZ = 4, SPIN = 5, - ENSEMBLE = 6 + ENSEMBLE = 6, + VALUE_ERROR = 7 }; class MultiRangeType @@ -58,6 +59,8 @@ namespace MultiArrayTools { public: typedef Index IndexType; + + virtual ~RangeBase() = default; virtual size_t size() const = 0; virtual Index begin() const = 0; diff --git a/src/single_range.cc b/src/single_range.cc index 6400c5b..779e97c 100644 --- a/src/single_range.cc +++ b/src/single_range.cc @@ -53,6 +53,168 @@ namespace MultiArrayTools { return SingleIndex(this, mSpace.size()); } + + // specializations + + SingleRange::SingleRange(int begin, int end) : + RangeBase >(), + mBegin(begin), mEnd(end) {} + + int SingleRange::get(size_t pos) const + { + return mBegin + pos; + } + + size_t SingleRange::getMeta(int metaPos) const + { + return metaPos - mBegin; + } + + + size_t SingleRange::size() const + { + return mEnd - mBegin; + } + + + MultiRangeType SingleRange::type() const + { + return MultiRangeType(RangeType::SPACE); + } + + + SingleIndex SingleRange::begin() const + { + return SingleIndex(this, 0); + } + + + SingleIndex SingleRange::end() const + { + return SingleIndex(this, size()); + } + + // + + + SingleRange::SingleRange(size_t num) : + RangeBase >(), + mNum(num) {} + + + size_t SingleRange::get(size_t pos) const + { + return pos; + } + + + size_t SingleRange::getMeta(size_t metaPos) const + { + return metaPos; + } + + + size_t SingleRange::size() const + { + return mNum; + } + + + MultiRangeType SingleRange::type() const + { + return MultiRangeType(RangeType::ENSEMBLE); + } + + + SingleIndex SingleRange::begin() const + { + return SingleIndex(this, 0); + } + + + SingleIndex SingleRange::end() const + { + return SingleIndex(this, size()); + } + + // + + VET SingleRange::get(size_t pos) const + { + return static_cast( pos ); + } + + + size_t SingleRange::getMeta(VET metaPos) const + { + return static_cast( metaPos ); + } + + + size_t SingleRange::size() const + { + return 2; + } + + + MultiRangeType SingleRange::type() const + { + return MultiRangeType(RangeType::VALUE_ERROR); + } + + + SingleIndex SingleRange::begin() const + { + return SingleIndex(this, 0); + } + + + SingleIndex SingleRange::end() const + { + return SingleIndex(this, size()); + } + + // + + + size_t SingleRange::get(size_t pos) const + { + return pos; + } + + + size_t SingleRange::getMeta(size_t metaPos) const + { + return metaPos; + } + + + size_t SingleRange::size() const + { + #ifdef LORENTZ_DIMENSION + return LORENTZ_DIMENSION; + #else + return 4; + #endif + } + + + MultiRangeType SingleRange::type() const + { + return MultiRangeType(RangeType::LORENTZ); + } + + + SingleIndex SingleRange::begin() const + { + return SingleIndex(this, 0); + } + + + SingleIndex SingleRange::end() const + { + return SingleIndex(this, size()); + } /****************** * SingleIndex * diff --git a/src/single_range.h b/src/single_range.h index 4ac250b..40f1e98 100644 --- a/src/single_range.h +++ b/src/single_range.h @@ -83,6 +83,93 @@ namespace MultiArrayTools std::vector mSpace; }; + // specializaions + + template <> + class SingleRange : public RangeBase > + { + 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 begin() const override; + SingleIndex end() const override; + + protected: + int mBegin; + int mEnd; + }; + + template <> + class SingleRange : public RangeBase > + { + 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 begin() const override; + SingleIndex end() const override; + + protected: + size_t mNum; + }; + + enum class VET + { + VALUE = 0, + ERROR = 1 + }; + + template <> + class SingleRange : public RangeBase > + { + 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 begin() const override; + SingleIndex end() const override; + }; + + template <> + class SingleRange : public RangeBase > + { + 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 begin() const override; + SingleIndex end() const override; + }; + } #include "single_range.cc"