6#include <system/object.h>
7#include <system/object_ext.h>
8#include <system/shared_ptr.h>
9#include <system/smart_ptr.h>
10#include <system/sequence_position.h>
11#include <system/span.h>
12#include <system/memory.h>
13#include <system/array.h>
27 typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
28 RTTI_INFO_TEMPLATE_CLASS(
ThisType, ThisTypeBaseTypesInfo)
37 : m_memory(memory), m_runningIndex(0) {}
71 return m_runningIndex;
78 m_runningIndex =
value;
84 int64_t m_runningIndex;
104 if (!memory.get_IsEmpty())
106 auto segment = System::MakeObject<ReadOnlySequenceSegment<T>>(memory);
116 : _start(start), _end(end)
168 if (segment == GetSegment(_end))
176 length +=
static_cast<int64_t
>(segment->get_Memory().get_Length()) -
static_cast<int64_t
>(_start.
GetInteger());
180 length +=
static_cast<int64_t
>(segment->get_Memory().get_Length());
183 segment = segment->get_Next();
221 return segment->get_Memory().Slice(start, segment->get_Memory().get_Length() - start);
257 int64_t currentOffset =
static_cast<int64_t
>(position.
GetInteger());
258 int64_t remaining = offset;
260 int32_t segLen = segment->get_Memory().get_Length();
261 if (currentOffset + remaining < segLen)
263 position =
SequencePosition(segment,
static_cast<int32_t
>(currentOffset + remaining));
267 remaining -= (segLen - currentOffset);
268 segment = segment->get_Next();
272 segLen = segment->get_Memory().get_Length();
273 if (remaining < segLen)
279 segment = segment->get_Next();
299 if (start < 0 || length < 0 || start + length >
get_Length())
333 memory = segment->get_Memory().Slice(position.
GetInteger(), segment->get_Memory().get_Length() - position.
GetInteger());
379 return !(*
this == other);
392 return System::ExplicitCast<ReadOnlySequenceSegment<T>>(position.
GetObject());
395 SequencePosition _start;
396 SequencePosition _end;
Represents a sequence of elements that can be backed either by a single contiguous memory block or by...
Definition: read_only_sequence.h:92
SequencePosition GetPosition(int64_t offset) const
Gets the position at the specified zero-based offset from the start of the sequence.
Definition: read_only_sequence.h:234
ReadOnlySequence(const SequencePosition &start, const SequencePosition &end)
Constructs a multi-segment sequence from a range defined by a start and end position.
Definition: read_only_sequence.h:115
bool operator!=(const ReadOnlySequence &other) const
Determines whether the current sequence references a different range than the specified sequence.
Definition: read_only_sequence.h:377
ReadOnlySpan< T > get_FirstSpan() const
Gets the first memory block of the sequence as a read-only span.
Definition: read_only_sequence.h:226
int64_t get_Length() const
Gets the number of elements in the sequence.
Definition: read_only_sequence.h:152
bool operator==(const ReadOnlySequence &other) const
Determines whether the current sequence references the same range as the specified sequence.
Definition: read_only_sequence.h:369
bool Equals(const ReadOnlySequence &other) const
Determines whether the current sequence references the same range as the specified sequence.
Definition: read_only_sequence.h:354
SequencePosition GetPosition(int64_t offset, const SequencePosition &origin) const
Gets the position at the specified zero-based offset from the given origin position.
Definition: read_only_sequence.h:243
ReadOnlySequence Slice(const SequencePosition &start, const SequencePosition &end) const
Creates a slice of the sequence defined by a start and end position.
Definition: read_only_sequence.h:313
bool get_IsEmpty() const
Determines whether the sequence is empty.
Definition: read_only_sequence.h:145
static ReadOnlySequence get_Empty()
Gets the default (empty) ReadOnlySequence instance.
Definition: read_only_sequence.h:135
int32_t GetHashCode() const
Returns a hash code for the current sequence.
Definition: read_only_sequence.h:361
bool get_IsSingleSegment() const
Determines whether the sequence consists of a single contiguous memory block.
Definition: read_only_sequence.h:191
bool TryGet(SequencePosition &position, ReadOnlyMemory< T > &memory, bool advance) const
Retrieves the memory block that contains the given position.
Definition: read_only_sequence.h:325
ReadOnlySequence Slice(int64_t start) const
Creates a slice of the sequence starting at the given offset.
Definition: read_only_sequence.h:288
SequencePosition get_End() const
Gets the position one past the last element in the sequence.
Definition: read_only_sequence.h:205
ReadOnlySequence()=default
Constructs an empty ReadOnlySequence.
ReadOnlySequence(const SharedPtr< ReadOnlySequenceSegment< T > > &startSegment, int32_t startIndex, const SharedPtr< ReadOnlySequenceSegment< T > > &endSegment, int32_t endIndex)
Constructs a multi-segment sequence from a linked list of segments.
Definition: read_only_sequence.h:125
ReadOnlySequence Slice(int64_t start, int64_t length) const
Creates a slice of the sequence defined by a start and length.
Definition: read_only_sequence.h:297
SequencePosition get_Start() const
Gets the position of the first element in the sequence.
Definition: read_only_sequence.h:198
static const ReadOnlySequence Empty
The default (empty) ReadOnlySequence instance.
Definition: read_only_sequence.h:141
T value_type
The element type.
Definition: read_only_sequence.h:95
ReadOnlySequence(const ReadOnlyMemory< T > &memory)
Constructs a single-segment sequence that wraps the specified contiguous memory.
Definition: read_only_sequence.h:102
ReadOnlyMemory< T > get_First() const
Gets the first memory block of the sequence.
Definition: read_only_sequence.h:212
Represents a linked-list node that holds a single contiguous memory segment participating in a multi-...
Definition: read_only_sequence.h:23
ReadOnlySequenceSegment(const ReadOnlyMemory< T > &memory)
Constructs a segment wrapping the given memory block.
Definition: read_only_sequence.h:36
ReadOnlyMemory< T > get_Memory() const
Gets the contiguous memory held by this segment.
Definition: read_only_sequence.h:41
int64_t get_RunningIndex() const
Gets the index of the first element of this segment within the overall sequence.
Definition: read_only_sequence.h:69
void set_Memory(const ReadOnlyMemory< T > &value)
Sets the contiguous memory held by this segment.
Definition: read_only_sequence.h:48
void set_RunningIndex(int64_t value)
Sets the index of the first element of this segment within the overall sequence.
Definition: read_only_sequence.h:76
void set_Next(const SharedPtr< ReadOnlySequenceSegment< T > > &value)
Sets the next segment in the sequence.
Definition: read_only_sequence.h:62
SharedPtr< ReadOnlySequenceSegment< T > > get_Next() const
Gets the next segment in the sequence.
Definition: read_only_sequence.h:55
ReadOnlySequenceSegment()
Constructs an empty segment.
Definition: read_only_sequence.h:32
Base class that enables using methods available for System.Object class in C#. All non-trivial classe...
Definition: object.h:51
Represents a read-only memory segment backed by an array.
Definition: memory.h:237
Forward to use within Span class.
Definition: span.h:415
Represents the position of an element in a sequence. It wraps a reference to a segment object (usuall...
Definition: sequence_position.h:17
int32_t GetInteger() const noexcept
Gets the integer offset that accompanies the referenced segment.
const SharedPtr< Object > & GetObject() const noexcept
Gets the segment reference this position points into.
int32_t GetHashCode() const
Returns a hash code for the current SequencePosition.
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: smart_ptr.h:180
Definition: db_command.h:9
System::ExceptionWrapper< Details_ArgumentOutOfRangeException > ArgumentOutOfRangeException
Definition: throw_helper.h:24