change behavior of operator* for RangePtr: preserve sub-range structure
This commit is contained in:
parent
1d6f8dc52b
commit
2d4d0b8ee9
2 changed files with 40 additions and 25 deletions
|
@ -109,8 +109,17 @@ namespace CNORXZ
|
||||||
template <class Range>
|
template <class Range>
|
||||||
Sptr<Range> rangeCast(const RangePtr r);
|
Sptr<Range> rangeCast(const RangePtr r);
|
||||||
|
|
||||||
RangePtr operator*(const RangePtr& a, const RangePtr& b); // -> Ptr to YRange
|
|
||||||
|
|
||||||
|
struct RangePack
|
||||||
|
{
|
||||||
|
Vector<RangePtr> 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
|
#endif
|
||||||
|
|
|
@ -97,37 +97,43 @@ namespace CNORXZ
|
||||||
* Non-member functions *
|
* Non-member functions *
|
||||||
****************************/
|
****************************/
|
||||||
|
|
||||||
RangePtr operator*(const RangePtr& a, const RangePtr& b)
|
RangePack::operator RangePtr() const
|
||||||
|
{
|
||||||
|
return YRangeFactory(mRs).create();
|
||||||
|
}
|
||||||
|
|
||||||
|
RangePack operator*(const RangePtr& a, const RangePtr& b)
|
||||||
{
|
{
|
||||||
CXZ_ASSERT(a != nullptr, "first operand not initialized");
|
CXZ_ASSERT(a != nullptr, "first operand not initialized");
|
||||||
CXZ_ASSERT(b != nullptr, "second operand not initialized");
|
CXZ_ASSERT(b != nullptr, "second operand not initialized");
|
||||||
|
|
||||||
Vector<RangePtr> rvec;
|
return RangePack { Vector<RangePtr> { a, b } };
|
||||||
rvec.reserve(a->dim() + b->dim());
|
//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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(b->sub(0) != nullptr){
|
RangePack operator*(const RangePtr& a, const RangePack& b)
|
||||||
for(SizeT i = 0; i != b->dim(); ++i){
|
{
|
||||||
CXZ_ASSERT(b->sub(i) != nullptr,
|
CXZ_ASSERT(a != nullptr, "first operand not initialized");
|
||||||
"sub range " << i << " of second operand not available");
|
|
||||||
rvec.push_back(b->sub(i));
|
RangePack o { { a } };
|
||||||
}
|
o.mRs.insert(o.mRs.end(), b.mRs.begin(), b.mRs.end());
|
||||||
}
|
return o;
|
||||||
else {
|
|
||||||
rvec.push_back(b);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
} // end namespace CNORXZ
|
||||||
|
|
Loading…
Reference in a new issue