Chemical Data Processing Library C++ API - Version 1.4.0
Public Types | Public Member Functions | List of all members
CDPL::Math::SparseContainerElement< C, K > Class Template Reference

Proxy that exposes a single (key, value) entry of a sparse container as a writable reference. More...

#include <SparseContainerElement.hpp>

Public Types

typedef C ContainerType
 The sparse container type the proxy references. More...
 
typedef K KeyType
 The key type used to address an entry of the container. More...
 
typedef ContainerType::ValueType ValueType
 The value type stored in the container. More...
 
typedef ContainerType::SizeType SizeType
 The size type used by the container. More...
 
typedef ValueTypeReference
 Mutable reference type to a value. More...
 
typedef ContainerType::ConstReference ConstReference
 Constant reference type to a value (as defined by the container). More...
 
typedef ContainerType::ArrayType ArrayType
 Underlying associative-array type of the container (typically a std::map / std::unordered_map specialization). More...
 

Public Member Functions

 SparseContainerElement (ContainerType &c, KeyType key)
 Constructs the proxy for the (key, value) entry of the sparse container c. More...
 
SparseContainerElementoperator= (const SparseContainerElement &p)
 Copies the value pointed to by p into the entry pointed to by this proxy. More...
 
template<typename D >
SparseContainerElementoperator= (const D &d)
 Assigns the value d to the entry pointed to by this proxy. More...
 
template<typename D >
SparseContainerElementoperator+= (const D &d)
 Adds d to the value of the entry pointed to by this proxy. More...
 
template<typename D >
SparseContainerElementoperator-= (const D &d)
 Subtracts d from the value of the entry pointed to by this proxy. More...
 
template<typename D >
SparseContainerElementoperator*= (const D &d)
 Multiplies the value of the entry pointed to by this proxy by d. More...
 
template<typename D >
SparseContainerElementoperator/= (const D &d)
 Divides the value of the entry pointed to by this proxy by d. More...
 
template<typename D >
bool operator== (const D &d) const
 Tests the value of the entry pointed to by this proxy for equality with d. More...
 
template<typename D >
bool operator!= (const D &d) const
 Tests the value of the entry pointed to by this proxy for inequality with d. More...
 
 operator ConstReference () const
 Implicit conversion to a const reference to the value of the entry pointed to by this proxy (returns a default-constructed value when the entry does not exist in the underlying storage). More...
 

Detailed Description

template<typename C, typename K = typename C::KeyType>
class CDPL::Math::SparseContainerElement< C, K >

Proxy that exposes a single (key, value) entry of a sparse container as a writable reference.

Reading the proxy returns the value associated with key (or a default-constructed value if no entry exists). Writing to the proxy inserts/updates the entry; assigning the default-constructed value removes the entry from the underlying sparse storage.

Template Parameters
CThe sparse container type (must expose KeyType, ValueType, SizeType, ConstReference, ArrayType and getData()).
KThe key type (defaults to C::KeyType).

Member Typedef Documentation

◆ ContainerType

template<typename C , typename K = typename C::KeyType>
typedef C CDPL::Math::SparseContainerElement< C, K >::ContainerType

The sparse container type the proxy references.

◆ KeyType

template<typename C , typename K = typename C::KeyType>
typedef K CDPL::Math::SparseContainerElement< C, K >::KeyType

The key type used to address an entry of the container.

◆ ValueType

template<typename C , typename K = typename C::KeyType>
typedef ContainerType::ValueType CDPL::Math::SparseContainerElement< C, K >::ValueType

The value type stored in the container.

◆ SizeType

template<typename C , typename K = typename C::KeyType>
typedef ContainerType::SizeType CDPL::Math::SparseContainerElement< C, K >::SizeType

The size type used by the container.

◆ Reference

template<typename C , typename K = typename C::KeyType>
typedef ValueType& CDPL::Math::SparseContainerElement< C, K >::Reference

Mutable reference type to a value.

◆ ConstReference

template<typename C , typename K = typename C::KeyType>
typedef ContainerType::ConstReference CDPL::Math::SparseContainerElement< C, K >::ConstReference

Constant reference type to a value (as defined by the container).

◆ ArrayType

template<typename C , typename K = typename C::KeyType>
typedef ContainerType::ArrayType CDPL::Math::SparseContainerElement< C, K >::ArrayType

Underlying associative-array type of the container (typically a std::map / std::unordered_map specialization).

Constructor & Destructor Documentation

◆ SparseContainerElement()

template<typename C , typename K = typename C::KeyType>
CDPL::Math::SparseContainerElement< C, K >::SparseContainerElement ( ContainerType c,
KeyType  key 
)
inline

Constructs the proxy for the (key, value) entry of the sparse container c.

Parameters
cThe sparse container.
keyThe key of the addressed entry.

Member Function Documentation

◆ operator=() [1/2]

template<typename C , typename K = typename C::KeyType>
SparseContainerElement& CDPL::Math::SparseContainerElement< C, K >::operator= ( const SparseContainerElement< C, K > &  p)
inline

Copies the value pointed to by p into the entry pointed to by this proxy.

Parameters
pThe source proxy.
Returns
A reference to itself.

◆ operator=() [2/2]

template<typename C , typename K = typename C::KeyType>
template<typename D >
SparseContainerElement& CDPL::Math::SparseContainerElement< C, K >::operator= ( const D &  d)
inline

Assigns the value d to the entry pointed to by this proxy.

If d equals the default-constructed value, the entry is removed from the underlying sparse storage.

Template Parameters
DThe type of the assigned value (convertible to ValueType).
Parameters
dThe value to assign.
Returns
A reference to itself.

◆ operator+=()

template<typename C , typename K = typename C::KeyType>
template<typename D >
SparseContainerElement& CDPL::Math::SparseContainerElement< C, K >::operator+= ( const D &  d)
inline

Adds d to the value of the entry pointed to by this proxy.

Template Parameters
DThe type of the addend (must support value += d).
Parameters
dThe value to add.
Returns
A reference to itself.

◆ operator-=()

template<typename C , typename K = typename C::KeyType>
template<typename D >
SparseContainerElement& CDPL::Math::SparseContainerElement< C, K >::operator-= ( const D &  d)
inline

Subtracts d from the value of the entry pointed to by this proxy.

Template Parameters
DThe type of the subtrahend (must support value -= d).
Parameters
dThe value to subtract.
Returns
A reference to itself.

◆ operator*=()

template<typename C , typename K = typename C::KeyType>
template<typename D >
SparseContainerElement& CDPL::Math::SparseContainerElement< C, K >::operator*= ( const D &  d)
inline

Multiplies the value of the entry pointed to by this proxy by d.

Template Parameters
DThe type of the multiplier (must support value *= d).
Parameters
dThe multiplier.
Returns
A reference to itself.

◆ operator/=()

template<typename C , typename K = typename C::KeyType>
template<typename D >
SparseContainerElement& CDPL::Math::SparseContainerElement< C, K >::operator/= ( const D &  d)
inline

Divides the value of the entry pointed to by this proxy by d.

Template Parameters
DThe type of the divisor (must support value /= d).
Parameters
dThe divisor.
Returns
A reference to itself.

◆ operator==()

template<typename C , typename K = typename C::KeyType>
template<typename D >
bool CDPL::Math::SparseContainerElement< C, K >::operator== ( const D &  d) const
inline

Tests the value of the entry pointed to by this proxy for equality with d.

Template Parameters
DThe type of the right-hand side (must support value == d).
Parameters
dThe value to compare against.
Returns
true if the entry's value equals d, and false otherwise.

◆ operator!=()

template<typename C , typename K = typename C::KeyType>
template<typename D >
bool CDPL::Math::SparseContainerElement< C, K >::operator!= ( const D &  d) const
inline

Tests the value of the entry pointed to by this proxy for inequality with d.

Template Parameters
DThe type of the right-hand side (must support value != d).
Parameters
dThe value to compare against.
Returns
true if the entry's value differs from d, and false otherwise.

◆ operator ConstReference()

template<typename C , typename K = typename C::KeyType>
CDPL::Math::SparseContainerElement< C, K >::operator ConstReference ( ) const
inline

Implicit conversion to a const reference to the value of the entry pointed to by this proxy (returns a default-constructed value when the entry does not exist in the underlying storage).

Returns
A const reference to the value.

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