AXOM
Axom provides a robust, flexible software infrastructure for the development of multi-physics applications and computational tools.
|
Provides a generic multi-component array, contained in Sidre. More...
#include </home/docs/checkouts/readthedocs.org/user_builds/axom/checkouts/v0.5.0/src/axom/sidre/core/Array.hpp>
Public Member Functions | |
Array ()=delete | |
Default constructor. Disabled. More... | |
virtual | ~Array () |
Sidre Array constructors | |
Array (View *view) | |
Creates an Array instance from a View that already has data. More... | |
Array (View *view, axom::IndexType num_tuples, axom::IndexType num_components=1, axom::IndexType capacity=0) | |
Creates an Array instance of num_tuples size, where each tuple consists of num_components values and populates the associated View. More... | |
Array methods to query and set attributes | |
virtual bool | isExternal () const |
Return true iff the external buffer constructor was called. More... | |
virtual bool | isInSidre () const |
Return true iff a sidre constructor was called. More... | |
const View * | getView () const |
Return a pointer to the View that this Array wraps. More... | |
Array tuple access operators | |
T & | operator() (IndexType pos, IndexType component=0) |
Accessor, returns a reference to the given component of the specified tuple. More... | |
const T & | operator() (IndexType pos, IndexType component=0) const |
T & | operator[] (IndexType idx) |
Accessor, returns a reference to the given value. More... | |
const T & | operator[] (IndexType idx) const |
T * | getData () |
Return a pointer to the array of data. More... | |
const T * | getData () const |
Array methods to modify the data. | |
void | fill (const T &value) |
Set all the values of the array. More... | |
void | append (const T &value) |
Append a value to the end of the array. More... | |
void | append (const T *tuples, IndexType n) |
Append tuples to the end of the array. More... | |
void | set (const T *tuples, IndexType n, IndexType pos) |
Modify the values of existing tuples. More... | |
void | insert (const T &value, IndexType pos) |
Insert a tuple into the array at the given position. More... | |
void | insert (const T *tuples, IndexType n, IndexType pos) |
Insert tuples into the array at the given position. More... | |
void | emplace (IndexType n, IndexType pos, const T &value=T()) |
Insert multiple copies of the same value at the given position. More... | |
Array methods to query and set attributes | |
IndexType | capacity () const |
Return the number of tuples allocated for the data array. More... | |
void | reserve (IndexType capacity) |
Increase the capacity. Does nothing if the new capacity is less than the current capacity. More... | |
void | shrink () |
Shrink the capacity to be equal to the size. More... | |
bool | empty () const |
Returns true iff the Array stores no elements. More... | |
IndexType | size () const |
Return the number of tuples stored in the data array. More... | |
void | resize (IndexType new_num_tuples) |
Update the number of tuples stored in the data array. More... | |
double | getResizeRatio () const |
Get the ratio by which the capacity increases upon dynamic resize. More... | |
void | setResizeRatio (double ratio) |
Set the ratio by which the capacity increases upon dynamic resize. More... | |
IndexType | numComponents () const |
Return the number of components per tuple. More... | |
Static Public Attributes | |
static constexpr double | DEFAULT_RESIZE_RATIO = 2.0 |
static constexpr IndexType | MIN_DEFAULT_CAPACITY = 32 |
Protected Member Functions | |
virtual void | updateNumTuples (axom::IndexType new_num_tuples) |
Update the number of tuples. More... | |
virtual void | setCapacity (axom::IndexType new_capacity) |
Set the number of tuples allocated for the data array. More... | |
virtual void | dynamicRealloc (axom::IndexType new_num_tuples) |
Reallocates the data array when the size exceeds the capacity. More... | |
void | describeView () |
Applies this Array's type and dimensions to the sidre View. More... | |
axom::IndexType | getViewShape (int dim) const |
Given a non-empty View of dimension 2, returns the length of the given dimension. More... | |
void | reallocViewData (IndexType new_capacity) |
Allocates space within the Array's View. More... | |
DISABLE_COPY_AND_ASSIGNMENT (Array) | |
DISABLE_MOVE_AND_ASSIGNMENT (Array) | |
void | initialize (IndexType num_tuples, IndexType num_components, IndexType capacity) |
Initialize an Array instance with the given number of tuples. More... | |
T * | reserveForInsert (IndexType n, IndexType pos) |
Make space for a subsequent insertion into the array. More... | |
Internal bounds-checking routines | |
bool | inBounds (IndexType pos, IndexType component) const |
Test if pos and component are within bounds. More... | |
bool | inBounds (IndexType idx) const |
Test if idx is within bounds. More... | |
Static Protected Member Functions | |
template<typename U = T> | |
static constexpr std::enable_if<!std::is_enum< U >::value, TypeID >::type | sidreTypeId () |
Return the TypeID corresponding to T. This function handles when T is not an enum. More... | |
template<typename U = T> | |
static constexpr std::enable_if< std::is_enum< U >::value, TypeID >::type | sidreTypeId () |
Return the TypeID corresponding to T. This function handles when T is an enum. More... | |
Protected Attributes | |
View * | m_view |
T * | m_data |
IndexType | m_num_tuples |
IndexType | m_capacity |
IndexType | m_num_components |
double | m_resize_ratio |
bool const | m_is_external |
Provides a generic multi-component array, contained in Sidre.
This sidre::Array class extends axom::utilities::Array by storing data in a Sidre DataStore
. This class provides a generic multi-component array container with dynamic re-allocation and insertion. Each element in the array is a tuple consisting of 1 or more components, which are stored contiguously.
Objects of the sidre::Array class may be constructed from a View. All array operations can be performed as with the base axom::utilities::Array class. The size of the Array can grow as needed, and all memory management is delegated to Sidre.
reserve()
when the number of nodes is known a priori, or opt to use a constructor that takes an actual size and capacity when possible.T | the type of the values to hold. |
|
delete |
Default constructor. Disabled.
axom::sidre::Array< T >::Array | ( | View * | view | ) |
Creates an Array instance from a View that already has data.
References axom::sidre::View::getBuffer(), axom::sidre::Buffer::getNumElements(), axom::sidre::View::getTypeID(), axom::sidre::Array< T >::getViewShape(), axom::sidre::View::getVoidPtr(), axom::sidre::View::isEmpty(), axom::Array< T >::m_capacity, axom::Array< T >::m_data, axom::Array< T >::m_num_components, axom::Array< T >::m_num_tuples, axom::sidre::Array< T >::m_view, axom::sidre::Array< T >::sidreTypeId(), and SLIC_ERROR_IF.
axom::sidre::Array< T >::Array | ( | View * | view, |
axom::IndexType | num_tuples, | ||
axom::IndexType | num_components = 1 , |
||
axom::IndexType | capacity = 0 |
||
) |
Creates an Array instance of num_tuples
size, where each tuple consists of num_components
values and populates the associated View.
[in] | view | the View that will hold this Array's data. |
[in] | num_tuples | the number of tuples accounted for in the Array. |
[in] | num_components | the number of values per tuple. If not specified defaults to 1. |
[in] | capacity | the number of tuples to allocate space for. |
References axom::Array< T >::initialize(), axom::sidre::View::isEmpty(), axom::Array< T >::m_capacity, axom::Array< T >::m_data, axom::Array< T >::m_num_components, axom::Array< T >::m_num_tuples, axom::sidre::Array< T >::m_view, SLIC_ASSERT, and SLIC_ERROR_IF.
|
virtual |
Destructor. Frees the associated buffer unless owned by Sidre.
Reimplemented from axom::Array< T >.
References axom::Array< T >::m_data, and axom::sidre::Array< T >::m_view.
|
inlinevirtual |
Return true iff the external buffer constructor was called.
|
inlinevirtual |
Return true iff a sidre constructor was called.
Reimplemented from axom::Array< T >.
|
inline |
|
inlineprotectedvirtual |
Update the number of tuples.
[in] | new_num_tuples | the new number of tuples. |
Reimplemented from axom::Array< T >.
References axom::sidre::Array< T >::describeView(), axom::Array< T >::m_capacity, axom::Array< T >::m_num_tuples, and SLIC_ASSERT.
Referenced by axom::sidre::Array< T >::setCapacity().
|
inlineprotectedvirtual |
Set the number of tuples allocated for the data array.
[in] | capacity | the new number of tuples to allocate. |
Reimplemented from axom::Array< T >.
References axom::Array< T >::m_num_tuples, axom::sidre::Array< T >::reallocViewData(), SLIC_ASSERT, and axom::sidre::Array< T >::updateNumTuples().
|
inlineprotectedvirtual |
Reallocates the data array when the size exceeds the capacity.
[in] | new_num_tuples | the number of tuples which exceeds the current capacity. |
Reimplemented from axom::Array< T >.
References axom::Array< T >::m_resize_ratio, axom::sidre::Array< T >::reallocViewData(), and SLIC_ERROR_IF.
|
inlinestaticprotected |
Return the TypeID corresponding to T. This function handles when T is not an enum.
Referenced by axom::sidre::Array< T >::Array(), axom::sidre::Array< T >::describeView(), and axom::sidre::Array< T >::reallocViewData().
|
inlinestaticprotected |
Return the TypeID corresponding to T. This function handles when T is an enum.
|
inlineprotected |
Applies this Array's type and dimensions to the sidre View.
Calls m_view->apply(sidreTypeId(), 2, {m_num_tuples, m_num_components}).
References axom::sidre::View::apply(), axom::Array< T >::m_num_components, axom::Array< T >::m_num_tuples, axom::sidre::Array< T >::m_view, axom::sidre::Array< T >::sidreTypeId(), and SLIC_ASSERT.
Referenced by axom::sidre::Array< T >::reallocViewData(), and axom::sidre::Array< T >::updateNumTuples().
|
inlineprotected |
Given a non-empty View of dimension 2, returns the length of the given dimension.
[in] | view | the View to examine. |
[in] | dim | the dimension (0 or 1) to return the length of. |
References axom::sidre::View::getNumDimensions(), axom::sidre::View::getShape(), axom::sidre::View::isEmpty(), axom::sidre::Array< T >::m_view, and SLIC_ERROR_IF.
Referenced by axom::sidre::Array< T >::Array().
|
inlineprotected |
Allocates space within the Array's View.
[in] | new_num_tuples | the number of tuples which exceeds the current capacity. |
References axom::sidre::View::allocate(), axom::sidre::Array< T >::describeView(), axom::sidre::View::getVoidPtr(), axom::sidre::View::isEmpty(), axom::Array< T >::m_capacity, axom::Array< T >::m_data, axom::Array< T >::m_num_components, axom::sidre::Array< T >::m_view, axom::sidre::View::reallocate(), axom::sidre::Array< T >::sidreTypeId(), and SLIC_ERROR_IF.
Referenced by axom::sidre::Array< T >::dynamicRealloc(), and axom::sidre::Array< T >::setCapacity().
|
protected |
|
protected |
|
inlineinherited |
Accessor, returns a reference to the given component of the specified tuple.
[in] | pos | the tuple to query. |
[in] | component | the component to return. |
|
inlineinherited |
|
inlineinherited |
Accessor, returns a reference to the given value.
[in] | idx | the position of the value to return. |
|
inlineinherited |
|
inlineinherited |
Return a pointer to the array of data.
Referenced by axom::mint::ConnectivityArray< TYPE >::getValuePtr(), and axom::mint::ConnectivityArray< TYPE >::operator[]().
|
inlineinherited |
|
inlineinherited |
Set all the values of the array.
[in] | value | the value to set to. |
|
inlineinherited |
Append a value to the end of the array.
[in] | value | the value to append. |
Referenced by axom::mint::ConnectivityArray< TYPE >::appendM().
|
inlineinherited |
Append tuples to the end of the array.
[in] | tuples | the tuples to append. |
[in] | n | the number of tuples to append. |
|
inlineinherited |
Modify the values of existing tuples.
[in] | tuples | the new tuples to write. |
[in] | n | the number of tuples to write. |
[in] | pos | the position at which to begin writing. |
Referenced by axom::mint::ConnectivityArray< TYPE >::set(), and axom::mint::ConnectivityArray< TYPE >::setM().
|
inlineinherited |
Insert a tuple into the array at the given position.
[in] | value | the value to insert. |
[in] | pos | the position at which to insert. |
Referenced by axom::mint::ConnectivityArray< TYPE >::insertM().
|
inlineinherited |
Insert tuples into the array at the given position.
[in] | tuples | the tuples to insert. |
[in] | n | the number of tuples to insert. |
[in] | pos | the position at which to begin the insertion. |
|
inlineinherited |
Insert multiple copies of the same value at the given position.
[in] | n | the number of tuples to insert. |
[in] | pos | the position to insert at. |
[in] | value | the value for each component of the new tuples. If not specified defaults to the default value of T (zero for most numeric types). |
|
inlineinherited |
Return the number of tuples allocated for the data array.
Referenced by axom::mint::ConnectivityArray< TYPE >::getIDCapacity(), and axom::mint::ConnectivityArray< TYPE >::reserve().
|
inlineinherited |
Increase the capacity. Does nothing if the new capacity is less than the current capacity.
[in] | capacity | the new number of tuples to allocate. |
Referenced by axom::mint::ConnectivityArray< TYPE >::reserve().
|
inlineinherited |
Shrink the capacity to be equal to the size.
Referenced by axom::mint::ConnectivityArray< TYPE >::shrink().
|
inlineinherited |
Returns true iff the Array stores no elements.
Referenced by axom::mint::ConnectivityArray< TYPE >::empty().
|
inlineinherited |
Return the number of tuples stored in the data array.
Referenced by axom::mint::ConnectivityArray< TYPE >::getNumberOfIDs(), and axom::mint::ConnectivityArray< TYPE >::getNumberOfValues().
|
inlineinherited |
Update the number of tuples stored in the data array.
Referenced by axom::mint::ConnectivityArray< TYPE >::resize().
|
inlineinherited |
Get the ratio by which the capacity increases upon dynamic resize.
Referenced by axom::mint::ConnectivityArray< TYPE >::getResizeRatio().
|
inlineinherited |
Set the ratio by which the capacity increases upon dynamic resize.
[in] | ratio | the new resize ratio. |
Referenced by axom::mint::ConnectivityArray< TYPE >::setResizeRatio().
|
inlineinherited |
Return the number of components per tuple.
Referenced by axom::mint::ConnectivityArray< TYPE >::ConnectivityArray().
|
inlineprotectedinherited |
Initialize an Array instance with the given number of tuples.
[in] | num_tuples | the number of tuples the Array holds. |
[in] | num_components | the number of values per tuple. If not specified defaults to 1. |
[in] | capacity | the number of tuples to allocate space for. |
Referenced by axom::sidre::Array< T >::Array().
|
inlineprotectedinherited |
Make space for a subsequent insertion into the array.
[in] | n | the number of tuples to insert. |
[in] | pos | the position at which to begin the insertion. |
|
inlineprotectedinherited |
Test if pos and component are within bounds.
|
inlineprotectedinherited |
Test if idx is within bounds.
|
protected |
|
staticinherited |
|
staticinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
Referenced by axom::sidre::Array< T >::dynamicRealloc().
|
protectedinherited |