libpnicore
|
type erasure array types More...
#include <array.hpp>
Public Types | |
typedef value | value_type |
value type of the array | |
typedef array_iterator< 0 > | iterator |
read/write iterator | |
typedef array_iterator< 1 > | const_iterator |
typedef array_holder_interface::element_index | element_index |
element index type | |
typedef array_holder_interface::view_index | view_index |
view index type | |
typedef size_t | size_type |
type used for array size | |
Public Member Functions | |
array () | |
default constructor | |
template<typename T , typename = typename std::enable_if< !std::is_same<array,typename std::remove_reference<T>::type >::value >::type> | |
array (const T &o) | |
copy original object More... | |
template<typename T , typename = typename std::enable_if< !std::is_same<array,typename std::remove_reference<T>::type >::value >::type> | |
array (T &&o) | |
move original object More... | |
array (const array &e) | |
copy constructor | |
array (array &&e) | |
move constructor | |
array & | operator= (const array &a) |
copy assignment operator | |
array & | operator= (array &&a) |
move assignment operator | |
type_id_t | type_id () const |
get type id More... | |
size_t | rank () const |
return rank of array More... | |
shape_t | shape () const |
return shape More... | |
template<typename CTYPE > | |
CTYPE | shape () const |
return shape in an arbitrary container More... | |
size_t | size () const |
return number of elements More... | |
value | operator[] (size_t i) const |
get value at index i More... | |
value | at (size_t i) const |
get value at index i More... | |
value_ref | operator[] (size_t i) |
get a reference to index i More... | |
value_ref | at (size_t i) |
get element at index i | |
value_ref | operator() (const element_index &index) |
get reference to element More... | |
value | operator() (const element_index &index) const |
get element value More... | |
string | type_name () const |
return the type name | |
iterator | begin () |
get iterator to first element | |
iterator | end () |
get iterator to last+1 element | |
const_iterator | begin () const |
get const iterator to first element | |
const_iterator | end () const |
get const iterator to last+1 element | |
const void * | data () const |
get const pointer to data | |
void * | data () |
get pointer to data | |
Private Types | |
typedef std::unique_ptr < array_holder_interface > | pointer_type |
local pointer type used to hold the array | |
Static Private Member Functions | |
static void | _throw_not_allocated_error (const exception_record &r) |
throw exception More... | |
static void | _check_pointer (const pointer_type &ptr, const exception_record &r) |
check pointer More... | |
Private Attributes | |
pointer_type | _ptr |
pointer to an instance of array_holder | |
This type erasure can hold all kind of array types provides by libpnicore. It takes entire ownership over the array it holds. The construction is fairly easy
! as the array_type instance is a temporary move construction will be used.
Alternatively, copy construction can be done with
! in which case the copy constructor is used to copy the array's data. It is clear that in this latter case the two objects are entirely decoupled. Changing a value in a will not influence the original instance data.
Like any other array in libpnicore an instance of array can be considered as a one dimensional container providing linear access to the data stored in it by means of iterators, the [] operator, and the at() method. Like standard C++ container only the latter method ensures index checking. See code examples at the various member functions for more detail about the methods.
typedef array_iterator<1> pni::core::array::const_iterator |
read only iterator
|
inlineexplicit |
This constructor creates a type erasure by copying the original data to the internal object. This constructor is called in a situation as this one
! the content of the original array data is copied to the internal array of type array_type encapsulated by the type erasure.
T | type of the object. |
o | const reference to the original object |
|
inlineexplicit |
Constructor moves the original object to the type erasure
!
T | original type |
o | rvalue reference to the original object |
|
inlinestaticprivate |
Check the internal pointer for validity. If the pointer is not valid an exception is thrown.
memory_not_allocated | if pointer is not valid |
ptr | the pointer to check |
r | the exception record |
|
inlinestaticprivate |
Static helper method that throws a MemoryNotAllcatedError if the type erasure holds no data and data access is requested by the user.
MemoryNotAllocatedError |
r | exception record where the error occured. |
value pni::core::array::at | ( | size_t | i | ) | const |
Return the content of the array at linear index i as an instance of value (thus only read only access). This method performs index checking.
IndexError | if i exceeds the size of the array |
i | linear index of the element |
value_ref pni::core::array::operator() | ( | const element_index & | index | ) |
value pni::core::array::operator() | ( | const element_index & | index | ) | const |
Returns the value of an element as an instance of value.
index | the element index |
value pni::core::array::operator[] | ( | size_t | i | ) | const |
This operator returns the content of the element with linear index i as an instance of value by which one cannot alter the data stored in the array. This operator performs no index checking.
i | linear index of the element |
value_ref pni::core::array::operator[] | ( | size_t | i | ) |
Return a reference to the element at linear index i. The reference is provided as an instance of value_ref via which the content of the array can be altered. This operator performs no index checking.
i | linear index i |
size_t pni::core::array::rank | ( | ) | const |
Return the number of dimensions the multidimensional array spans. In the case of a scalar the return value of this method is 0.
shape_t pni::core::array::shape | ( | ) | const |
Return the number of elements along each dimension of the array as an instance of shape_t. In the case of a scalar value the return value is empty (size=0).
CTYPE pni::core::array::shape | ( | ) | const |
Return the number of dimensions along each dimension as a container type specified by the user.
! If the wrapped type is a scalar an empty instance of CTYPE is returned.
CTYPE | container type |
size_t pni::core::array::size | ( | ) | const |
Returns the total number of elements stored in the array. In the case of a scalar the size is 1.
type_id_t pni::core::array::type_id | ( | ) | const |
Return the type id of the data held by an instance of array.