![]() |
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 ElementType & | Reference |
Reference type of the accessed element. | |
typedef const ElementType & | ConstReference |
Reference type of the accessed constant element. | |
typedef VT::Iterator | Iterator |
Iterator type of the accessed sparse vector. | |
Public Member Functions | |
Constructors | |
VectorAccessProxy (VT &sv, size_t i) | |
Initialization constructor for a VectorAccessProxy. | |
VectorAccessProxy (const VectorAccessProxy &vap) | |
The copy constructor for VectorAccessProxy. | |
Operators | |
VectorAccessProxy & | operator= (const VectorAccessProxy &vap) |
Copy assignment operator for VectorAccessProxy. | |
template<typename T > | |
VectorAccessProxy & | operator= (const T &value) |
Assignment to the accessed sparse vector element. | |
template<typename T > | |
VectorAccessProxy & | operator+= (const T &value) |
Addition assignment to the accessed sparse vector element. | |
template<typename T > | |
VectorAccessProxy & | operator-= (const T &value) |
Subtraction assignment to the accessed sparse vector element. | |
template<typename T > | |
VectorAccessProxy & | operator*= (const T &value) |
Multiplication assignment to the accessed sparse vector element. | |
template<typename T > | |
VectorAccessProxy & | operator/= (const T &value) |
Division assignment to the accessed sparse vector element. | |
Conversion operator | |
operator Reference () const | |
Conversion to the accessed sparse vector element. | |
Private Member Functions | |
Utility functions | |
Reference | get () const |
Returning the value of the accessed sparse vector element. | |
void | set (ConstReference value) const |
Setting the value of the accessed sparse vector element. | |
Private Attributes | |
Member variables | |
VT & | sv_ |
Reference to the accessed sparse vector. | |
size_t | i_ |
Index of the accessed sparse vector element. | |
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:
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.
|
inlineexplicit |
Initialization constructor for a VectorAccessProxy.
sv | Reference to the accessed sparse vector. |
i | The index of the accessed sparse vector element. |
|
inline |
The copy constructor for VectorAccessProxy.
vap | Sparse vector access proxy to be copied. |
|
inlineprivate |
Returning the value of the accessed sparse vector element.
|
inline |
Conversion to the accessed sparse vector element.
|
inline |
Multiplication assignment to the accessed sparse vector element.
value | The right-hand side value for the multiplication. |
|
inline |
Addition assignment to the accessed sparse vector element.
value | The right-hand side value to be added to the sparse vector element. |
|
inline |
Subtraction assignment to the accessed sparse vector element.
value | The right-hand side value to be subtracted from the sparse vector element. |
|
inline |
Division assignment to the accessed sparse vector element.
value | The right-hand side value for the division. |
|
inline |
Copy assignment operator for VectorAccessProxy.
vap | Sparse vector access proxy to be copied. |
|
inline |
Assignment to the accessed sparse vector element.
value | The new value of the sparse vector element. |
|
inlineprivate |
Setting the value of the accessed sparse vector element.
value | Reference to the new value of the sparse vector element. |