CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
System::Buffers::ReadOnlySequence< T > Class Template Reference

Represents a sequence of elements that can be backed either by a single contiguous memory block or by a linked list of contiguous memory segments. More...

#include <read_only_sequence.h>

Inherits System::Details::BoxableObjectBase.

Public Types

using value_type = T
 The element type. More...
 

Public Member Functions

 ReadOnlySequence ()=default
 Constructs an empty ReadOnlySequence. More...
 
 ReadOnlySequence (const ReadOnlyMemory< T > &memory)
 Constructs a single-segment sequence that wraps the specified contiguous memory. More...
 
 ReadOnlySequence (const SequencePosition &start, const SequencePosition &end)
 Constructs a multi-segment sequence from a range defined by a start and end position. More...
 
 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. More...
 
bool get_IsEmpty () const
 Determines whether the sequence is empty. More...
 
int64_t get_Length () const
 Gets the number of elements in the sequence. More...
 
bool get_IsSingleSegment () const
 Determines whether the sequence consists of a single contiguous memory block. More...
 
SequencePosition get_Start () const
 Gets the position of the first element in the sequence. More...
 
SequencePosition get_End () const
 Gets the position one past the last element in the sequence. More...
 
ReadOnlyMemory< T > get_First () const
 Gets the first memory block of the sequence. More...
 
ReadOnlySpan< T > get_FirstSpan () const
 Gets the first memory block of the sequence as a read-only span. More...
 
SequencePosition GetPosition (int64_t offset) const
 Gets the position at the specified zero-based offset from the start of the sequence. More...
 
SequencePosition GetPosition (int64_t offset, const SequencePosition &origin) const
 Gets the position at the specified zero-based offset from the given origin position. More...
 
ReadOnlySequence Slice (int64_t start) const
 Creates a slice of the sequence starting at the given offset. More...
 
ReadOnlySequence Slice (int64_t start, int64_t length) const
 Creates a slice of the sequence defined by a start and length. More...
 
ReadOnlySequence Slice (const SequencePosition &start, const SequencePosition &end) const
 Creates a slice of the sequence defined by a start and end position. More...
 
bool TryGet (SequencePosition &position, ReadOnlyMemory< T > &memory, bool advance) const
 Retrieves the memory block that contains the given position. More...
 
bool Equals (const ReadOnlySequence &other) const
 Determines whether the current sequence references the same range as the specified sequence. More...
 
int32_t GetHashCode () const
 Returns a hash code for the current sequence. More...
 
bool operator== (const ReadOnlySequence &other) const
 Determines whether the current sequence references the same range as the specified sequence. More...
 
bool operator!= (const ReadOnlySequence &other) const
 Determines whether the current sequence references a different range than the specified sequence. More...
 

Static Public Member Functions

static ReadOnlySequence get_Empty ()
 Gets the default (empty) ReadOnlySequence instance. More...
 

Static Public Attributes

static const ReadOnlySequence Empty
 The default (empty) ReadOnlySequence instance. More...
 

Detailed Description

template<typename T>
class System::Buffers::ReadOnlySequence< T >

Represents a sequence of elements that can be backed either by a single contiguous memory block or by a linked list of contiguous memory segments.

Template Parameters
TThe type of elements in the sequence.

Member Typedef Documentation

◆ value_type

template<typename T >
using System::Buffers::ReadOnlySequence< T >::value_type = T

The element type.

Constructor & Destructor Documentation

◆ ReadOnlySequence() [1/4]

template<typename T >
System::Buffers::ReadOnlySequence< T >::ReadOnlySequence ( )
default

Constructs an empty ReadOnlySequence.

◆ ReadOnlySequence() [2/4]

template<typename T >
System::Buffers::ReadOnlySequence< T >::ReadOnlySequence ( const ReadOnlyMemory< T > &  memory)
inline

Constructs a single-segment sequence that wraps the specified contiguous memory.

Parameters
memoryThe memory block to wrap as a single-segment sequence.

◆ ReadOnlySequence() [3/4]

template<typename T >
System::Buffers::ReadOnlySequence< T >::ReadOnlySequence ( const SequencePosition &  start,
const SequencePosition &  end 
)
inline

Constructs a multi-segment sequence from a range defined by a start and end position.

Parameters
startThe position of the first element.
endThe position one past the last element.

◆ ReadOnlySequence() [4/4]

template<typename T >
System::Buffers::ReadOnlySequence< T >::ReadOnlySequence ( const SharedPtr< ReadOnlySequenceSegment< T > > &  startSegment,
int32_t  startIndex,
const SharedPtr< ReadOnlySequenceSegment< T > > &  endSegment,
int32_t  endIndex 
)
inline

Constructs a multi-segment sequence from a linked list of segments.

Parameters
startSegmentThe first segment of the sequence.
startIndexThe offset of the first element within startSegment.
endSegmentThe last segment of the sequence.
endIndexThe offset one past the last element within endSegment.

Member Function Documentation

◆ Equals()

template<typename T >
bool System::Buffers::ReadOnlySequence< T >::Equals ( const ReadOnlySequence< T > &  other) const
inline

Determines whether the current sequence references the same range as the specified sequence.

Parameters
otherThe sequence to compare with the current one.
Returns
True if both sequences represent the same start/end positions; otherwise, false.

◆ get_Empty()

template<typename T >
static ReadOnlySequence System::Buffers::ReadOnlySequence< T >::get_Empty ( )
inlinestatic

Gets the default (empty) ReadOnlySequence instance.

Returns
An empty ReadOnlySequence.

◆ get_End()

template<typename T >
SequencePosition System::Buffers::ReadOnlySequence< T >::get_End ( ) const
inline

Gets the position one past the last element in the sequence.

Returns
A SequencePosition pointing one past the last element.

◆ get_First()

template<typename T >
ReadOnlyMemory< T > System::Buffers::ReadOnlySequence< T >::get_First ( ) const
inline

Gets the first memory block of the sequence.

Returns
A ReadOnlyMemory<T> covering the first segment.

◆ get_FirstSpan()

template<typename T >
ReadOnlySpan< T > System::Buffers::ReadOnlySequence< T >::get_FirstSpan ( ) const
inline

Gets the first memory block of the sequence as a read-only span.

Returns
A ReadOnlySpan<T> covering the first segment.

◆ get_IsEmpty()

template<typename T >
bool System::Buffers::ReadOnlySequence< T >::get_IsEmpty ( ) const
inline

Determines whether the sequence is empty.

Returns
True if the sequence has no elements; otherwise, false.

◆ get_IsSingleSegment()

template<typename T >
bool System::Buffers::ReadOnlySequence< T >::get_IsSingleSegment ( ) const
inline

Determines whether the sequence consists of a single contiguous memory block.

Returns
True if the sequence is backed by a single segment; otherwise, false.

◆ get_Length()

template<typename T >
int64_t System::Buffers::ReadOnlySequence< T >::get_Length ( ) const
inline

Gets the number of elements in the sequence.

Returns
The total element count.

◆ get_Start()

template<typename T >
SequencePosition System::Buffers::ReadOnlySequence< T >::get_Start ( ) const
inline

Gets the position of the first element in the sequence.

Returns
A SequencePosition pointing to the first element.

◆ GetHashCode()

template<typename T >
int32_t System::Buffers::ReadOnlySequence< T >::GetHashCode ( ) const
inline

Returns a hash code for the current sequence.

Returns
A hash code based on the start and end positions.

◆ GetPosition() [1/2]

template<typename T >
SequencePosition System::Buffers::ReadOnlySequence< T >::GetPosition ( int64_t  offset) const
inline

Gets the position at the specified zero-based offset from the start of the sequence.

Parameters
offsetThe number of elements to advance.
Returns
The resulting SequencePosition.

◆ GetPosition() [2/2]

template<typename T >
SequencePosition System::Buffers::ReadOnlySequence< T >::GetPosition ( int64_t  offset,
const SequencePosition &  origin 
) const
inline

Gets the position at the specified zero-based offset from the given origin position.

Parameters
offsetThe number of elements to advance.
originThe position from which the offset is measured.
Returns
The resulting SequencePosition.

◆ operator!=()

template<typename T >
bool System::Buffers::ReadOnlySequence< T >::operator!= ( const ReadOnlySequence< T > &  other) const
inline

Determines whether the current sequence references a different range than the specified sequence.

Parameters
otherThe sequence to compare with the current one.
Returns
True if the sequences are not equal; otherwise, false.

◆ operator==()

template<typename T >
bool System::Buffers::ReadOnlySequence< T >::operator== ( const ReadOnlySequence< T > &  other) const
inline

Determines whether the current sequence references the same range as the specified sequence.

Parameters
otherThe sequence to compare with the current one.
Returns
True if both sequences represent the same start/end positions; otherwise, false.

◆ Slice() [1/3]

template<typename T >
ReadOnlySequence System::Buffers::ReadOnlySequence< T >::Slice ( const SequencePosition &  start,
const SequencePosition &  end 
) const
inline

Creates a slice of the sequence defined by a start and end position.

Parameters
startThe position of the first element of the slice.
endThe position one past the last element of the slice.
Returns
A ReadOnlySequence representing the requested sub-range.

◆ Slice() [2/3]

template<typename T >
ReadOnlySequence System::Buffers::ReadOnlySequence< T >::Slice ( int64_t  start) const
inline

Creates a slice of the sequence starting at the given offset.

Parameters
startThe offset of the first element of the slice.
Returns
A ReadOnlySequence representing the requested sub-range.

◆ Slice() [3/3]

template<typename T >
ReadOnlySequence System::Buffers::ReadOnlySequence< T >::Slice ( int64_t  start,
int64_t  length 
) const
inline

Creates a slice of the sequence defined by a start and length.

Parameters
startThe offset of the first element of the slice.
lengthThe number of elements in the slice.
Returns
A ReadOnlySequence representing the requested sub-range.

◆ TryGet()

template<typename T >
bool System::Buffers::ReadOnlySequence< T >::TryGet ( SequencePosition &  position,
ReadOnlyMemory< T > &  memory,
bool  advance 
) const
inline

Retrieves the memory block that contains the given position.

Parameters
positionOn input, a position identifying a segment. On output, updated to the position of the first element of the next segment (if advance is true), or left at the end of the returned memory otherwise.
memoryWhen this method returns, contains the memory block starting at the given position.
advanceTrue to advance the position to the next segment after reading.
Returns
True if a segment was found and memory was populated; otherwise, false.

Member Data Documentation

◆ Empty

template<typename T >
const ReadOnlySequence< T > System::Buffers::ReadOnlySequence< T >::Empty
static

The default (empty) ReadOnlySequence instance.

Definition of the static empty sequence member.