casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VectorSTLIterator.h
Go to the documentation of this file.
1 //# VectorSTLIterator.h: Random access iterator for Casacore Vectors
2 //# Copyright (C) 2004
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id$
27 
28 #ifndef CASA_VECTORSTLITERATOR_H
29 #define CASA_VECTORSTLITERATOR_H
30 
31 //# Includes
32 #include <casacore/casa/aips.h>
34 #include <iterator>
35 
36 namespace casacore { //# NAMESPACE CASACORE - BEGIN
37 
38 //# Forward Declarations
39 
40 // <summary> Casacore Vector iterator </summary>
41 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
42 // </reviewed>
43 // <synopsis>
44 // This class creates a random access STL iterator for an Casacore Vector. All
45 // the STL functionality is present (or if something missing can be easily
46 // added). <br>
47 // The following comments hold:
48 // <ul>
49 // <li> A VectorSTLIterator can be created from a <src>Vector</src> (non-STL)
50 // It is the same as using <src>Vector.begin()</src>
51 // <li> No contiguous iterator is provided. Its construction is not necessary,
52 // since <src>Vector.data()</src> is a fully functional STL iterator already.
53 // <li> This iterator is non-intrusive. Since it needs state (the 'step')
54 // nothing substantial is gained by having it included in the Vector class.
55 // The major gain would be to be able to use the standard nomenclature:
56 // <src>Vector::iterator()</src> rather than <src>VectorSTLiterator</src>
57 // <li> It would be advisable, and easy to implement, to add a template argument
58 // to the <src>Array</src> classes: <src><class T, Bool isCont=True></src>. The
59 // default is contiguous, since creation is contiguous. In that case correct
60 // iterators for e.g. contiguous arrays are supplied automatically.
61 // <li> needs probably some 'const' fine tuning; and the <src>-></src> operator
62 // </ul>
63 // </synopsis>
64 
65 template <class T>
67 : public std::iterator<std::random_access_iterator_tag, T> {
68  public:
69  typedef T value_type;
70  typedef value_type* pointer;
71  typedef const value_type* const_pointer;
75  typedef const value_type& const_reference;
76  typedef std::size_t size_type;
77  typedef ptrdiff_t difference_type;
78  // Constructors. The iterator constructor from a <src>Vector</src> is
79  // the same as if created from <src>Vector.begin()</src>. Copy
80  // constructor and assignment can be the default ones.
81  // <group>
82  explicit VectorSTLIterator(const Vector<T> &c)
83  : start_p(const_cast<T*>(c.data())),
84  step_p (std::max(ssize_t(1), c.steps()(0))),
85  iter_p (const_cast<T*>(c.data()))
86  {}
88  {}
90  : start_p(c.pos()),
91  step_p (std::max(ssize_t(1), c.steps()(0))),
92  iter_p (start_p)
93  {}
94  // Copy constructor.
95  //# It is certainly needed for the Intel compiler.
97  : std::iterator<std::random_access_iterator_tag, T>(that),
98  start_p(that.start_p), step_p(that.step_p),
99  iter_p(that.iter_p)
100  {}
101  // Assignment.
102  //# It is certainly needed for the Intel compiler.
104  {
105  if (this != &that) {
107  start_p = that.start_p;
108  step_p = that.step_p;
109  iter_p = that.iter_p;
110  }
111  return *this;
112  }
113  // </group>
114  // Destructor
116  // Access
117  // <group>
118  reference operator[](uInt i) { return *(start_p+i*step_p); };
120  return *(start_p+i*step_p); };
121  reference operator*() { return *iter_p; };
122  const_reference operator*() const { return *iter_p; };
123  pointer pos() const {return iter_p; }
124  // </group>
125  // Manipulation
126  // <group>
127  const iterator &operator++() { iter_p+=step_p; return *this; };
129  iterator t = *this; iter_p+=step_p; return t; };
130  iterator &operator--() { iter_p-=step_p; return *this; };
132  VectorSTLIterator<T> t = *this;iter_p-=step_p; return t; };
134  iter_p+=i*step_p; return *this; };
136  iter_p-=i*step_p; return *this; };
138  VectorSTLIterator<T> t = *this; return t+=i; };
140  VectorSTLIterator<T> t = *this; return t-=i; };
141  // </group>
142  // Size related
143  // <group>
145  return (iter_p-x.iter_p)/step_p; };
146  // </group>
147  // Comparisons
148  // <group>
149  Bool operator== (const iterator &other) const {
150  return iter_p == other.iter_p; };
151  Bool operator!= (const iterator other) const {
152  return iter_p != other.iter_p; };
153  Bool operator< (const iterator &other) const {
154  return iter_p < other.iter_p; };
156  return iter_p == pos; };
158  return iter_p != pos; };
160  return iter_p < pos; };
161  // </group>
162  protected:
163  // Start (for random indexing)
164  pointer const start_p;
165  // Distance between elements
167  // Current element pointer
169 };
170 
171 
172 } //# NAMESPACE CASACORE - END
173 
174 #endif
A 1-D Specialization of the Array class.
iterator & operator-=(difference_type i)
pointer iter_p
Current element pointer.
iterator operator+(difference_type i) const
reference operator[](uInt i)
Access.
pointer const start_p
Start (for random indexing)
LatticeExprNode max(const LatticeExprNode &left, const LatticeExprNode &right)
PtrHolder< T > & operator=(const PtrHolder< T > &other)
VectorSTLIterator(const typename Array< T >::IteratorSTL &c)
Bool operator<(const iterator &other) const
ABSTRACT CLASSES Deliberately vague to be general enough to allow for many different types of data
Definition: PlotData.h:48
const_reference operator*() const
const value_type * const_pointer
iterator operator-(difference_type i) const
Bool operator==(const iterator &other) const
Comparisons.
Casacore Vector iterator.
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
difference_type operator-(const VectorSTLIterator< T > &x) const
Size related.
VectorSTLIterator< T > iterator
VectorSTLIterator(const Vector< T > &c)
Constructors.
iterator & operator+=(difference_type i)
const value_type & const_reference
const_reference operator[](uInt i) const
const Double c
Fundamental physical constants (SI units):
const iterator & operator++()
Manipulation.
difference_type step_p
Distance between elements.
Bool operator!=(const iterator other) const
VectorSTLIterator< T > & operator=(const VectorSTLIterator< T > &that)
Assignment.
const VectorSTLIterator< T > const_iterator
VectorSTLIterator(const VectorSTLIterator< T > &that)
Copy constructor.
unsigned int uInt
Definition: aipstype.h:51
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42