All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VectorAccessProxy.h
Go to the documentation of this file.
1 //=================================================================================================
20 //=================================================================================================
21 
22 #ifndef _BLAZE_MATH_SPARSE_VECTORACCESSPROXY_H_
23 #define _BLAZE_MATH_SPARSE_VECTORACCESSPROXY_H_
24 
25 
26 //*************************************************************************************************
27 // Includes
28 //*************************************************************************************************
29 
30 #include <blaze/util/Assert.h>
31 #include <blaze/util/Types.h>
32 
33 
34 namespace blaze {
35 
36 //=================================================================================================
37 //
38 // CLASS DEFINITION
39 //
40 //=================================================================================================
41 
42 //*************************************************************************************************
74 template< typename VT > // Type of the sparse vector
76 {
77  public:
78  //**Type definitions****************************************************************************
79  typedef VT VectorType;
80  typedef typename VT::ElementType ElementType;
82  typedef const ElementType& ConstReference;
83  typedef typename VT::Iterator Iterator;
84  //**********************************************************************************************
85 
86  //**Constructors********************************************************************************
89  explicit inline VectorAccessProxy( VT& sv, size_t i );
90  inline VectorAccessProxy( const VectorAccessProxy& vap );
92  //**********************************************************************************************
93 
94  //**Destructor**********************************************************************************
95  // No explicitly declared destructor.
96  //**********************************************************************************************
97 
98  //**Operators***********************************************************************************
101  inline VectorAccessProxy& operator= ( const VectorAccessProxy& vap );
102  template< typename T > inline VectorAccessProxy& operator= ( const T& value );
103  template< typename T > inline VectorAccessProxy& operator+=( const T& value );
104  template< typename T > inline VectorAccessProxy& operator-=( const T& value );
105  template< typename T > inline VectorAccessProxy& operator*=( const T& value );
106  template< typename T > inline VectorAccessProxy& operator/=( const T& value );
108  //**********************************************************************************************
109 
110  //**Conversion operator*************************************************************************
113  inline operator Reference() const;
115  //**********************************************************************************************
116 
117  private:
118  //**Utility functions***************************************************************************
121  Reference get() const;
122  void set( ConstReference value ) const;
124  //**********************************************************************************************
125 
126  //**Member variables****************************************************************************
129  VT& sv_;
130  size_t i_;
131 
132  //**********************************************************************************************
133 };
134 //*************************************************************************************************
135 
136 
137 
138 
139 //=================================================================================================
140 //
141 // CONSTRUCTORS
142 //
143 //=================================================================================================
144 
145 //*************************************************************************************************
151 template< typename VT > // Type of the sparse vector
153  : sv_( sv ) // Reference to the accessed sparse vector
154  , i_ ( i ) // Index of the accessed sparse vector element
155 {
156  const Iterator element( sv_.find( i_ ) );
157  if( element == sv_.end() )
158  sv_.insert( i_, ElementType() );
159 }
160 //*************************************************************************************************
161 
162 
163 //*************************************************************************************************
168 template< typename VT > // Type of the sparse vector
170  : sv_( vap.sv_ ) // Reference to the accessed sparse vector
171  , i_ ( vap.i_ ) // Index of the accessed sparse vector element
172 {
173  BLAZE_INTERNAL_ASSERT( sv_.find( i_ ) != sv_.end(), "Missing vector element detected" );
174 }
175 //*************************************************************************************************
176 
177 
178 
179 
180 //=================================================================================================
181 //
182 // OPERATORS
183 //
184 //=================================================================================================
185 
186 //*************************************************************************************************
192 template< typename VT > // Type of the sparse vector
194 {
195  set( vap.get() );
196  return *this;
197 }
198 //*************************************************************************************************
199 
200 
201 //*************************************************************************************************
207 template< typename VT > // Type of the sparse vector
208 template< typename T > // Type of the right-hand side value
210 {
211  set( value );
212  return *this;
213 }
214 //*************************************************************************************************
215 
216 
217 //*************************************************************************************************
223 template< typename VT > // Type of the sparse vector
224 template< typename T > // Type of the right-hand side value
226 {
227  get() += value;
228  return *this;
229 }
230 //*************************************************************************************************
231 
232 
233 //*************************************************************************************************
239 template< typename VT > // Type of the sparse vector
240 template< typename T > // Type of the right-hand side value
242 {
243  get() -= value;
244  return *this;
245 }
246 //*************************************************************************************************
247 
248 
249 //*************************************************************************************************
255 template< typename VT > // Type of the sparse vector
256 template< typename T > // Type of the right-hand side value
258 {
259  get() *= value;
260  return *this;
261 }
262 //*************************************************************************************************
263 
264 
265 //*************************************************************************************************
271 template< typename VT > // Type of the sparse vector
272 template< typename T > // Type of the right-hand side value
274 {
275  get() /= value;
276  return *this;
277 }
278 //*************************************************************************************************
279 
280 
281 
282 
283 //=================================================================================================
284 //
285 // CONVERSION OPERATOR
286 //
287 //=================================================================================================
288 
289 //*************************************************************************************************
294 template< typename VT > // Type of the sparse vector
296 {
297  return get();
298 }
299 //*************************************************************************************************
300 
301 
302 
303 
304 //=================================================================================================
305 //
306 // UTILITY FUNCTIONS
307 //
308 //=================================================================================================
309 
310 //*************************************************************************************************
315 template< typename VT > // Type of the sparse vector
317 {
318  const Iterator element( sv_.find( i_ ) );
319  BLAZE_INTERNAL_ASSERT( element != sv_.end(), "Missing vector element detected" );
320  return element->value();
321 }
322 //*************************************************************************************************
323 
324 
325 //*************************************************************************************************
331 template< typename VT > // Type of the sparse vector
332 inline void VectorAccessProxy<VT>::set( ConstReference value ) const
333 {
334  const Iterator element( sv_.find( i_ ) );
335  BLAZE_INTERNAL_ASSERT( element != sv_.end(), "Missing vector element detected" );
336  element->value() = value;
337 }
338 //*************************************************************************************************
339 
340 } // namespace blaze
341 
342 #endif