ranges: getMeta(): return size when out of scope (no throw)

This commit is contained in:
Christian Zimmermann 2024-03-22 00:26:58 +01:00
parent c1acda90f0
commit dc2c239650
6 changed files with 18 additions and 7 deletions

View file

@ -185,7 +185,8 @@ namespace CNORXZ
*/
SizeT get(SizeT pos) const;
/** return position for given meta data
/** return position for given meta data.
Returns size() if metaPos is out of scope.
@param metaPos meta data, size type
*/
SizeT getMeta(SizeT metaPos) const;

View file

@ -299,8 +299,12 @@ namespace CNORXZ
auto b = mSpace.begin();
auto e = mSpace.end();
auto i = std::lower_bound(b, e, meta, std::less<MetaT>());
CXZ_ASSERT(i != e, "element with meta data = " << toString(meta) << " not in range"); // check this first, otherwise the next test may potentially result in a seg fault!
CXZ_ASSERT(*i == meta, "element with meta data = " << toString(meta) << " not in range");
if(i == e){
return size();
}
if(*i != meta){
return size();
}
return i - b;
}

View file

@ -197,6 +197,7 @@ namespace CNORXZ
const MetaType* get() const;
/** Get range position for given meta data.
Returns size() if metaPos is not part of the range.
@param metaPos Meta data.
@return Position of the given meta data if it is contained by the range.
*/

View file

@ -115,7 +115,7 @@ namespace CNORXZ
CIndex& CIndex::at(const SizeT& metaPos)
{
IB::mPos = metaPos;
IB::mPos = metaPos < lmax().val() ? metaPos : lmax().val();
return *this;
}
@ -204,6 +204,9 @@ namespace CNORXZ
SizeT CRange::getMeta(SizeT metaPos) const
{
if(metaPos >= size()){
return size();
}
return metaPos;
}

View file

@ -93,6 +93,7 @@ namespace CNORXZ
const String next = name.substr(delimpos+1);
auto g = getGroup(thisname);
g->open();
CHECK;
return g->get(next);
}
auto i = this->getIndexTo(thisname);
@ -101,7 +102,7 @@ namespace CNORXZ
Sptr<Group> Group::getGroup(const String& name) const
{
auto group = this->get(name);
ContentPtr group = this->get(name);
CXZ_ASSERT(group->type() == ContentType::GROUP,
"element '" << name << "' is not of type GROUP");
return std::dynamic_pointer_cast<Group>( group );
@ -236,6 +237,7 @@ namespace CNORXZ
auto dvec = [](const String& n) { return Vector<DType>({DType(n)}); };
auto i = mCont.begin();
i.at(dvec(name));
CXZ_ASSERT(i != mCont.end(), "no element '" << name << "' in group " << path());
return i;
}
@ -245,6 +247,7 @@ namespace CNORXZ
auto dvec = [](const String& n) { return Vector<DType>({DType(n)}); };
auto i = mCont.begin();
i.at(dvec(name));
CXZ_ASSERT(i != mCont.end(), "no element '" << name << "' in group " << path());
return i;
}

View file

@ -274,8 +274,7 @@ namespace CNORXZ
template <class IndexI, class IndexK>
decltype(auto) RIndex<IndexI,IndexK>::xpr(const Sptr<RIndex<IndexI,IndexK>>& _this) const
{
CXZ_ERROR("not implemented");
return 0;
return _this->local()->xpr( _this->local() );
}
template <class IndexI, class IndexK>