Sacado Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Sacado_TemplateIterator.hpp
Go to the documentation of this file.
1 // $Id$
2 // $Source$
3 // @HEADER
4 // ***********************************************************************
5 //
6 // Sacado Package
7 // Copyright (2006) Sandia Corporation
8 //
9 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
10 // the U.S. Government retains certain rights in this software.
11 //
12 // This library is free software; you can redistribute it and/or modify
13 // it under the terms of the GNU Lesser General Public License as
14 // published by the Free Software Foundation; either version 2.1 of the
15 // License, or (at your option) any later version.
16 //
17 // This library is distributed in the hope that it will be useful, but
18 // WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 // Lesser General Public License for more details.
21 //
22 // You should have received a copy of the GNU Lesser General Public
23 // License along with this library; if not, write to the Free Software
24 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
25 // USA
26 // Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps
27 // (etphipp@sandia.gov).
28 //
29 // ***********************************************************************
30 // @HEADER
31 
32 #ifndef SACADO_TEMPLATEITERATOR_HPP
33 #define SACADO_TEMPLATEITERATOR_HPP
34 
35 #include <vector>
36 #include <iterator>
37 
38 namespace Sacado {
39 
48  template <typename BaseT>
49  class TemplateIterator : public std::iterator<std::input_iterator_tag,
50  BaseT> {
51  public:
52 
55  typename std::vector< Teuchos::RCP<BaseT> >::iterator p) :
56  object_iterator(p) {}
57 
58  // No default constructor
59  // Use default copy constructor and copy assignment
60 
62  bool operator==(const TemplateIterator& t) const {
63  return object_iterator == t.objectIterator;
64  }
65 
67  bool operator!=(const TemplateIterator& t) const {
68  return object_iterator != t.object_iterator;
69  }
70 
73  operator*() const {
74  return *(*object_iterator);
75  }
76 
79  operator->() const {
80  return &(*(*object_iterator));
81  }
82 
86  return *this;
87  }
88 
91  TemplateIterator tmp = *this;
92  ++(*this);
93  return tmp;
94  }
95 
98  return *object_iterator;
99  }
100 
101  private:
102 
104  typename std::vector< Teuchos::RCP<BaseT> >::iterator object_iterator;
105 
106  };
107 
116  template <typename BaseT>
117  class ConstTemplateIterator : public std::iterator<std::input_iterator_tag,
118  BaseT> {
119  public:
120 
123  typename std::vector< Teuchos::RCP<BaseT> >::const_iterator p) :
124  object_iterator(p) {}
125 
126  // No default constructor
127  // Use default copy constructor and copy assignment
128 
130  bool operator==(const ConstTemplateIterator& t) const {
131  return object_iterator == t.objectIterator;
132  }
133 
135  bool operator!=(const ConstTemplateIterator& t) const {
136  return object_iterator != t.object_iterator;
137  }
138 
141  operator*() const {
142  return *(*object_iterator);
143  }
144 
147  operator->() const {
148  return &(*(*object_iterator));
149  }
150 
153  ++object_iterator;
154  return *this;
155  }
156 
159  ConstTemplateIterator tmp = *this;
160  ++(*this);
161  return tmp;
162  }
163 
166  return *object_iterator;
167  }
168 
169  private:
170 
172  typename std::vector< Teuchos::RCP<BaseT> >::const_iterator object_iterator;
173 
174  };
175 
176 }
177 
178 #endif
std::vector< Teuchos::RCP< BaseT > >::iterator object_iterator
Underlying object iterator.
TemplateIterator(typename std::vector< Teuchos::RCP< BaseT > >::iterator p)
Constructor.
bool operator==(const ConstTemplateIterator &t) const
Equal operator.
bool operator!=(const ConstTemplateIterator &t) const
Not equal operator.
Sacado::TemplateIterator< BaseT >::pointer operator->() const
-&gt; operator
Teuchos::RCP< BaseT > rcp() const
Returns a reference counted pointer object.
std::vector< Teuchos::RCP< BaseT > >::const_iterator object_iterator
Underlying object iterator.
TemplateIterator & operator++()
Prefix ++.
ConstTemplateIterator operator++(int)
Postfix ++.
TemplateIterator operator++(int)
Postfix ++.
Sacado::ConstTemplateIterator< BaseT >::pointer operator->() const
-&gt; operator
Teuchos::RCP< BaseT > rcp() const
Returns a reference counted pointer object.
ConstTemplateIterator & operator++()
Prefix ++.
bool operator!=(const TemplateIterator &t) const
Not equal operator.
Sacado::ConstTemplateIterator< BaseT >::reference operator*() const
Dereference operator.
Sacado::TemplateIterator< BaseT >::reference operator*() const
Dereference operator.
bool operator==(const TemplateIterator &t) const
Equal operator.
ConstTemplateIterator(typename std::vector< Teuchos::RCP< BaseT > >::const_iterator p)
Constructor.