AmpTools
MIPointerListIterator.h
Go to the documentation of this file.
1 #if !defined(MINUITINTERFACE_MIPOINTERLISTITERATOR_H)
2 #define MINUITINTERFACE_MIPOINTERLISTITERATOR_H
3 
4 // This file is a part of MinuitInterface - a front end for the Minuit minimization
5 // package (Minuit itself was authored by Fred James, of CERN)
6 //
7 //
8 // Copyright Cornell University 1993, 1996, All Rights Reserved.
9 //
10 // This software written by Lawrence Gibbons, Cornell University.
11 //
12 // Redistribution and use in source and binary forms, with or without
13 // modification, are permitted provided that the following conditions
14 // are met:
15 // 1. Redistributions of source code must retain the above copyright
16 // notice and author attribution, this list of conditions and the
17 // following disclaimer.
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice and author attribution, this list of conditions and the
20 // following disclaimer in the documentation and/or other materials
21 // provided with the distribution.
22 // 3. Neither the name of the University nor the names of its contributors
23 // may be used to endorse or promote products derived from this software
24 // without specific prior written permission.
25 //
26 // Creation of derivative forms of this software for commercial
27 // utilization may be subject to restriction; written permission may be
28 // obtained from Cornell University.
29 //
30 // CORNELL MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. By way
31 // of example, but not limitation, CORNELL MAKES NO REPRESENTATIONS OR
32 // WARRANTIES OF MERCANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT
33 // THE USE OF THIS SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY PATENTS,
34 // COPYRIGHTS, TRADEMARKS, OR OTHER RIGHTS. Cornell University shall not be
35 // held liable for any liability with respect to any claim by the user or any
36 // other party arising from use of the program.
37 //
38 
39 typedef long relative_address;
40 
41 template < class T_iter, class T_return, class T_valueType >
43 {
44 
45  // ---------- private typedefs ---------------
47 
48 public:
49  // ---------- constants, enums and typedefs --------------
50  typedef T_valueType value_type;
52  typedef T_return& reference;
53  typedef T_return* pointer;
54 
55 #if defined(NO_ITERATOR_TRAITS_BUG)
56  typedef typename iterator_traits<T_iter>::iterator_category iterator_category;
57 #endif
58 
59  // ---------- Constructors and destructor ----------------
60  // default constructor
62  // constructor based on the STL implemented iterator for the
63  // list of T* (takes double-dereferencing to get to T)
64  MIPointerListIterator( const T_iter& anIterator );
65 
66  // copy constructor
67  MIPointerListIterator( const self& rhs );
68 
69  // assignment operator
70  const self& operator=( const self& rhs );
71 
72  virtual ~MIPointerListIterator();
73 
74  // ---------- member functions ---------------------------
75  self& operator++();
76  self operator++(int);
77 
78  self& operator--();
79  self operator--(int);
80 
81  self& operator+=( relative_address n);
82  self& operator-=( relative_address n);
83 
84  // dereferencing operators
85  T_return& operator*();
86  T_return* operator->();
87 
88  // ---------- const member functions ---------------------
89 
90  // comparison operators
91  bool operator==( const self& anMIPointerListIterator ) const;
92  bool operator!=( const self& anMIPointerListIterator ) const;
93 
94  // iterator addition/subtraction
95  self operator+( relative_address n) const;
96  self operator-( relative_address n) const;
97 
98 protected:
99  // --------- not intended for public use -----------
100  const T_iter& bareIterator() const;
101 
102 private:
103  // ---------- data members -------------------------------
104  T_iter m_iterator;
105 
106 };
107 
108 // inline function definitions
109 
110 //
111 // Package: <MinuitInterface>
112 // Module: MIPointerListIterator
113 //
114 // Description: A smart pointer that implements an iterator over a
115 // container of T*, eliminating the need for users to
116 // double dereference.
117 //
118 // Implementation:
119 // This just holds an STL list iterator, with the dereferencing
120 // operators performing the first level of iteration, returning
121 // either a T* (->) or a T& (*).
122 //
123 //
124 // constructors and destructor
125 //
126 template<class T_iter, class T_return, class T_valueType>
128 {}
129 
130 template<class T_iter, class T_return, class T_valueType>
132 m_iterator( anIterator )
133 {}
134 
135 template<class T_iter, class T_return, class T_valueType>
137 m_iterator( rhs.m_iterator )
138 {}
139 
140 template<class T_iter, class T_return, class T_valueType>
142 {
143 }
144 
145 //
146 // assignment operators
147 //
148 template<class T_iter, class T_return, class T_valueType>
151 {
152  if( this != &rhs )
153  {
154 
155  m_iterator = rhs.m_iterator;
156  }
157 
158  return *this;
159 }
160 
161 //
162 // member functions
163 //
164 template<class T_iter, class T_return, class T_valueType>
167 {
168  ++m_iterator;
169  return *this;
170 }
171 
172 template<class T_iter, class T_return, class T_valueType>
175 {
177  ++(*this); // use prefix operator
178  return( before );
179 }
180 
181 
182 template<class T_iter, class T_return, class T_valueType>
185 {
186  --m_iterator;
187  return *this;
188 }
189 
190 
191 template<class T_iter, class T_return, class T_valueType>
194 {
196  --(*this); // use prefix operator
197  return ( before );
198 }
199 
200 
201 template<class T_iter, class T_return, class T_valueType>
204 {
205  for ( relative_address i = 0; i != n; ++i, ++*this ) {}
206  return *this;
207 }
208 
209 
210 template<class T_iter, class T_return, class T_valueType>
213 {
214  for ( relative_address i = 0; i != n; ++i, --*this ) {}
215  return *this;
216 }
217 
218 
219 //
220 // const member functions
221 //
222 
223 template<class T_iter, class T_return, class T_valueType>
224 T_return&
226 {
227  return( **m_iterator );
228 }
229 
230 
231 template<class T_iter, class T_return, class T_valueType>
232 T_return*
234 {
235  return( *m_iterator );
236 }
237 
238 
239 template<class T_iter, class T_return, class T_valueType>
240 bool
241 MIPointerListIterator<T_iter, T_return, T_valueType>::operator==( const self& anMIPointerListIterator ) const
242 {
243  return ( m_iterator == anMIPointerListIterator.m_iterator );
244 }
245 
246 
247 template<class T_iter, class T_return, class T_valueType>
248 bool
250 {
251  return (m_iterator != anItr.m_iterator);
252 }
253 
254 
255 template<class T_iter, class T_return, class T_valueType>
258 {
260  for( relative_address i = 0; i != n; ++i, ++tempItr ) {}
261  return tempItr;
262 }
263 
264 
265 template<class T_iter, class T_return, class T_valueType>
268 {
270  for( relative_address i = 0; i != n; ++i, --tempItr ) {}
271  return tempItr;
272 }
273 
274 
275 template<class T_iter, class T_return, class T_valueType>
276 const T_iter&
278 {
279  return( m_iterator );
280 }
281 
282 //
283 // static member functions
284 //
285 
286 #endif /* MINUITINTERFACE_MIPOINTERLISTITERATOR_H */
relative_address difference_type
self operator+(relative_address n) const
self & operator-=(relative_address n)
bool operator!=(const self &anMIPointerListIterator) const
self & operator+=(relative_address n)
const self & operator=(const self &rhs)
const T_iter & bareIterator() const
self operator-(relative_address n) const
bool operator==(const self &anMIPointerListIterator) const
long relative_address