MOOCHO (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AbstractLinAlgPack_GenPermMatrixSliceIterator.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
5 // Copyright (2003) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #ifndef GEN_PERM_MATRIX_SLICE_ITERATOR_H
43 #define GEN_PERM_MATRIX_SLICE_ITERATOR_H
44 
45 #include <assert.h>
46 
47 #include <iterator>
48 
50 
51 namespace AbstractLinAlgPack {
52 
53 namespace GenPermMatrixSliceIteratorPack {
54 
57 
62 template< class T >
64 public:
66  typedef T index_type;
68  typedef ptrdiff_t difference_type;
71  difference_type row_off
72  , difference_type col_off
73  , index_type row_i
74  , index_type col_j
75  )
76  :
77  row_off_(row_off), col_off_(col_off), row_i_(row_i), col_j_(col_j)
78  {}
83 };
84 
88 template< class T >
90 public:
92  typedef T index_type;
94  typedef ptrdiff_t difference_type;
97  difference_type row_off
98  , difference_type col_off
99  , index_type row_i[]
100  , index_type col_j[]
101  , size_type nz
102  );
104  void bind_view( const row_col_value_type<T>& val );
108  index_type row_i() const;
110  index_type col_j() const;
112  index_type* row_i_ptr() const;
116  operator const external_row_col_value_type<T>() const
117  {
119  }
122  {
125  *row_i_ = val.row_i_;
126  *col_j_ = val.col_j_;
127  return *this;
128  }
129 
130 private:
136  int k_; // zero based
138  void assert_in_range() const;
141 
142 }; // end class row_col_value_type
143 
145 template< class T >
146 inline
148 {
149  row_col_value_type<T> tmp = v1;
150  v1 = v2;
151  v2 = tmp;
152 }
153 
157 template< class T >
159 #if defined(_WINDOWS) || defined(_INTEL_CXX) || defined(_PG_CXX)
160  : public std::iterator< std::random_access_iterator_tag, row_col_value_type<T>, ptrdiff_t >
161 #endif
162 {
163 public:
165  typedef T index_type;
167  typedef std::random_access_iterator_tag iterator_category;
175  typedef ptrdiff_t difference_type;
180  difference_type row_off
181  ,difference_type col_off
182  ,index_type row_i[]
183  ,index_type col_j[]
184  ,size_type nz // Number of elements in row_i[] and col_j[]
185  );
191  reference operator*() const;
193  pointer operator->() const;
205  const row_col_iterator<T> operator++(int);
209  const row_col_iterator<T> operator--(int);
213  bool operator<( const row_col_iterator<T>& itr) const;
215  bool operator<=( const row_col_iterator<T>& itr) const;
217  bool operator>( const row_col_iterator<T>& itr) const;
219  bool operator>=( const row_col_iterator<T>& itr) const;
221  bool operator==( const row_col_iterator<T>& itr) const;
223  bool operator!=( const row_col_iterator<T>& itr) const;
225  bool operator!() const;
226 
227 private:
229 
230 }; // end class row_col_iterator<T>
231 
232 // //////////////////////////////////////////////////////////
233 // Inline members for row_col_value_type<T>
234 
235 template<class T>
236 inline
238  difference_type row_off
239  , difference_type col_off
240  , index_type row_i[]
241  , index_type col_j[]
242  , size_type nz
243  )
244  :
245  row_off_(row_off)
246  ,col_off_(col_off)
247  ,row_i_(row_i)
248  ,col_j_(col_j)
249  ,nz_(nz)
250  ,k_(0)
251 {}
252 
253 template<class T>
254 inline
256 {
257  row_off_ = val.row_off_;
258  col_off_ = val.col_off_;
259  row_i_ = val.row_i_;
260  col_j_ = val.col_j_;
261  nz_ = val.nz_;
262  k_ = val.k_;
263 }
264 
265 template< class T >
266 inline
268 {
269  row_i_ += d;
270  col_j_ += d;
271  k_ += d;
272 }
273 
274 template< class T >
275 inline
277 {
278  assert_in_range();
279  return *row_i_ + row_off_;
280 }
281 
282 template< class T >
283 inline
285 {
286  assert_in_range();
287  return *col_j_ + col_off_;
288 }
289 
290 template< class T >
291 inline
293 {
294  return row_i_;
295 }
296 
297 template< class T >
298 inline
300  const row_col_value_type<T>& val )
301 {
302  *row_i_ = *val.row_i_;
303  *col_j_ = *val.col_j_;
304  return *this;
305 }
306 
307 template< class T >
308 inline
310 {
311  // ToDo: Finish this!
312  TEUCHOS_TEST_FOR_EXCEPT( !( 0 <= k_ && k_ < nz_ ) );
313 }
314 
316 void GPMS_row_col_iterator_assert_not_null(const void* p);
317 
318 // //////////////////////////////////////////////////////////
319 // Inline members for row_col_iterator<T>
320 
321 template< class T >
322 inline
324  :
325  value_(0,0,NULL,NULL,0)
326 {}
327 
328 template< class T >
329 inline
331  difference_type row_off
332  ,difference_type col_off
333  ,index_type row_i[]
334  ,index_type col_j[]
335  ,size_type nz
336  )
337  :
338  value_(row_off,col_off,row_i,col_j,nz)
339 {}
340 
341 template< class T >
342 inline
344 {
345  value_.bind_view( itr.value_ );
346  return *this;
347 }
348 
349 template< class T >
350 inline
353 {
354  GPMS_row_col_iterator_assert_not_null(value_.row_i_ptr());
355  return value_;
356 }
357 
358 
359 template< class T >
360 inline
363 {
364  GPMS_row_col_iterator_assert_not_null(value_.row_i_ptr());
365  return value_;
366 }
367 
368 template< class T >
369 inline
372 {
373  GPMS_row_col_iterator_assert_not_null(value_.row_i_ptr());
374  return &value_;
375 }
376 
377 template< class T >
378 inline
381 {
382  row_col_iterator<T> itr = *this;
383  itr.value_.increment(d);
384  return itr;
385 }
386 
387 template< class T >
388 inline
391 {
392  row_col_iterator<T> itr = *this;
393  itr.value_.increment(-d);
394  return itr;
395 }
396 
397 template< class T >
398 inline
401 {
402  value_.increment(d);
403  return *this;
404 }
405 
406 template< class T >
407 inline
410 {
411  value_.increment(-d);
412  return *this;
413 }
414 
415 template< class T >
416 inline
419 {
420  value_.increment(1);
421  return *this;
422 }
423 
424 template< class T >
425 inline
428 {
429  row_col_iterator<T> itr = *this;
430  value_.increment(1);
431  return itr;
432 }
433 
434 template< class T >
435 inline
438 {
439  value_.increment(-1);
440  return *this;
441 }
442 
443 template< class T >
444 inline
447 {
448  row_col_iterator<T> itr = *this;
449  value_.increment(-1);
450  return itr;
451 }
452 
453 template< class T >
454 inline
457 {
458  return value_.row_i_ptr() - itr.value_.row_i_ptr();
459 }
460 
461 template< class T >
462 inline
464 {
465  return ( value_.row_i_ptr() && itr.value_.row_i_ptr() )
466  && ( value_.row_i_ptr() < itr.value_.row_i_ptr() );
467 }
468 
469 template< class T >
470 inline
472 {
473  return ( value_.row_i_ptr() && itr.value_.row_i_ptr() )
474  && ( value_.row_i_ptr() <= itr.value_.row_i_ptr() );
475 }
476 
477 template< class T >
478 inline
480 {
481  return ( value_.row_i_ptr() && itr.value_.row_i_ptr() )
482  && ( value_.row_i_ptr() > itr.value_.row_i_ptr() );
483 }
484 
485 template< class T >
486 inline
488 {
489  return ( value_.row_i_ptr() && itr.value_.row_i_ptr() )
490  && ( value_.row_i_ptr() >= itr.value_.row_i_ptr() );
491 }
492 
493 template< class T >
494 inline
496 {
497  return ( value_.row_i_ptr() && itr.value_.row_i_ptr() )
498  && ( value_.row_i_ptr() == itr.value_.row_i_ptr() );
499 }
500 
501 template< class T >
502 inline
504 {
505  return ( value_.row_i_ptr() && itr.value_.row_i_ptr() )
506  && ( value_.row_i_ptr() != itr.value_.row_i_ptr() );
507 }
508 
509 template< class T >
510 inline
512 {
513  return value_.row_i_ptr() == NULL;
514 }
515 
516 } // end namespace GenPermMatrixSliceIteratorPack
517 
518 } // end namespace AbstractLinAlgPack
519 
520 #endif // GEN_PERM_MATRIX_SLICE_ITERATOR_H
external_row_col_value_type(difference_type row_off, difference_type col_off, index_type row_i, index_type col_j)
This is a full random access iterator for accessing row and colunmn indices.
row_col_value_type< T > & operator=(const external_row_col_value_type< T > &val)
void swap(row_col_value_type< T > &v1, row_col_value_type< T > &v2)
Swap row_col_value_type<T> objects.
External storage of a row and column indice. This is required for creating a temporary in an assignme...
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)