diff --git a/src/include/ranges/range_base.h b/src/include/ranges/range_base.h index 308f07d..8019c63 100644 --- a/src/include/ranges/range_base.h +++ b/src/include/ranges/range_base.h @@ -106,6 +106,12 @@ namespace CNORXZ */ virtual RangePtr sub(SizeT num) const; + /** Access sub-ranges. + Same as sub(), but performs domain and memory safety checks. + @param num size type argument + */ + virtual RangePtr savesub(SizeT num) const; + /** Access sub-ranges. In the case the range is multi-dimensional this function returns an array of all sub-ranges (empty is one-dimensional) diff --git a/src/lib/ranges/range_base.cc b/src/lib/ranges/range_base.cc index eb20116..c023605 100644 --- a/src/lib/ranges/range_base.cc +++ b/src/lib/ranges/range_base.cc @@ -70,6 +70,15 @@ namespace CNORXZ return nullptr; } + RangePtr RangeBase::savesub(SizeT num) const + { + CXZ_ASSERT(num < dim(), "sub-range position = " << num + << " exceeds range dimension = " << dim()); + RangePtr o = sub(num); + CXZ_ASSERT(o != nullptr, "no sub-range at position = " << num); + return o; + } + MArray RangeBase::sub() const { return MArray();