Open CASCADE Technology Reference Manual 8.0.0
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions
NCollection_LinearVector< TheItemType > Class Template Reference

Contiguous dynamic array using a flat memory buffer. More...

#include <NCollection_LinearVector.hxx>

Public Types

using value_type = TheItemType
 
using size_type = size_t
 
using pointer = TheItemType*
 
using const_pointer = const TheItemType*
 
using reference = TheItemType&
 
using const_reference = const TheItemType&
 
using iterator = TheItemType*
 
using const_iterator = const TheItemType*
 
using allocator_type = NCollection_Allocator<TheItemType>
 

Public Member Functions

 NCollection_LinearVector () noexcept=default
 Empty constructor.
 
 NCollection_LinearVector (const size_t theCapacity)
 Constructor with pre-allocated capacity. Unlike std::vector(n), this constructor does not create elements. Use Resize() or NCollection_LinearVector(theSize, theValue) to construct items.
 
 NCollection_LinearVector (const size_t theSize, const TheItemType &theValue)
 Constructor creating theSize elements initialized to theValue. Equivalent to std::vector(n, val).
 
 NCollection_LinearVector (const NCollection_LinearVector &theOther)
 Copy constructor.
 
 NCollection_LinearVector (NCollection_LinearVector &&theOther) noexcept
 Move constructor.
 
 ~NCollection_LinearVector ()
 Destructor.
 
NCollection_LinearVectoroperator= (const NCollection_LinearVector &theOther)
 Copy assignment.
 
NCollection_LinearVectoroperator= (NCollection_LinearVector &&theOther) noexcept
 Move assignment.
 
TheItemTypeData () noexcept
 
const TheItemTypeData () const noexcept
 
bool HasData () const noexcept
 
bool Empty () const noexcept
 
size_t Size () const noexcept
 
bool IsEmpty () const noexcept
 
size_t Capacity () const noexcept
 
void Reserve (const size_t theCapacity)
 Pre-allocate memory for at least theCapacity elements without changing size.
 
void Resize (const size_t theSize)
 Change the number of elements. If theSize > Size(), new elements are default-constructed. If theSize < Size(), excess elements are destroyed.
 
void Resize (const size_t theSize, const TheItemType &theValue)
 Change the number of elements, filling new slots with theValue. If theSize > Size(), new elements are copy-constructed from theValue. If theSize < Size(), excess elements are destroyed.
 
const TheItemTypeValue (const size_t theIndex) const
 
TheItemTypeChangeValue (const size_t theIndex)
 
const TheItemTypeoperator() (const size_t theIndex) const
 
TheItemTypeoperator() (const size_t theIndex)
 
const TheItemTypeoperator[] (const size_t theIndex) const
 
TheItemTypeoperator[] (const size_t theIndex)
 
const TheItemTypeFirst () const
 
TheItemTypeChangeFirst ()
 
const TheItemTypeLast () const
 
TheItemTypeChangeLast ()
 
TheItemTypeAppend (const TheItemType &theValue)
 Append a copy of theValue to the end.
 
TheItemTypeAppend (TheItemType &&theValue)
 Append theValue by move to the end.
 
TheItemTypeAppended ()
 Append a default-constructed element.
 
template<class... Args>
TheItemTypeEmplaceAppend (Args &&... theArgs)
 Append an element constructed in-place with the given arguments.
 
TheItemTypeSetValue (const size_t theIndex, const TheItemType &theValue)
 Set value at theIndex. If theIndex >= Size(), the vector is extended.
 
TheItemTypeSetValue (const size_t theIndex, TheItemType &&theValue)
 Set value at theIndex by move. If theIndex >= Size(), the vector is extended.
 
void InsertBefore (const size_t theIndex, const TheItemType &theValue)
 Insert theValue before theIndex, shifting elements right.
 
void InsertAfter (const size_t theIndex, const TheItemType &theValue)
 Insert theValue after theIndex, shifting elements right.
 
void InsertBefore (const size_t theIndex, TheItemType &&theValue)
 Insert theValue before theIndex, shifting elements right.
 
void InsertAfter (const size_t theIndex, TheItemType &&theValue)
 Insert theValue after theIndex, shifting elements right.
 
void EraseLast ()
 Remove the last element.
 
void Erase (const size_t theIndex)
 Remove element at theIndex, shifting subsequent elements left.
 
void Erase (const size_t theFrom, const size_t theTo)
 Remove elements in range [theFrom, theTo), shifting subsequent elements left.
 
void Clear (const bool theReleaseMemory=false)
 Remove all elements.
 
iterator begin () noexcept
 
iterator end () noexcept
 
const_iterator begin () const noexcept
 
const_iterator end () const noexcept
 
const_iterator cbegin () const noexcept
 
const_iterator cend () const noexcept
 

Static Public Member Functions

static constexpr size_t MaxSize () noexcept
 

Detailed Description

template<typename TheItemType>
class NCollection_LinearVector< TheItemType >

Contiguous dynamic array using a flat memory buffer.

Unlike NCollection_DynamicArray which uses segmented block storage, this container stores all elements in a single contiguous allocation, providing O(1) element access with a single pointer dereference.

For trivially copyable types, growth uses Standard::Reallocate which can extend the buffer in-place without copying elements. For non-trivial types, growth allocates a new buffer and move-constructs elements.

Indices are always 0-based.

Warning
Any operation that may grow the buffer - Append, Appended, EmplaceAppend, SetValue past end, Resize, Reserve, InsertBefore, InsertAfter, copy/move assignment - invalidates all iterators, references, and raw pointers into the vector whenever it actually reallocates. Erase/EraseLast also invalidate references at or beyond the removed position.

Member Typedef Documentation

◆ allocator_type

◆ const_iterator

◆ const_pointer

◆ const_reference

template<typename TheItemType >
using NCollection_LinearVector< TheItemType >::const_reference = const TheItemType&

◆ iterator

◆ pointer

◆ reference

◆ size_type

◆ value_type

Constructor & Destructor Documentation

◆ NCollection_LinearVector() [1/5]

Empty constructor.

◆ NCollection_LinearVector() [2/5]

Constructor with pre-allocated capacity. Unlike std::vector(n), this constructor does not create elements. Use Resize() or NCollection_LinearVector(theSize, theValue) to construct items.

Parameters
[in]theCapacitynumber of elements to pre-allocate

◆ NCollection_LinearVector() [3/5]

template<typename TheItemType >
NCollection_LinearVector< TheItemType >::NCollection_LinearVector ( const size_t theSize,
const TheItemType & theValue )
inline

Constructor creating theSize elements initialized to theValue. Equivalent to std::vector(n, val).

Parameters
[in]theSizenumber of elements to construct
[in]theValuevalue to initialize each element with

◆ NCollection_LinearVector() [4/5]

Copy constructor.

◆ NCollection_LinearVector() [5/5]

Move constructor.

◆ ~NCollection_LinearVector()

Destructor.

Member Function Documentation

◆ Append() [1/2]

template<typename TheItemType >
TheItemType & NCollection_LinearVector< TheItemType >::Append ( const TheItemType & theValue)
inline

Append a copy of theValue to the end.

Parameters
[in]theValueelement to append
Returns
reference to the appended element

◆ Append() [2/2]

template<typename TheItemType >
TheItemType & NCollection_LinearVector< TheItemType >::Append ( TheItemType && theValue)
inline

Append theValue by move to the end.

Parameters
[in]theValueelement to move-append
Returns
reference to the appended element

◆ Appended()

Append a default-constructed element.

Returns
reference to the appended element

◆ begin() [1/2]

template<typename TheItemType >
const_iterator NCollection_LinearVector< TheItemType >::begin ( ) const
inlinenoexcept
Returns
const iterator to the first element.

◆ begin() [2/2]

template<typename TheItemType >
iterator NCollection_LinearVector< TheItemType >::begin ( )
inlinenoexcept
Returns
iterator to the first element.

◆ Capacity()

template<typename TheItemType >
size_t NCollection_LinearVector< TheItemType >::Capacity ( ) const
inlinenoexcept
Returns
current allocated capacity.

◆ cbegin()

template<typename TheItemType >
const_iterator NCollection_LinearVector< TheItemType >::cbegin ( ) const
inlinenoexcept
Returns
const iterator to the first element.

◆ cend()

template<typename TheItemType >
const_iterator NCollection_LinearVector< TheItemType >::cend ( ) const
inlinenoexcept
Returns
const iterator past the last element.

◆ ChangeFirst()

template<typename TheItemType >
TheItemType & NCollection_LinearVector< TheItemType >::ChangeFirst ( )
inline
Returns
mutable reference to the first element.

◆ ChangeLast()

template<typename TheItemType >
TheItemType & NCollection_LinearVector< TheItemType >::ChangeLast ( )
inline
Returns
mutable reference to the last element.

◆ ChangeValue()

template<typename TheItemType >
TheItemType & NCollection_LinearVector< TheItemType >::ChangeValue ( const size_t theIndex)
inline
Returns
mutable reference to element at theIndex.
Parameters
[in]theIndexelement index (0-based)

◆ Clear()

template<typename TheItemType >
void NCollection_LinearVector< TheItemType >::Clear ( const bool theReleaseMemory = false)
inline

Remove all elements.

Parameters
[in]theReleaseMemoryif true, deallocate the buffer

◆ Data() [1/2]

template<typename TheItemType >
const TheItemType * NCollection_LinearVector< TheItemType >::Data ( ) const
inlinenoexcept
Returns
raw data pointer.

◆ Data() [2/2]

template<typename TheItemType >
TheItemType * NCollection_LinearVector< TheItemType >::Data ( )
inlinenoexcept
Returns
raw data pointer.

◆ EmplaceAppend()

template<typename TheItemType >
template<class... Args>
TheItemType & NCollection_LinearVector< TheItemType >::EmplaceAppend ( Args &&... theArgs)
inline

Append an element constructed in-place with the given arguments.

Parameters
[in]theArgsconstructor arguments
Returns
reference to the appended element

◆ Empty()

template<typename TheItemType >
bool NCollection_LinearVector< TheItemType >::Empty ( ) const
inlinenoexcept
Returns
true if the vector contains no elements.

◆ end() [1/2]

Returns
const iterator past the last element.

◆ end() [2/2]

Returns
iterator past the last element.

◆ Erase() [1/2]

template<typename TheItemType >
void NCollection_LinearVector< TheItemType >::Erase ( const size_t theFrom,
const size_t theTo )
inline

Remove elements in range [theFrom, theTo), shifting subsequent elements left.

Parameters
[in]theFromstart index (inclusive, 0-based)
[in]theToend index (exclusive, 0-based)

◆ Erase() [2/2]

template<typename TheItemType >
void NCollection_LinearVector< TheItemType >::Erase ( const size_t theIndex)
inline

Remove element at theIndex, shifting subsequent elements left.

Parameters
[in]theIndexelement index (0-based)

◆ EraseLast()

template<typename TheItemType >
void NCollection_LinearVector< TheItemType >::EraseLast ( )
inline

Remove the last element.

◆ First()

template<typename TheItemType >
const TheItemType & NCollection_LinearVector< TheItemType >::First ( ) const
inline
Returns
const reference to the first element.

◆ HasData()

template<typename TheItemType >
bool NCollection_LinearVector< TheItemType >::HasData ( ) const
inlinenoexcept
Returns
true if the vector has allocated storage.

◆ InsertAfter() [1/2]

template<typename TheItemType >
void NCollection_LinearVector< TheItemType >::InsertAfter ( const size_t theIndex,
const TheItemType & theValue )
inline

Insert theValue after theIndex, shifting elements right.

Parameters
[in]theIndexposition after which to insert (0-based)
[in]theValueelement to insert

◆ InsertAfter() [2/2]

template<typename TheItemType >
void NCollection_LinearVector< TheItemType >::InsertAfter ( const size_t theIndex,
TheItemType && theValue )
inline

Insert theValue after theIndex, shifting elements right.

Parameters
[in]theIndexposition after which to insert (0-based)
[in]theValueelement to move-insert

◆ InsertBefore() [1/2]

template<typename TheItemType >
void NCollection_LinearVector< TheItemType >::InsertBefore ( const size_t theIndex,
const TheItemType & theValue )
inline

Insert theValue before theIndex, shifting elements right.

Parameters
[in]theIndexinsertion position (0-based)
[in]theValueelement to insert

◆ InsertBefore() [2/2]

template<typename TheItemType >
void NCollection_LinearVector< TheItemType >::InsertBefore ( const size_t theIndex,
TheItemType && theValue )
inline

Insert theValue before theIndex, shifting elements right.

Parameters
[in]theIndexinsertion position (0-based)
[in]theValueelement to move-insert

◆ IsEmpty()

template<typename TheItemType >
bool NCollection_LinearVector< TheItemType >::IsEmpty ( ) const
inlinenoexcept
Returns
true if the vector contains no elements.

◆ Last()

template<typename TheItemType >
const TheItemType & NCollection_LinearVector< TheItemType >::Last ( ) const
inline
Returns
const reference to the last element.

◆ MaxSize()

template<typename TheItemType >
static constexpr size_t NCollection_LinearVector< TheItemType >::MaxSize ( )
inlinestaticconstexprnoexcept
Returns
current max supported size.

◆ operator()() [1/2]

Returns
mutable reference to element at theIndex.

◆ operator()() [2/2]

template<typename TheItemType >
const TheItemType & NCollection_LinearVector< TheItemType >::operator() ( const size_t theIndex) const
inline
Returns
const reference to element at theIndex.

◆ operator=() [1/2]

Copy assignment.

◆ operator=() [2/2]

Move assignment.

◆ operator[]() [1/2]

Returns
mutable reference to element at theIndex.

◆ operator[]() [2/2]

template<typename TheItemType >
const TheItemType & NCollection_LinearVector< TheItemType >::operator[] ( const size_t theIndex) const
inline
Returns
const reference to element at theIndex.

◆ Reserve()

template<typename TheItemType >
void NCollection_LinearVector< TheItemType >::Reserve ( const size_t theCapacity)
inline

Pre-allocate memory for at least theCapacity elements without changing size.

Parameters
[in]theCapacityminimum capacity to ensure

◆ Resize() [1/2]

template<typename TheItemType >
void NCollection_LinearVector< TheItemType >::Resize ( const size_t theSize)
inline

Change the number of elements. If theSize > Size(), new elements are default-constructed. If theSize < Size(), excess elements are destroyed.

Parameters
[in]theSizenew number of elements

◆ Resize() [2/2]

template<typename TheItemType >
void NCollection_LinearVector< TheItemType >::Resize ( const size_t theSize,
const TheItemType & theValue )
inline

Change the number of elements, filling new slots with theValue. If theSize > Size(), new elements are copy-constructed from theValue. If theSize < Size(), excess elements are destroyed.

Parameters
[in]theSizenew number of elements
[in]theValuevalue to fill new elements with

◆ SetValue() [1/2]

template<typename TheItemType >
TheItemType & NCollection_LinearVector< TheItemType >::SetValue ( const size_t theIndex,
const TheItemType & theValue )
inline

Set value at theIndex. If theIndex >= Size(), the vector is extended.

Parameters
[in]theIndexelement index (0-based)
[in]theValuevalue to set
Returns
reference to the element

◆ SetValue() [2/2]

template<typename TheItemType >
TheItemType & NCollection_LinearVector< TheItemType >::SetValue ( const size_t theIndex,
TheItemType && theValue )
inline

Set value at theIndex by move. If theIndex >= Size(), the vector is extended.

Parameters
[in]theIndexelement index (0-based)
[in]theValuevalue to set
Returns
reference to the element

◆ Size()

template<typename TheItemType >
size_t NCollection_LinearVector< TheItemType >::Size ( ) const
inlinenoexcept
Returns
number of elements.

◆ Value()

template<typename TheItemType >
const TheItemType & NCollection_LinearVector< TheItemType >::Value ( const size_t theIndex) const
inline
Returns
const reference to element at theIndex.
Parameters
[in]theIndexelement index (0-based)

The documentation for this class was generated from the following file: