From 215c2c4f554d2b8d30230a300ee6862783476dcf Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Tue, 11 Jun 2024 13:50:14 +0200 Subject: [PATCH] range base: add savesub function --- src/include/ranges/range_base.h | 6 ++++++ src/lib/ranges/range_base.cc | 9 +++++++++ 2 files changed, 15 insertions(+) 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();