libpnicore
Public Types | Public Member Functions | Static Public Attributes | Private Attributes
pni::core::scalar< T > Class Template Reference

Scalar template for scalar values. More...

#include <scalar.hpp>

Public Types

typedef T value_type
 native data type of the scalar
 
typedef scalar< T > array_type
 type of the scalar itself
 
typedef std::array< T, 1 > storage_type
 storage type
 
typedef scalar_iterator
< array_type
iterator
 iterator
 
typedef scalar_iterator< const
array_type
const_iterator
 const iterator
 
typedef array_view< array_typeview_type
 view type
 

Public Member Functions

 scalar ()
 default constructor
 
 scalar (const array_type &s)
 copy constructor
 
 scalar (const value_type &r)
 constructor from a scalar value
 
 ~scalar ()
 destructor
 
array_typeoperator= (const value_type &v)
 assignment from T value More...
 
array_typeoperator= (const array_type &v)
 assignment from Scalar<T> More...
 
 operator T () const
 conversion operator More...
 
operator[] (size_t) const
 get data More...
 
T & operator[] (size_t)
 get reference to data More...
 
at (size_t) const
 get data value More...
 
T & at (size_t)
 get data reference More...
 
void insert (size_t, const T &v)
 set data value More...
 
const storage_typestorage () const
 get reference to the storage object More...
 
template<typename... ITYPES>
T & operator() (ITYPES...)
 get reference to the data More...
 
template<typename... ITYPES>
operator() (ITYPES...) const
 get value of data More...
 
template<template< typename...> class CTYPE, typename... OTS>
T & operator() (const CTYPE< OTS...> &)
 get reference to data More...
 
template<template< typename...> class CTYPE, typename... OTS>
operator() (const CTYPE< OTS...> &) const
 get data value More...
 
size_t size () const
 get size More...
 
size_t rank () const
 get rank More...
 
template<typename CTYPE >
CTYPE shape () const
 get shape More...
 
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
 

Static Public Attributes

static const type_id_t type_id = type_id_map<T>::type_id
 type ID of the data type held by the scalar
 

Private Attributes

std::array< T, 1 > _data
 static buffer holding the data value
 

Detailed Description

template<typename T>
class pni::core::scalar< T >

This template is used in expression tempaltes. Its purpose is to give scalar values an array like interface.

Template Parameters
Tscalar type of the data stored.

Member Function Documentation

template<typename T>
T pni::core::scalar< T >::at ( size_t  ) const
inline

Return the value of the data stored in the instance no matter of the value of the index.

Parameters
iindex
Returns
data value
template<typename T>
T& pni::core::scalar< T >::at ( size_t  )
inline

Return a reference to the data stored in the scalar no matter what index is passed to the method.

Parameters
iindex
Returns
reference to data
template<typename T>
void pni::core::scalar< T >::insert ( size_t  ,
const T &  v 
)
inline

Method to set a data value. The index does not matter.

Parameters
iindex
vvalue
template<typename T>
pni::core::scalar< T >::operator T ( ) const
inline

Allows conversion from an instance of scalar<T> to a variable of type T.

Returns
value of type T
template<typename T>
template<typename... ITYPES>
T& pni::core::scalar< T >::operator() ( ITYPES...  )
inline

Returns the reference to the data value no matter how many or what indices are passed.

Template Parameters
ITYPESindex types
Parameters
indicesmultidimensional index
Returns
reference to data
template<typename T>
template<typename... ITYPES>
T pni::core::scalar< T >::operator() ( ITYPES...  ) const
inline

Return the value of the scalar. The number of indices or their type do not matter.

Template Parameters
ITYPESindex types
Parameters
indicesmultidimensional index
Returns
data value
template<typename T>
template<template< typename...> class CTYPE, typename... OTS>
T& pni::core::scalar< T >::operator() ( const CTYPE< OTS...> &  )
inline

Return a reference to the data. The multidimensional index is passed by a container. The number of indices or their value are ignored.

Template Parameters
CTYPEcontainer template
OTStemplate arguments for the container template
Returns
reference to the data
template<typename T>
template<template< typename...> class CTYPE, typename... OTS>
T pni::core::scalar< T >::operator() ( const CTYPE< OTS...> &  ) const
inline

Return the data value. The multidimensional index is passed by a container. The number of indices or their value are ignored.

Template Parameters
CTYPEcontainer template
OTStemplate arguments of the container template
Returns
data value
template<typename T>
array_type& pni::core::scalar< T >::operator= ( const value_type v)
inline

Assigns a value of type T to the scalar.

Parameters
vvalue to assign
Returns
reference to array_type
template<typename T>
array_type& pni::core::scalar< T >::operator= ( const array_type v)
inline

This is the most trivial case. An object of type Scalar<T> is assigned to an other object of type Scalar<T>.

Parameters
vvalue of scalar<T> to assign
Returns
reference to array_type
template<typename T>
T pni::core::scalar< T >::operator[] ( size_t  ) const
inline

Return the single data value independent of what value of i is given.

Parameters
ilinear index of the value
Returns
value of the scalar
template<typename T>
T& pni::core::scalar< T >::operator[] ( size_t  )
inline

Return a reference to the data stored in the scalar. No matter what value of i is passed to this operator - it will always return the same reference.

Parameters
iindex
Returns
reference to the scalar data
template<typename T>
size_t pni::core::scalar< T >::rank ( ) const
inline

Return the number of dimensions of the scalar. This is always 0.

Returns
0
template<typename T>
template<typename CTYPE >
CTYPE pni::core::scalar< T >::shape ( ) const
inline

Returns the shape of the scalar - this is a container with a single value 1.

Returns
container with 1
template<typename T>
size_t pni::core::scalar< T >::size ( ) const
inline

For a scalar object this method always returns 1. This is due to the fact that one needs to allocate only one block of memory of sizeof(T) bytes to hold the scalar data.

Returns
1
template<typename T>
const storage_type& pni::core::scalar< T >::storage ( ) const
inline

Return a const reference to the static buffer that holds the scalar data.

Returns
reference to buffer object

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