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>
|
||||
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
|
||||
|
|
|
@ -97,37 +97,43 @@ namespace CNORXZ
|
|||
* 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(b != nullptr, "second operand not initialized");
|
||||
|
||||
Vector<RangePtr> rvec;
|
||||
rvec.reserve(a->dim() + b->dim());
|
||||
|
||||
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);
|
||||
return RangePack { Vector<RangePtr> { a, b } };
|
||||
//return YRangeFactory(rvec).create();
|
||||
}
|
||||
|
||||
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 operator*(const RangePtr& a, const RangePack& b)
|
||||
{
|
||||
CXZ_ASSERT(a != nullptr, "first operand not initialized");
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue