Blaze 3.9
VectorAccessProxy.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_SPARSE_VECTORACCESSPROXY_H_
36#define _BLAZE_MATH_SPARSE_VECTORACCESSPROXY_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
43#include <utility>
44#include <blaze/math/Aliases.h>
54#include <blaze/util/Assert.h>
55#include <blaze/util/Types.h>
56
57
58namespace blaze {
59
60//=================================================================================================
61//
62// CLASS DEFINITION
63//
64//=================================================================================================
65
66//*************************************************************************************************
98template< typename VT > // Type of the sparse vector
100 : public Proxy< VectorAccessProxy<VT>, ElementType_t<VT> >
101{
102 public:
103 //**Type definitions****************************************************************************
106 //**********************************************************************************************
107
108 //**Constructors********************************************************************************
111 explicit inline VectorAccessProxy( VT& sv, size_t i );
112
113 VectorAccessProxy( const VectorAccessProxy& ) = default;
115 //**********************************************************************************************
116
117 //**Destructor**********************************************************************************
120 inline ~VectorAccessProxy();
122 //**********************************************************************************************
123
124 //**Operators***********************************************************************************
127 inline const VectorAccessProxy& operator=( const VectorAccessProxy& vap ) const;
128
129 template< typename T >
130 inline const VectorAccessProxy& operator=( initializer_list<T> list ) const;
131
132 template< typename T >
133 inline const VectorAccessProxy& operator=( initializer_list< initializer_list<T> > list ) const;
134
135 template< typename T > inline const VectorAccessProxy& operator= ( const T& value ) const;
136 template< typename T > inline const VectorAccessProxy& operator+=( const T& value ) const;
137 template< typename T > inline const VectorAccessProxy& operator-=( const T& value ) const;
138 template< typename T > inline const VectorAccessProxy& operator*=( const T& value ) const;
139 template< typename T > inline const VectorAccessProxy& operator/=( const T& value ) const;
140 template< typename T > inline const VectorAccessProxy& operator%=( const T& value ) const;
142 //**********************************************************************************************
143
144 //**Utility functions***************************************************************************
147 inline RawReference get() const noexcept;
148 inline bool isRestricted() const noexcept;
150 //**********************************************************************************************
151
152 //**Conversion operator*************************************************************************
155 inline operator RawReference() const noexcept;
157 //**********************************************************************************************
158
159 private:
160 //**Member variables****************************************************************************
163 VT& sv_;
164 size_t i_;
166 //**********************************************************************************************
167
168 //**Forbidden operations************************************************************************
171 void* operator&() const;
173 //**********************************************************************************************
174
175 //**Compile time checks*************************************************************************
179 //**********************************************************************************************
180};
181//*************************************************************************************************
182
183
184
185
186//=================================================================================================
187//
188// CONSTRUCTORS
189//
190//=================================================================================================
191
192//*************************************************************************************************
198template< typename VT > // Type of the sparse vector
199inline VectorAccessProxy<VT>::VectorAccessProxy( VT& sv, size_t i )
200 : sv_( sv ) // Reference to the accessed sparse vector
201 , i_ ( i ) // Index of the accessed sparse vector element
202{
203 const Iterator_t<VT> element( sv_.find( i_ ) );
204 if( element == sv_.end() )
205 sv_.insert( i_, RepresentedType{} );
206}
207//*************************************************************************************************
208
209
210
211
212//=================================================================================================
213//
214// DESTRUCTOR
215//
216//=================================================================================================
217
218//*************************************************************************************************
221template< typename VT > // Type of the sparse vector
223{
224 const Iterator_t<VT> element( sv_.find( i_ ) );
225 if( element != sv_.end() && isDefault<strict>( element->value() ) )
226 sv_.erase( element );
227}
228//*************************************************************************************************
229
230
231
232
233//=================================================================================================
234//
235// OPERATORS
236//
237//=================================================================================================
238
239//*************************************************************************************************
245template< typename VT > // Type of the sparse vector
247{
248 const Iterator_t<VT> element( vap.sv_.find( vap.i_ ) );
249 const auto& source( element != vap.sv_.end() ? element->value() : RepresentedType{} );
250
251 get() = source;
252 return *this;
253}
254//*************************************************************************************************
255
256
257//*************************************************************************************************
263template< typename VT > // Type of the sparse vector
264template< typename T > // Type of the right-hand side elements
265inline const VectorAccessProxy<VT>&
266 VectorAccessProxy<VT>::operator=( initializer_list<T> list ) const
267{
268 get() = list;
269 return *this;
270}
271//*************************************************************************************************
272
273
274//*************************************************************************************************
280template< typename VT > // Type of the sparse vector
281template< typename T > // Type of the right-hand side elements
282inline const VectorAccessProxy<VT>&
283 VectorAccessProxy<VT>::operator=( initializer_list< initializer_list<T> > list ) const
284{
285 get() = list;
286 return *this;
287}
288//*************************************************************************************************
289
290
291//*************************************************************************************************
297template< typename VT > // Type of the sparse vector
298template< typename T > // Type of the right-hand side value
299inline const VectorAccessProxy<VT>& VectorAccessProxy<VT>::operator=( const T& value ) const
300{
301 get() = value;
302 return *this;
303}
304//*************************************************************************************************
305
306
307//*************************************************************************************************
313template< typename VT > // Type of the sparse vector
314template< typename T > // Type of the right-hand side value
315inline const VectorAccessProxy<VT>& VectorAccessProxy<VT>::operator+=( const T& value ) const
316{
317 get() += value;
318 return *this;
319}
320//*************************************************************************************************
321
322
323//*************************************************************************************************
329template< typename VT > // Type of the sparse vector
330template< typename T > // Type of the right-hand side value
331inline const VectorAccessProxy<VT>& VectorAccessProxy<VT>::operator-=( const T& value ) const
332{
333 get() -= value;
334 return *this;
335}
336//*************************************************************************************************
337
338
339//*************************************************************************************************
345template< typename VT > // Type of the sparse vector
346template< typename T > // Type of the right-hand side value
347inline const VectorAccessProxy<VT>& VectorAccessProxy<VT>::operator*=( const T& value ) const
348{
349 get() *= value;
350 return *this;
351}
352//*************************************************************************************************
353
354
355//*************************************************************************************************
361template< typename VT > // Type of the sparse vector
362template< typename T > // Type of the right-hand side value
363inline const VectorAccessProxy<VT>& VectorAccessProxy<VT>::operator/=( const T& value ) const
364{
365 get() /= value;
366 return *this;
367}
368//*************************************************************************************************
369
370
371//*************************************************************************************************
381template< typename VT > // Type of the sparse vector
382template< typename T > // Type of the right-hand side value
383inline const VectorAccessProxy<VT>& VectorAccessProxy<VT>::operator%=( const T& value ) const
384{
385 get() %= value;
386 return *this;
387}
388//*************************************************************************************************
389
390
391
392
393//=================================================================================================
394//
395// UTILITY FUNCTIONS
396//
397//=================================================================================================
398
399//*************************************************************************************************
404template< typename VT > // Type of the sparse vector
406{
407 Iterator_t<VT> element( sv_.find( i_ ) );
408 if( element == sv_.end() )
409 element = sv_.insert( i_, RepresentedType{} );
410 BLAZE_INTERNAL_ASSERT( element != sv_.end(), "Missing vector element detected" );
411 return element->value();
412}
413//*************************************************************************************************
414
415
416//*************************************************************************************************
421template< typename VT > // Type of the sparse vector
422inline bool VectorAccessProxy<VT>::isRestricted() const noexcept
423{
424 return false;
425}
426//*************************************************************************************************
427
428
429
430
431//=================================================================================================
432//
433// CONVERSION OPERATOR
434//
435//=================================================================================================
436
437//*************************************************************************************************
442template< typename VT > // Type of the sparse vector
444{
445 return get();
446}
447//*************************************************************************************************
448
449
450
451
452//=================================================================================================
453//
454// GLOBAL FUNCTIONS
455//
456//=================================================================================================
457
458//*************************************************************************************************
461template< typename VT >
462void swap( const VectorAccessProxy<VT>& a, const VectorAccessProxy<VT>& b ) noexcept;
463
464template< typename VT, typename T >
465void swap( const VectorAccessProxy<VT>& a, T& b ) noexcept;
466
467template< typename T, typename VT >
468void swap( T& a, const VectorAccessProxy<VT>& v ) noexcept;
470//*************************************************************************************************
471
472
473//*************************************************************************************************
481template< typename VT >
482inline void swap( const VectorAccessProxy<VT>& a, const VectorAccessProxy<VT>& b ) noexcept
483{
484 using std::swap;
485
486 swap( a.get(), b.get() );
487}
488//*************************************************************************************************
489
490
491//*************************************************************************************************
499template< typename VT, typename T >
500inline void swap( const VectorAccessProxy<VT>& a, T& b ) noexcept
501{
502 using std::swap;
503
504 swap( a.get(), b );
505}
506//*************************************************************************************************
507
508
509//*************************************************************************************************
517template< typename T, typename VT >
518inline void swap( T& a, const VectorAccessProxy<VT>& b ) noexcept
519{
520 using std::swap;
521
522 swap( a, b.get() );
523}
524//*************************************************************************************************
525
526} // namespace blaze
527
528#endif
Header file for auxiliary alias declarations.
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.
Definition: Aliases.h:190
typename T::Iterator Iterator_t
Alias declaration for nested Iterator type definitions.
Definition: Aliases.h:210
Header file for run time assertion macros.
Header file for the isDefault shim.
Header file for the isOne shim.
Header file for the isReal shim.
Header file for the relaxation flag enumeration.
Proxy base class.
Definition: Proxy.h:169
Access proxy for sparse, N-dimensional vectors.
Definition: VectorAccessProxy.h:101
const VectorAccessProxy & operator=(const VectorAccessProxy &vap) const
Copy assignment operator for VectorAccessProxy.
Definition: VectorAccessProxy.h:246
RawReference get() const noexcept
Returning the value of the accessed sparse vector element.
Definition: VectorAccessProxy.h:405
~VectorAccessProxy()
The destructor for VectorAccessProxy.
Definition: VectorAccessProxy.h:222
RepresentedType & RawReference
Raw reference to the represented element.
Definition: VectorAccessProxy.h:105
size_t i_
Index of the accessed sparse vector element.
Definition: VectorAccessProxy.h:164
VectorAccessProxy(VT &sv, size_t i)
Initialization constructor for a VectorAccessProxy.
Definition: VectorAccessProxy.h:199
VT & sv_
Reference to the accessed sparse vector.
Definition: VectorAccessProxy.h:163
ElementType_t< VT > RepresentedType
Type of the represented sparse vector element.
Definition: VectorAccessProxy.h:104
bool isRestricted() const noexcept
Returns whether the proxy represents a restricted sparse vector element..
Definition: VectorAccessProxy.h:422
Constraint on the data type.
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_VECTOR_TYPE(T)
Constraint on the data type.
Definition: SparseVector.h:61
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.
Definition: Assert.h:101
void swap(T &a, const VectorAccessProxy< VT > &v) noexcept
Swapping the contents of an access proxy with another element.
Definition: VectorAccessProxy.h:518
Header file for the extended initializer_list functionality.
Header file for the Proxy class.
Header file for the clear shim.
Header file for the isZero shim.
Header file for basic type definitions.