MAIA bb96820c
Multiphysics at AIA
|
A vector-like data storage class that supports both internal and external storage mechanisms. More...
#include <tensor.h>
Public Types | |
typedef MLong | size_type |
typedef T | value_type |
typedef value_type * | pointer |
typedef const value_type * | const_pointer |
typedef value_type & | reference |
typedef const value_type & | const_reference |
typedef pointer | iterator |
typedef const_pointer | const_iterator |
Public Member Functions | |
TensorStorage () | |
Default constructor does not allocate any memory but creates a zero-sized storage container. More... | |
TensorStorage (const TensorStorage< T > &ts) | |
Copy constructor creates a copy of the provided object. More... | |
TensorStorage (size_type n) | |
Creates a new TensorStorage object using internal storage. More... | |
TensorStorage (size_type n, T *data) | |
Creates a new TensorStorage object using external storage, i.e. no memory is allocated. More... | |
~TensorStorage () | |
The destructor only calls clear(). More... | |
size_type | size () const |
Returns the current size of the data container. More... | |
void | resize (size_type n) |
Resizes the container by first dropping all existing elements and then reallocating new memory. More... | |
void | resize (size_type n, T *data) |
Resizes the container by first dropping all existing elements and then using the external data pointer for the new storage. More... | |
void | clear () |
Clears the data storage by deallocating any previously allocated memory and setting the size to zero. More... | |
void | swap (TensorStorage< T > &other) |
Swap the contents of the existing TensorStorage object with another one. More... | |
TensorStorage< T > & | operator= (TensorStorage< T > copy) |
Assignment operator copies another object to the current one. More... | |
T & | operator[] (size_type n) |
Returns a reference to the element at position n (non-const version). More... | |
const T & | operator[] (size_type n) const |
Returns a reference to the element at position n (const version). More... | |
Private Member Functions | |
MBool | isAllocated () |
Returns true if this class has allocated its own memory, and false if external memory is used. More... | |
void | reallocate (size_type n) |
Clears any existing internal data storage and then allocates new memory to store as many elements as specified. More... | |
Private Attributes | |
T * | m_data |
size_type | m_size |
MBool | m_isAllocated |
Friends | |
template<class TT > | |
void | swap (TensorStorage< TT > &a, TensorStorage< TT > &b) |
Swap the contents between two TensorStorage objects. More... | |
T | Scalar data type of the tensor elements. |
By default, an internal storage mechanism is used, i.e. memory is allocated and deallocated automatically. However, there is also the possibility to provide a pointer to an existing storage location, which allows this class to be used as a "viewport" to data in memory. For the design of the class, a close look was taken at std::vector, in order to support most of the dynamic reallocation methods and other operations that std::vector has as well.
This class is mainly used by Tensor as its internal storage.
typedef const_pointer maia::tensor::detail_::TensorStorage< T >::const_iterator |
typedef const value_type* maia::tensor::detail_::TensorStorage< T >::const_pointer |
typedef const value_type& maia::tensor::detail_::TensorStorage< T >::const_reference |
typedef pointer maia::tensor::detail_::TensorStorage< T >::iterator |
typedef value_type* maia::tensor::detail_::TensorStorage< T >::pointer |
typedef value_type& maia::tensor::detail_::TensorStorage< T >::reference |
typedef MLong maia::tensor::detail_::TensorStorage< T >::size_type |
typedef T maia::tensor::detail_::TensorStorage< T >::value_type |
|
inline |
|
inline |
[in] | ts | Object that is copied. |
Note: The copy constructor will always allocate memory, even if the original object used external storage.
Definition at line 847 of file tensor.h.
|
inlineexplicit |
[in] | n | Size of the new container. |
Definition at line 863 of file tensor.h.
|
inline |
[in] | n | Size of the storage in memory. |
[in] | data | Pointer to existing memory location. |
Since this is supposed to be a very lightweight and fast way to access memory through TensorStorage, no data is changed to some initial value when this constructor is called. Furthermore, the user has to ensure that the data location that is pointed to does not get deallocated before the TensorStorage object is destroyed.
Definition at line 883 of file tensor.h.
|
inline |
Definition at line 896 of file tensor.h.
|
inline |
Definition at line 959 of file tensor.h.
|
inlineprivate |
|
inline |
[in] | copy | The object that is copied. |
Definition at line 1014 of file tensor.h.
|
inline |
[in] | n | Position of the element in the data storage. |
Definition at line 1032 of file tensor.h.
|
inline |
|
private |
|
inline |
[in] | n | New size of the data container. |
Definition at line 924 of file tensor.h.
|
inline |
[in] | n | New size of the data container. |
[in] | data | Pointer to existing memory location. |
|
inline |
|
inline |
|
friend |
TT |
[in] | a | First object. |
[in] | b | Second object. |
|
private |
|
private |
|
private |