Open CASCADE Technology Reference Manual 8.0.0
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
NCollection_Array1< TheItemType > Class Template Reference

The class NCollection_Array1 represents unidimensional arrays of fixed size known at run time. The range of the index is user defined. An array1 can be constructed with a "C array". This functionality is useful to call methods expecting an Array1. It allows to carry the bounds inside the arrays. More...

#include <NCollection_Array1.hxx>

Inheritance diagram for NCollection_Array1< TheItemType >:
Inheritance graph
[legend]

Public Types

typedef NCollection_Allocator< TheItemTypeallocator_type
 Memory allocation.
 
using value_type = TheItemType
 
using size_type = size_t
 
using difference_type = size_t
 
using pointer = TheItemType*
 
using const_pointer = const TheItemType*
 
using reference = TheItemType&
 
using const_reference = const TheItemType&
 
using iterator
 
using const_iterator
 
using Iterator = NCollection_Iterator<NCollection_Array1<TheItemType>>
 

Public Member Functions

const_iterator begin () const noexcept
 
iterator begin () noexcept
 
const_iterator cbegin () const noexcept
 
iterator end () noexcept
 
const_iterator end () const noexcept
 
const_iterator cend () const noexcept
 
 NCollection_Array1 () noexcept
 
 NCollection_Array1 (const int theLower, const int theUpper)
 
 NCollection_Array1 (const_reference theBegin, const int theLower, const int theUpper, const bool theUseBuffer=true)
 
 NCollection_Array1 (const size_t theSize)
 Zero-based constructor: allocates theSize elements with lower bound 0. Use At()/ChangeAt() or STL iterators for optimal access (no offset subtraction).
 
 NCollection_Array1 (pointer theBegin, const size_t theSize)
 Zero-based buffer-reuse constructor: wraps an existing C array of theSize elements. The array does NOT own the buffer and will NOT free it on destruction. Use At()/ChangeAt() or STL iterators for optimal access (no offset subtraction).
 
 NCollection_Array1 (const NCollection_Array1 &theOther)
 Copy constructor.
 
 NCollection_Array1 (NCollection_Array1 &&theOther) noexcept
 Move constructor.
 
virtual ~NCollection_Array1 ()
 
void Init (const_reference theValue)
 Initialise the items with theValue.
 
size_t Size () const noexcept
 Size query.
 
int Length () const noexcept
 Length query (legacy int-returning API).
 
bool IsEmpty () const noexcept
 Return TRUE if array has zero length.
 
int Lower () const noexcept
 Lower bound.
 
int Upper () const noexcept
 Upper bound.
 
NCollection_Array1Assign (const NCollection_Array1 &theOther)
 Replaces this array by a copy of theOther array. Bounds and length are copied from theOther. When this array wraps an external (non-owned) buffer:
 
NCollection_Array1CopyValues (const NCollection_Array1 &theOther)
 Copies values from theOther array without changing this array bounds. This array should be pre-allocated and have the same length as theOther; otherwise exception Standard_DimensionMismatch is thrown.
 
NCollection_Array1Move (NCollection_Array1 &&theOther) noexcept
 Move assignment. This array will borrow all the data from theOther. The moved object will keep pointer to the memory buffer and range, but it will not free the buffer on destruction.
 
NCollection_Array1Move (NCollection_Array1 &theOther) noexcept
 
NCollection_Array1operator= (const NCollection_Array1 &theOther)
 Assignment operator;.
 
NCollection_Array1operator= (NCollection_Array1 &&theOther) noexcept
 Move assignment operator;.
 
const_reference First () const noexcept
 
reference ChangeFirst () noexcept
 
const_reference Last () const noexcept
 
reference ChangeLast () noexcept
 
const_reference Value (const int theIndex) const
 Constant value access.
 
const_reference operator() (const int theIndex) const
 operator() - alias to Value
 
const_reference operator[] (const int theIndex) const
 operator[] - alias to Value
 
reference ChangeValue (const int theIndex)
 Variable value access.
 
reference operator() (const int theIndex)
 operator() - alias to ChangeValue
 
reference operator[] (const int theIndex)
 operator[] - alias to ChangeValue
 
const_reference At (const size_t theIndex) const
 0-based checked access independent of Lower()/Upper().
 
reference ChangeAt (const size_t theIndex)
 0-based checked mutable access independent of Lower()/Upper().
 
void SetValue (const int theIndex, const value_type &theItem)
 Set value.
 
void SetValue (const int theIndex, value_type &&theItem)
 Set value.
 
template<typename... Args>
reference EmplaceValue (const int theIndex, Args &&... theArgs)
 Emplace value at the specified index, constructing it in-place.
 
void UpdateLowerBound (const int theLower) noexcept
 Changes the lowest bound. Do not move data.
 
void UpdateUpperBound (const int theUpper) noexcept
 Changes the upper bound. Do not move data.
 
void Resize (const int theLower, const int theUpper, const bool theToCopyData)
 Resizes the array to specified bounds. No re-allocation will be done if length of array does not change, but existing values will not be discarded if theToCopyData set to FALSE.
 
void Resize (const size_t theSize, const bool theToCopyData)
 Resizes the array to theSize elements, keeping the lower bound unchanged.
 
bool IsDeletable () const noexcept
 

Data Fields

friend iterator
 
friend const_iterator
 

Protected Member Functions

void resizeImpl (const size_t theNewSize, const int theNewLower, const bool theToCopyData)
 Core resize implementation used by all public Resize() overloads.
 
const_reference at (const size_t theIndex) const
 
reference at (const size_t theIndex)
 
template<typename U = TheItemType>
std::enable_if< std::is_trivially_default_constructible< U >::value, void >::type construct (const size_t, const size_t)
 
template<typename U = TheItemType>
std::enable_if<!std::is_trivially_default_constructible< U >::value, void >::type construct (const size_t theFrom, const size_t theTo)
 
template<typename U = TheItemType>
std::enable_if< std::is_trivially_destructible< U >::value, void >::type destroy (pointer, const size_t, const size_t)
 
template<typename U = TheItemType>
std::enable_if<!std::is_trivially_destructible< U >::value, void >::type destroy (pointer theWhat, const size_t theFrom, const size_t theTo)
 
void assign (const const_pointer theFrom, const size_t theSize, const int theLower)
 
template<typename U = TheItemType>
std::enable_if< std::is_trivially_copyable< U >::value, void >::type copyAssign (pointer theTarget, const_pointer theFrom, const size_t theCount)
 
template<typename U = TheItemType>
std::enable_if<!std::is_trivially_copyable< U >::value, void >::type copyAssign (pointer theTarget, const_pointer theFrom, const size_t theCount)
 
void copyConstruct (const pointer theFrom, const size_t theCount)
 
template<typename U = TheItemType>
std::enable_if< std::is_trivially_copyable< U >::value, void >::type copyConstruct (pointer theTarget, const_pointer theFrom, const size_t theCount)
 
template<typename U = TheItemType>
std::enable_if<!std::is_trivially_copyable< U >::value, void >::type copyConstruct (pointer theTarget, const_pointer theFrom, const size_t theCount)
 

Protected Attributes

int myLowerBound
 
size_t mySize
 
pointer myPointer = nullptr
 
bool myIsOwner = false
 
allocator_type myAllocator
 

Detailed Description

template<class TheItemType>
class NCollection_Array1< TheItemType >

The class NCollection_Array1 represents unidimensional arrays of fixed size known at run time. The range of the index is user defined. An array1 can be constructed with a "C array". This functionality is useful to call methods expecting an Array1. It allows to carry the bounds inside the arrays.

Examples:

Item tab[100]; // an example with a C array
NCollection_Array1<Item> tttab (ttab(10), 10, 20); // a slice of ttab
#define Item
Definition MAT_ListOfBisector.hxx:96
STL input iterator that wraps an OCCT More()/Next() iterator.
Definition NCollection_ForwardRange.hxx:142

If you want to reindex an array from 1 to Length do:

NCollection_Array1<Item> tab1 (tab (tab.Lower()), 1, tab.Length());

Warning: Programs client of such a class must be independent of the range of the first element. Then, a C++ for loop must be written like this

for (i = A.Lower(); i <= A.Upper(); i++)

Zero-based (size_t) construction mode: Use NCollection_Array1(size_t theSize) or NCollection_Array1(pointer, size_t) to create a zero-based array (Lower()==0). In this mode At()/ChangeAt() and STL iterators are the preferred access path - they address elements directly without any offset subtraction. Buffer-reuse variants do NOT own the memory and will not free it on destruction.

int aBuffer[100];
NCollection_Array1<int> aZero(100); // allocates, lower=0
NCollection_Array1<int> aWrap(aBuffer, 100); // wraps aBuffer, lower=0, not owner
for (size_t i = 0; i < aWrap.Size(); ++i)
aWrap.At(i) = static_cast<int>(i);

Member Typedef Documentation

◆ allocator_type

Memory allocation.

◆ const_iterator

template<class TheItemType >
using NCollection_Array1< TheItemType >::const_iterator
Initial value:
NCollection_IndexedIterator<std::random_access_iterator_tag,
true>
TheItemType value_type
Definition NCollection_Array1.hxx:82
NCollection_Array1() noexcept
Definition NCollection_Array1.hxx:115
Helper class that allows to use NCollection iterators as STL iterators. NCollection iterator can be e...
Definition NCollection_IndexedIterator.hxx:28

◆ const_pointer

template<class TheItemType >
using NCollection_Array1< TheItemType >::const_pointer = const TheItemType*

◆ const_reference

template<class TheItemType >
using NCollection_Array1< TheItemType >::const_reference = const TheItemType&

◆ difference_type

template<class TheItemType >
using NCollection_Array1< TheItemType >::difference_type = size_t

◆ iterator

Initial value:
NCollection_IndexedIterator<std::random_access_iterator_tag,
false>

◆ Iterator

◆ pointer

◆ reference

◆ size_type

◆ value_type

Constructor & Destructor Documentation

◆ NCollection_Array1() [1/7]

◆ NCollection_Array1() [2/7]

template<class TheItemType >
NCollection_Array1< TheItemType >::NCollection_Array1 ( const int theLower,
const int theUpper )
inlineexplicit

◆ NCollection_Array1() [3/7]

template<class TheItemType >
NCollection_Array1< TheItemType >::NCollection_Array1 ( const_reference theBegin,
const int theLower,
const int theUpper,
const bool theUseBuffer = true )
inlineexplicit

◆ NCollection_Array1() [4/7]

template<class TheItemType >
NCollection_Array1< TheItemType >::NCollection_Array1 ( const size_t theSize)
inlineexplicit

Zero-based constructor: allocates theSize elements with lower bound 0. Use At()/ChangeAt() or STL iterators for optimal access (no offset subtraction).

◆ NCollection_Array1() [5/7]

template<class TheItemType >
NCollection_Array1< TheItemType >::NCollection_Array1 ( pointer theBegin,
const size_t theSize )
inlineexplicit

Zero-based buffer-reuse constructor: wraps an existing C array of theSize elements. The array does NOT own the buffer and will NOT free it on destruction. Use At()/ChangeAt() or STL iterators for optimal access (no offset subtraction).

◆ NCollection_Array1() [6/7]

Copy constructor.

◆ NCollection_Array1() [7/7]

Move constructor.

◆ ~NCollection_Array1()

Member Function Documentation

◆ assign()

template<class TheItemType >
void NCollection_Array1< TheItemType >::assign ( const const_pointer theFrom,
const size_t theSize,
const int theLower )
inlineprotected

◆ Assign()

template<class TheItemType >
NCollection_Array1 & NCollection_Array1< TheItemType >::Assign ( const NCollection_Array1< TheItemType > & theOther)
inline

Replaces this array by a copy of theOther array. Bounds and length are copied from theOther. When this array wraps an external (non-owned) buffer:

  • if theOther has the same length, values are copied in place into the external buffer and ownership is unchanged;
  • if theOther has a different length, this array detaches from the external buffer and allocates a fresh owned buffer. Use CopyValues() to preserve this array's bounds.

◆ at() [1/2]

template<class TheItemType >
reference NCollection_Array1< TheItemType >::at ( const size_t theIndex)
inlineprotected

◆ At()

template<class TheItemType >
const_reference NCollection_Array1< TheItemType >::At ( const size_t theIndex) const
inline

0-based checked access independent of Lower()/Upper().

Parameters
[in]theIndex0-based index in [0, Size()-1]

◆ at() [2/2]

template<class TheItemType >
const_reference NCollection_Array1< TheItemType >::at ( const size_t theIndex) const
inlineprotected

◆ begin() [1/2]

template<class TheItemType >
const_iterator NCollection_Array1< TheItemType >::begin ( ) const
inlinenoexcept

◆ begin() [2/2]

template<class TheItemType >
iterator NCollection_Array1< TheItemType >::begin ( )
inlinenoexcept

◆ cbegin()

template<class TheItemType >
const_iterator NCollection_Array1< TheItemType >::cbegin ( ) const
inlinenoexcept

◆ cend()

template<class TheItemType >
const_iterator NCollection_Array1< TheItemType >::cend ( ) const
inlinenoexcept

◆ ChangeAt()

template<class TheItemType >
reference NCollection_Array1< TheItemType >::ChangeAt ( const size_t theIndex)
inline

0-based checked mutable access independent of Lower()/Upper().

Parameters
[in]theIndex0-based index in [0, Size()-1]

◆ ChangeFirst()

template<class TheItemType >
reference NCollection_Array1< TheItemType >::ChangeFirst ( )
inlinenoexcept
Returns
first element

◆ ChangeLast()

template<class TheItemType >
reference NCollection_Array1< TheItemType >::ChangeLast ( )
inlinenoexcept
Returns
last element

◆ ChangeValue()

template<class TheItemType >
reference NCollection_Array1< TheItemType >::ChangeValue ( const int theIndex)
inline

Variable value access.

◆ construct() [1/2]

template<class TheItemType >
template<typename U = TheItemType>
std::enable_if<!std::is_trivially_default_constructible< U >::value, void >::type NCollection_Array1< TheItemType >::construct ( const size_t theFrom,
const size_t theTo )
inlineprotected

◆ construct() [2/2]

template<class TheItemType >
template<typename U = TheItemType>
std::enable_if< std::is_trivially_default_constructible< U >::value, void >::type NCollection_Array1< TheItemType >::construct ( const size_t ,
const size_t  )
inlineprotected

◆ copyAssign() [1/2]

template<class TheItemType >
template<typename U = TheItemType>
std::enable_if< std::is_trivially_copyable< U >::value, void >::type NCollection_Array1< TheItemType >::copyAssign ( pointer theTarget,
const_pointer theFrom,
const size_t theCount )
inlineprotected

◆ copyAssign() [2/2]

template<class TheItemType >
template<typename U = TheItemType>
std::enable_if<!std::is_trivially_copyable< U >::value, void >::type NCollection_Array1< TheItemType >::copyAssign ( pointer theTarget,
const_pointer theFrom,
const size_t theCount )
inlineprotected

◆ copyConstruct() [1/3]

template<class TheItemType >
void NCollection_Array1< TheItemType >::copyConstruct ( const pointer theFrom,
const size_t theCount )
inlineprotected

◆ copyConstruct() [2/3]

template<class TheItemType >
template<typename U = TheItemType>
std::enable_if< std::is_trivially_copyable< U >::value, void >::type NCollection_Array1< TheItemType >::copyConstruct ( pointer theTarget,
const_pointer theFrom,
const size_t theCount )
inlineprotected

◆ copyConstruct() [3/3]

template<class TheItemType >
template<typename U = TheItemType>
std::enable_if<!std::is_trivially_copyable< U >::value, void >::type NCollection_Array1< TheItemType >::copyConstruct ( pointer theTarget,
const_pointer theFrom,
const size_t theCount )
inlineprotected

◆ CopyValues()

template<class TheItemType >
NCollection_Array1 & NCollection_Array1< TheItemType >::CopyValues ( const NCollection_Array1< TheItemType > & theOther)
inline

Copies values from theOther array without changing this array bounds. This array should be pre-allocated and have the same length as theOther; otherwise exception Standard_DimensionMismatch is thrown.

◆ destroy() [1/2]

template<class TheItemType >
template<typename U = TheItemType>
std::enable_if<!std::is_trivially_destructible< U >::value, void >::type NCollection_Array1< TheItemType >::destroy ( pointer theWhat,
const size_t theFrom,
const size_t theTo )
inlineprotected

◆ destroy() [2/2]

template<class TheItemType >
template<typename U = TheItemType>
std::enable_if< std::is_trivially_destructible< U >::value, void >::type NCollection_Array1< TheItemType >::destroy ( pointer ,
const size_t ,
const size_t  )
inlineprotected

◆ EmplaceValue()

template<class TheItemType >
template<typename... Args>
reference NCollection_Array1< TheItemType >::EmplaceValue ( const int theIndex,
Args &&... theArgs )
inline

Emplace value at the specified index, constructing it in-place.

Parameters
theIndexindex at which to emplace the value
theArgsarguments forwarded to TheItemType constructor
Returns
reference to the newly constructed item

◆ end() [1/2]

template<class TheItemType >
const_iterator NCollection_Array1< TheItemType >::end ( ) const
inlinenoexcept

◆ end() [2/2]

template<class TheItemType >
iterator NCollection_Array1< TheItemType >::end ( )
inlinenoexcept

◆ First()

template<class TheItemType >
const_reference NCollection_Array1< TheItemType >::First ( ) const
inlinenoexcept
Returns
first element

◆ Init()

template<class TheItemType >
void NCollection_Array1< TheItemType >::Init ( const_reference theValue)
inline

Initialise the items with theValue.

◆ IsDeletable()

template<class TheItemType >
bool NCollection_Array1< TheItemType >::IsDeletable ( ) const
inlinenoexcept

◆ IsEmpty()

template<class TheItemType >
bool NCollection_Array1< TheItemType >::IsEmpty ( ) const
inlinenoexcept

Return TRUE if array has zero length.

◆ Last()

template<class TheItemType >
const_reference NCollection_Array1< TheItemType >::Last ( ) const
inlinenoexcept
Returns
last element

◆ Length()

template<class TheItemType >
int NCollection_Array1< TheItemType >::Length ( ) const
inlinenoexcept

Length query (legacy int-returning API).

◆ Lower()

template<class TheItemType >
int NCollection_Array1< TheItemType >::Lower ( ) const
inlinenoexcept

Lower bound.

◆ Move() [1/2]

template<class TheItemType >
NCollection_Array1 & NCollection_Array1< TheItemType >::Move ( NCollection_Array1< TheItemType > && theOther)
inlinenoexcept

Move assignment. This array will borrow all the data from theOther. The moved object will keep pointer to the memory buffer and range, but it will not free the buffer on destruction.

◆ Move() [2/2]

template<class TheItemType >
NCollection_Array1 & NCollection_Array1< TheItemType >::Move ( NCollection_Array1< TheItemType > & theOther)
inlinenoexcept

◆ operator()() [1/2]

template<class TheItemType >
reference NCollection_Array1< TheItemType >::operator() ( const int theIndex)
inline

operator() - alias to ChangeValue

◆ operator()() [2/2]

template<class TheItemType >
const_reference NCollection_Array1< TheItemType >::operator() ( const int theIndex) const
inline

operator() - alias to Value

◆ operator=() [1/2]

Assignment operator;.

See also
Assign()

◆ operator=() [2/2]

Move assignment operator;.

See also
Move()

◆ operator[]() [1/2]

template<class TheItemType >
reference NCollection_Array1< TheItemType >::operator[] ( const int theIndex)
inline

operator[] - alias to ChangeValue

◆ operator[]() [2/2]

template<class TheItemType >
const_reference NCollection_Array1< TheItemType >::operator[] ( const int theIndex) const
inline

operator[] - alias to Value

◆ Resize() [1/2]

template<class TheItemType >
void NCollection_Array1< TheItemType >::Resize ( const int theLower,
const int theUpper,
const bool theToCopyData )
inline

Resizes the array to specified bounds. No re-allocation will be done if length of array does not change, but existing values will not be discarded if theToCopyData set to FALSE.

Parameters
theLowernew lower bound of array
theUppernew upper bound of array
theToCopyDataflag to copy existing data into new array

◆ Resize() [2/2]

template<class TheItemType >
void NCollection_Array1< TheItemType >::Resize ( const size_t theSize,
const bool theToCopyData )
inline

Resizes the array to theSize elements, keeping the lower bound unchanged.

Parameters
theSizenew number of elements
theToCopyDataflag to copy existing data into new array

◆ resizeImpl()

template<class TheItemType >
void NCollection_Array1< TheItemType >::resizeImpl ( const size_t theNewSize,
const int theNewLower,
const bool theToCopyData )
inlineprotected

Core resize implementation used by all public Resize() overloads.

Parameters
theNewSizenew number of elements
theNewLowernew lower bound value to store
theToCopyDatawhether to preserve existing elements

◆ SetValue() [1/2]

template<class TheItemType >
void NCollection_Array1< TheItemType >::SetValue ( const int theIndex,
const value_type & theItem )
inline

Set value.

◆ SetValue() [2/2]

template<class TheItemType >
void NCollection_Array1< TheItemType >::SetValue ( const int theIndex,
value_type && theItem )
inline

Set value.

◆ Size()

template<class TheItemType >
size_t NCollection_Array1< TheItemType >::Size ( ) const
inlinenoexcept

Size query.

◆ UpdateLowerBound()

template<class TheItemType >
void NCollection_Array1< TheItemType >::UpdateLowerBound ( const int theLower)
inlinenoexcept

Changes the lowest bound. Do not move data.

◆ UpdateUpperBound()

template<class TheItemType >
void NCollection_Array1< TheItemType >::UpdateUpperBound ( const int theUpper)
inlinenoexcept

Changes the upper bound. Do not move data.

◆ Upper()

template<class TheItemType >
int NCollection_Array1< TheItemType >::Upper ( ) const
inlinenoexcept

Upper bound.

◆ Value()

template<class TheItemType >
const_reference NCollection_Array1< TheItemType >::Value ( const int theIndex) const
inline

Constant value access.

Field Documentation

◆ const_iterator

template<class TheItemType >
friend NCollection_Array1< TheItemType >::const_iterator

◆ iterator

◆ myAllocator

template<class TheItemType >
allocator_type NCollection_Array1< TheItemType >::myAllocator
protected

◆ myIsOwner

template<class TheItemType >
bool NCollection_Array1< TheItemType >::myIsOwner = false
protected

◆ myLowerBound

template<class TheItemType >
int NCollection_Array1< TheItemType >::myLowerBound
protected

◆ myPointer

template<class TheItemType >
pointer NCollection_Array1< TheItemType >::myPointer = nullptr
protected

◆ mySize

template<class TheItemType >
size_t NCollection_Array1< TheItemType >::mySize
protected

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