From 2d4d0b8ee90f85d8d0f138550fed1f64d26653ed Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Tue, 14 Mar 2023 19:07:05 +0100 Subject: [PATCH] change behavior of operator* for RangePtr: preserve sub-range structure --- src/include/ranges/range_base.h | 11 ++++++- src/lib/ranges/range_base.cc | 54 ++++++++++++++++++--------------- 2 files changed, 40 insertions(+), 25 deletions(-) diff --git a/src/include/ranges/range_base.h b/src/include/ranges/range_base.h index 1b91c86..cc1a5f5 100644 --- a/src/include/ranges/range_base.h +++ b/src/include/ranges/range_base.h @@ -109,8 +109,17 @@ namespace CNORXZ template Sptr rangeCast(const RangePtr r); - RangePtr operator*(const RangePtr& a, const RangePtr& b); // -> Ptr to YRange + struct RangePack + { + Vector mRs; + operator RangePtr() const; // -> Ptr to YRange + }; + + RangePack operator*(const RangePtr& a, const RangePtr& b); + RangePack operator*(const RangePtr& a, const RangePack& b); + RangePack operator*(const RangePack& a, const RangePtr& b); + RangePack operator*(const RangePack& a, const RangePack& b); } #endif diff --git a/src/lib/ranges/range_base.cc b/src/lib/ranges/range_base.cc index b17abfe..52de19f 100644 --- a/src/lib/ranges/range_base.cc +++ b/src/lib/ranges/range_base.cc @@ -96,38 +96,44 @@ namespace CNORXZ /**************************** * Non-member functions * ****************************/ + + RangePack::operator RangePtr() const + { + return YRangeFactory(mRs).create(); + } - RangePtr operator*(const RangePtr& a, const RangePtr& b) + RangePack operator*(const RangePtr& a, const RangePtr& b) { CXZ_ASSERT(a != nullptr, "first operand not initialized"); CXZ_ASSERT(b != nullptr, "second operand not initialized"); - Vector rvec; - rvec.reserve(a->dim() + b->dim()); + return RangePack { Vector { a, b } }; + //return YRangeFactory(rvec).create(); + } - if(a->sub(0) != nullptr){ - for(SizeT i = 0; i != a->dim(); ++i){ - CXZ_ASSERT(a->sub(i) != nullptr, - "sub range " << i << " of first operand not available"); - rvec.push_back(a->sub(i)); - } - } - else { - rvec.push_back(a); - } + RangePack operator*(const RangePtr& a, const RangePack& b) + { + CXZ_ASSERT(a != nullptr, "first operand not initialized"); - if(b->sub(0) != nullptr){ - for(SizeT i = 0; i != b->dim(); ++i){ - CXZ_ASSERT(b->sub(i) != nullptr, - "sub range " << i << " of second operand not available"); - rvec.push_back(b->sub(i)); - } - } - else { - rvec.push_back(b); - } + RangePack o { { a } }; + o.mRs.insert(o.mRs.end(), b.mRs.begin(), b.mRs.end()); + return o; + } - return YRangeFactory(rvec).create(); + RangePack operator*(const RangePack& a, const RangePtr& b) + { + CXZ_ASSERT(b != nullptr, "first operand not initialized"); + + RangePack o = a; + o.mRs.push_back(b); + return o; + } + + RangePack operator*(const RangePack& a, const RangePack& b) + { + RangePack o = a; + o.mRs.insert(o.mRs.end(), b.mRs.begin(), b.mRs.end()); + return o; } } // end namespace CNORXZ