Skip to content

Commit fa8a0f7

Browse files
committed
DPL: introduce the PartsRange API
1 parent af08c7a commit fa8a0f7

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

Framework/Core/include/Framework/InputRecord.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,11 @@ class InputRecord
687687
return mPosition;
688688
}
689689

690+
[[nodiscard]] auto parts() const
691+
{
692+
return mParent->parts(mPosition);
693+
}
694+
690695
private:
691696
size_t mPosition;
692697
size_t mSize;
@@ -771,6 +776,24 @@ class InputRecord
771776
return {this, true};
772777
}
773778

779+
/// A range over the parts of a single slot that sets ref.spec on each DataRef.
780+
struct PartRange {
781+
InputRecord const* record;
782+
size_t slot;
783+
784+
[[nodiscard]] DataRefIndices initialIndices() const { return {0, 1}; }
785+
[[nodiscard]] DataRefIndices endIndices() const { return {size_t(-1), size_t(-1)}; }
786+
[[nodiscard]] DataRef getAtIndices(DataRefIndices idx) const { return record->getAtIndices((int)slot, idx); }
787+
[[nodiscard]] DataRefIndices nextIndices(DataRefIndices idx) const { return record->nextIndices((int)slot, idx); }
788+
[[nodiscard]] size_t size() const { return record->getNofParts((int)slot); }
789+
790+
[[nodiscard]] InputSpan::Iterator<PartRange, const DataRef> begin() const { return {this, size() == 0}; }
791+
[[nodiscard]] InputSpan::Iterator<PartRange, const DataRef> end() const { return {this, true}; }
792+
};
793+
794+
/// Return an iterable range over all parts in slot @a pos (DataRef objects have spec set).
795+
[[nodiscard]] PartRange parts(size_t pos) const { return {this, pos}; }
796+
774797
InputSpan& span()
775798
{
776799
return mSpan;

0 commit comments

Comments
 (0)