libpnicore
Public Types | Public Member Functions | Private Types | Static Private Member Functions | Private Attributes
pni::core::array Class Reference

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
 
arrayoperator= (const array &a)
 copy assignment operator
 
arrayoperator= (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
 

Detailed Description

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

array a = array_type::create({104,200});

! as the array_type instance is a temporary move construction will be used.

Alternatively, copy construction can be done with

auto data = array_type::create({104,200});
array a = data;

! 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.

Member Typedef Documentation

read only iterator

Constructor & Destructor Documentation

template<typename T , typename = typename std::enable_if< !std::is_same<array,typename std::remove_reference<T>::type >::value >::type>
pni::core::array::array ( const T &  o)
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

array_type data;
....
array a(data);

! the content of the original array data is copied to the internal array of type array_type encapsulated by the type erasure.

Template Parameters
Ttype of the object.
Parameters
oconst reference to the original object
template<typename T , typename = typename std::enable_if< !std::is_same<array,typename std::remove_reference<T>::type >::value >::type>
pni::core::array::array ( T &&  o)
inlineexplicit

Constructor moves the original object to the type erasure

array a = DArray<UInt16>(shape_t{1024,1024});

!

Template Parameters
Toriginal type
Parameters
orvalue reference to the original object

Member Function Documentation

static void pni::core::array::_check_pointer ( const pointer_type ptr,
const exception_record r 
)
inlinestaticprivate

Check the internal pointer for validity. If the pointer is not valid an exception is thrown.

Exceptions
memory_not_allocatedif pointer is not valid
Parameters
ptrthe pointer to check
rthe exception record
static void pni::core::array::_throw_not_allocated_error ( const exception_record r)
inlinestaticprivate

Static helper method that throws a MemoryNotAllcatedError if the type erasure holds no data and data access is requested by the user.

Exceptions
MemoryNotAllocatedError
Parameters
rexception 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.

Exceptions
IndexErrorif i exceeds the size of the array
Parameters
ilinear index of the element
Returns
element at index i as instance of value
value_ref pni::core::array::operator() ( const element_index index)

Returns a reference to an array element. The reference is represented by an instance of value_ref.

Parameters
indexthe index of the element
Returns
value_ref with reference to the element
value pni::core::array::operator() ( const element_index index) const

Returns the value of an element as an instance of value.

Parameters
indexthe element index
Returns
the value as an instance of value
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.

Parameters
ilinear index of the element
Returns
value holding the content of element i
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.

Parameters
ilinear index i
Returns
reference to element 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.

Returns
number of dimensions
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).

Returns
shape of the array
template<typename CTYPE >
CTYPE pni::core::array::shape ( ) const

Return the number of dimensions along each dimension as a container type specified by the user.

auto s = array.shape<std::list<size_t> >();

! If the wrapped type is a scalar an empty instance of CTYPE is returned.

Template Parameters
CTYPEcontainer type
Returns
instance of CTYPE
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.

Returns
number of elements
type_id_t pni::core::array::type_id ( ) const

Return the type id of the data held by an instance of array.

Returns
type id.

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