All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | List of all members
blaze::VectorAccessProxy< VT > Class Template Reference

Access proxy for sparse, N-dimensional vectors.The VectorAccessProxy provides safe access to the elements of a non-const sparse vector.
The proxied access to the elements of a sparse vector is necessary since it may be possible that several insertion operations happen in the same statement. The following code illustrates this with two examples by means of the CompressedVector class: More...

#include <VectorAccessProxy.h>

Public Types

typedef VT VectorType
 Type of the accessed sparse vector.
 
typedef VT::ElementType ElementType
 Type of the accessed sparse vector element.
 
typedef ElementTypeReference
 Reference type of the accessed element.
 
typedef const ElementTypeConstReference
 Reference type of the accessed constant element.
 
typedef VT::Iterator Iterator
 Iterator type of the accessed sparse vector.
 

Public Member Functions

template<typename T >
VectorAccessProxy< VT > & operator= (const T &value)
 Assignment to the accessed sparse vector element. More...
 
template<typename T >
VectorAccessProxy< VT > & operator+= (const T &value)
 Addition assignment to the accessed sparse vector element. More...
 
template<typename T >
VectorAccessProxy< VT > & operator-= (const T &value)
 Subtraction assignment to the accessed sparse vector element. More...
 
template<typename T >
VectorAccessProxy< VT > & operator*= (const T &value)
 Multiplication assignment to the accessed sparse vector element. More...
 
template<typename T >
VectorAccessProxy< VT > & operator/= (const T &value)
 Division assignment to the accessed sparse vector element. More...
 
Constructors
 VectorAccessProxy (VT &sv, size_t i)
 Initialization constructor for a VectorAccessProxy. More...
 
 VectorAccessProxy (const VectorAccessProxy &vap)
 The copy constructor for VectorAccessProxy. More...
 
Destructor
 ~VectorAccessProxy ()
 The destructor for VectorAccessProxy.
 
Operators
VectorAccessProxyoperator= (const VectorAccessProxy &vap)
 Copy assignment operator for VectorAccessProxy. More...
 
template<typename T >
VectorAccessProxyoperator= (const T &value)
 
template<typename T >
VectorAccessProxyoperator+= (const T &value)
 
template<typename T >
VectorAccessProxyoperator-= (const T &value)
 
template<typename T >
VectorAccessProxyoperator*= (const T &value)
 
template<typename T >
VectorAccessProxyoperator/= (const T &value)
 
Conversion operator
 operator Reference () const
 Conversion to the accessed sparse vector element. More...
 

Private Member Functions

Utility functions
Reference get () const
 Returning the value of the accessed sparse vector element. More...
 
void set (ConstReference value) const
 Setting the value of the accessed sparse vector element. More...
 

Private Attributes

Member variables
VT & sv_
 Reference to the accessed sparse vector.
 
size_t i_
 Index of the accessed sparse vector element.
 

Detailed Description

template<typename VT>
class blaze::VectorAccessProxy< VT >

Access proxy for sparse, N-dimensional vectors.

The VectorAccessProxy provides safe access to the elements of a non-const sparse vector.
The proxied access to the elements of a sparse vector is necessary since it may be possible that several insertion operations happen in the same statement. The following code illustrates this with two examples by means of the CompressedVector class:

CompressedVector<real> a( 5 );
// Standard usage of the subscript operator to initialize a vector element.
// Only a single vector matrix element is accessed!
a[0] = 1.0;
// Initialization of a vector element via another vector element.
// Two sparse vector accesses in one statement!
a[1] = a[0];
// Multiple accesses to elements of the sparse vector in one statement!
const real result = a[0] + a[2] + a[4];

The problem (especially with the last statement) is that several insertion operations might take place due to the access via the subscript operator. If the subscript operator would return a direct reference to one of the accessed elements, this reference might be invalidated during the evaluation of a subsequent subscript operator, which results in undefined behavior. This class provides the necessary functionality to guarantee a safe access to the sparse vector elements while preserving the intuitive use of the subscript operator.

Constructor & Destructor Documentation

template<typename VT >
blaze::VectorAccessProxy< VT >::VectorAccessProxy ( VT &  sv,
size_t  i 
)
inlineexplicit

Initialization constructor for a VectorAccessProxy.

Parameters
svReference to the accessed sparse vector.
iThe index of the accessed sparse vector element.
template<typename VT >
blaze::VectorAccessProxy< VT >::VectorAccessProxy ( const VectorAccessProxy< VT > &  vap)
inline

The copy constructor for VectorAccessProxy.

Parameters
vapSparse vector access proxy to be copied.

Member Function Documentation

template<typename VT >
VectorAccessProxy< VT >::Reference blaze::VectorAccessProxy< VT >::get ( ) const
inlineprivate

Returning the value of the accessed sparse vector element.

Returns
Reference to the accessed sparse vector element.
template<typename VT >
blaze::VectorAccessProxy< VT >::operator Reference ( ) const
inline

Conversion to the accessed sparse vector element.

Returns
Reference to the accessed sparse vector element.
template<typename VT>
template<typename T >
VectorAccessProxy<VT>& blaze::VectorAccessProxy< VT >::operator*= ( const T &  value)
inline

Multiplication assignment to the accessed sparse vector element.

Parameters
valueThe right-hand side value for the multiplication.
Returns
Reference to the assigned access proxy.
template<typename VT>
template<typename T >
VectorAccessProxy<VT>& blaze::VectorAccessProxy< VT >::operator+= ( const T &  value)
inline

Addition assignment to the accessed sparse vector element.

Parameters
valueThe right-hand side value to be added to the sparse vector element.
Returns
Reference to the assigned access proxy.
template<typename VT>
template<typename T >
VectorAccessProxy<VT>& blaze::VectorAccessProxy< VT >::operator-= ( const T &  value)
inline

Subtraction assignment to the accessed sparse vector element.

Parameters
valueThe right-hand side value to be subtracted from the sparse vector element.
Returns
Reference to the assigned access proxy.
template<typename VT>
template<typename T >
VectorAccessProxy<VT>& blaze::VectorAccessProxy< VT >::operator/= ( const T &  value)
inline

Division assignment to the accessed sparse vector element.

Parameters
valueThe right-hand side value for the division.
Returns
Reference to the assigned access proxy.
template<typename VT >
VectorAccessProxy< VT > & blaze::VectorAccessProxy< VT >::operator= ( const VectorAccessProxy< VT > &  vap)
inline

Copy assignment operator for VectorAccessProxy.

Parameters
vapSparse vector access proxy to be copied.
Returns
Reference to the assigned access proxy.
template<typename VT>
template<typename T >
VectorAccessProxy<VT>& blaze::VectorAccessProxy< VT >::operator= ( const T &  value)
inline

Assignment to the accessed sparse vector element.

Parameters
valueThe new value of the sparse vector element.
Returns
Reference to the assigned access proxy.
template<typename VT >
void blaze::VectorAccessProxy< VT >::set ( ConstReference  value) const
inlineprivate

Setting the value of the accessed sparse vector element.

Parameters
valueReference to the new value of the sparse vector element.
Returns
void

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