Skip to content

Commit fda4f94

Browse files
committed
DPL: introduce the PartsRange API
1 parent 8936d29 commit fda4f94

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
@@ -668,6 +668,11 @@ class InputRecord
668668
return mPosition;
669669
}
670670

671+
[[nodiscard]] auto parts() const
672+
{
673+
return mParent->parts(mPosition);
674+
}
675+
671676
private:
672677
size_t mPosition;
673678
size_t mSize;
@@ -752,6 +757,24 @@ class InputRecord
752757
return {this, true};
753758
}
754759

760+
/// A range over the parts of a single slot that sets ref.spec on each DataRef.
761+
struct PartRange {
762+
InputRecord const* record;
763+
size_t slot;
764+
765+
[[nodiscard]] DataRefIndices initialIndices() const { return {0, 1}; }
766+
[[nodiscard]] DataRefIndices endIndices() const { return {size_t(-1), size_t(-1)}; }
767+
[[nodiscard]] DataRef getAtIndices(DataRefIndices idx) const { return record->getAtIndices((int)slot, idx); }
768+
[[nodiscard]] DataRefIndices nextIndices(DataRefIndices idx) const { return record->nextIndices((int)slot, idx); }
769+
[[nodiscard]] size_t size() const { return record->getNofParts((int)slot); }
770+
771+
[[nodiscard]] InputSpan::Iterator<PartRange, const DataRef> begin() const { return {this, size() == 0}; }
772+
[[nodiscard]] InputSpan::Iterator<PartRange, const DataRef> end() const { return {this, true}; }
773+
};
774+
775+
/// Return an iterable range over all parts in slot @a pos (DataRef objects have spec set).
776+
[[nodiscard]] PartRange parts(size_t pos) const { return {this, pos}; }
777+
755778
InputSpan& span()
756779
{
757780
return mSpan;

0 commit comments

Comments
 (0)