ranges: getMeta(): return size when out of scope (no throw)
This commit is contained in:
parent
c1acda90f0
commit
dc2c239650
6 changed files with 18 additions and 7 deletions
|
@ -185,7 +185,8 @@ namespace CNORXZ
|
||||||
*/
|
*/
|
||||||
SizeT get(SizeT pos) const;
|
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
|
@param metaPos meta data, size type
|
||||||
*/
|
*/
|
||||||
SizeT getMeta(SizeT metaPos) const;
|
SizeT getMeta(SizeT metaPos) const;
|
||||||
|
|
|
@ -299,8 +299,12 @@ namespace CNORXZ
|
||||||
auto b = mSpace.begin();
|
auto b = mSpace.begin();
|
||||||
auto e = mSpace.end();
|
auto e = mSpace.end();
|
||||||
auto i = std::lower_bound(b, e, meta, std::less<MetaT>());
|
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!
|
if(i == e){
|
||||||
CXZ_ASSERT(*i == meta, "element with meta data = " << toString(meta) << " not in range");
|
return size();
|
||||||
|
}
|
||||||
|
if(*i != meta){
|
||||||
|
return size();
|
||||||
|
}
|
||||||
return i - b;
|
return i - b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -197,6 +197,7 @@ namespace CNORXZ
|
||||||
const MetaType* get() const;
|
const MetaType* get() const;
|
||||||
|
|
||||||
/** Get range position for given meta data.
|
/** Get range position for given meta data.
|
||||||
|
Returns size() if metaPos is not part of the range.
|
||||||
@param metaPos Meta data.
|
@param metaPos Meta data.
|
||||||
@return Position of the given meta data if it is contained by the range.
|
@return Position of the given meta data if it is contained by the range.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -115,7 +115,7 @@ namespace CNORXZ
|
||||||
|
|
||||||
CIndex& CIndex::at(const SizeT& metaPos)
|
CIndex& CIndex::at(const SizeT& metaPos)
|
||||||
{
|
{
|
||||||
IB::mPos = metaPos;
|
IB::mPos = metaPos < lmax().val() ? metaPos : lmax().val();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,6 +204,9 @@ namespace CNORXZ
|
||||||
|
|
||||||
SizeT CRange::getMeta(SizeT metaPos) const
|
SizeT CRange::getMeta(SizeT metaPos) const
|
||||||
{
|
{
|
||||||
|
if(metaPos >= size()){
|
||||||
|
return size();
|
||||||
|
}
|
||||||
return metaPos;
|
return metaPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -93,6 +93,7 @@ namespace CNORXZ
|
||||||
const String next = name.substr(delimpos+1);
|
const String next = name.substr(delimpos+1);
|
||||||
auto g = getGroup(thisname);
|
auto g = getGroup(thisname);
|
||||||
g->open();
|
g->open();
|
||||||
|
CHECK;
|
||||||
return g->get(next);
|
return g->get(next);
|
||||||
}
|
}
|
||||||
auto i = this->getIndexTo(thisname);
|
auto i = this->getIndexTo(thisname);
|
||||||
|
@ -101,7 +102,7 @@ namespace CNORXZ
|
||||||
|
|
||||||
Sptr<Group> Group::getGroup(const String& name) const
|
Sptr<Group> Group::getGroup(const String& name) const
|
||||||
{
|
{
|
||||||
auto group = this->get(name);
|
ContentPtr group = this->get(name);
|
||||||
CXZ_ASSERT(group->type() == ContentType::GROUP,
|
CXZ_ASSERT(group->type() == ContentType::GROUP,
|
||||||
"element '" << name << "' is not of type GROUP");
|
"element '" << name << "' is not of type GROUP");
|
||||||
return std::dynamic_pointer_cast<Group>( 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 dvec = [](const String& n) { return Vector<DType>({DType(n)}); };
|
||||||
auto i = mCont.begin();
|
auto i = mCont.begin();
|
||||||
i.at(dvec(name));
|
i.at(dvec(name));
|
||||||
|
CXZ_ASSERT(i != mCont.end(), "no element '" << name << "' in group " << path());
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -245,6 +247,7 @@ namespace CNORXZ
|
||||||
auto dvec = [](const String& n) { return Vector<DType>({DType(n)}); };
|
auto dvec = [](const String& n) { return Vector<DType>({DType(n)}); };
|
||||||
auto i = mCont.begin();
|
auto i = mCont.begin();
|
||||||
i.at(dvec(name));
|
i.at(dvec(name));
|
||||||
|
CXZ_ASSERT(i != mCont.end(), "no element '" << name << "' in group " << path());
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -274,8 +274,7 @@ namespace CNORXZ
|
||||||
template <class IndexI, class IndexK>
|
template <class IndexI, class IndexK>
|
||||||
decltype(auto) RIndex<IndexI,IndexK>::xpr(const Sptr<RIndex<IndexI,IndexK>>& _this) const
|
decltype(auto) RIndex<IndexI,IndexK>::xpr(const Sptr<RIndex<IndexI,IndexK>>& _this) const
|
||||||
{
|
{
|
||||||
CXZ_ERROR("not implemented");
|
return _this->local()->xpr( _this->local() );
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class IndexI, class IndexK>
|
template <class IndexI, class IndexK>
|
||||||
|
|
Loading…
Reference in a new issue