InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
CellIterator.h
1 //========================================================================================
2 //
3 // $File$
4 //
5 // Owner: Mat Marcus
6 //
7 // $Author$
8 //
9 // $DateTime$
10 //
11 // $Revision$
12 //
13 // $Change$
14 //
15 // Copyright 1997-2010 Adobe Systems Incorporated. All rights reserved.
16 //
17 // NOTICE: Adobe permits you to use, modify, and distribute this file in accordance
18 // with the terms of the Adobe license agreement accompanying it. If you have received
19 // this file from a source other than Adobe, then your use, modification, or
20 // distribution of it requires the prior written permission of Adobe.
21 //
22 //========================================================================================
23 
24 #ifndef __CellIterator__
25 #define __CellIterator__
26 
27 #include <iterator>
28 #include <functional>
29 #include "TableTypes.h"
30 #include "K2Iterator.h"
31 
32 template <class Structure>
34 {
35 public:
36  // declare typedefs by hand instead of inheriting from std::iterator
37  typedef GridAddress value_type;
38  typedef std::ptrdiff_t difference_type;
39  typedef const GridAddress* pointer;
40  typedef const GridAddress& reference;
41 
42  typedef std::bidirectional_iterator_tag iterator_category;
43 
44  CellIterator(const GridAddress& gridRef, const GridArea& gridArea, const Structure* structure);
45  CellIterator(const CellIterator& rhs);
46  ~CellIterator();
47 
48  const GridAddress& operator * () const;
49  const GridAddress* operator -> () const;
50 
51  CellIterator& operator ++ ();
52  CellIterator operator ++ (int);
53  CellIterator& operator= (const CellIterator& rhs);
54 
55  CellIterator& operator -- ();
56  CellIterator operator -- (int);
57 
58  bool16 operator ==(const CellIterator& rhs) const;
59  bool16 operator != (const CellIterator& rhs) const;
60  bool16 operator < (const CellIterator& rhs) const;
61 
62 private:
63  void MoveForward();
64  void MoveBackward();
65 
66 private:
67  GridAddress fGridAddress;
68  GridArea fGridArea;
69  const Structure* fStructure;
70 };
71 
72 template <class Structure>
74 {
75 
76 public:
78  typedef std::bidirectional_iterator_tag iterator_category;
79 
80  typedef GridAddress value_type;
81  typedef std::ptrdiff_t difference_type;
82  typedef const GridAddress* pointer;
83  typedef const GridAddress& reference;
84 
85  explicit ReverseCellIterator(iterator_type x) : fCurrent(x), fCached(fCurrent) {}
86 
87  iterator_type base() const { return fCurrent; }
88  reference operator*() const
89  {
90  if(fCached != fCurrent)
91  fCached = fCurrent;
92  return *--fCached;
93  }
94  pointer operator->() const { return &(**this); }
95 
96  ReverseCellIterator& operator++() { --fCurrent; return *this; }
97 
98  ReverseCellIterator operator++(int)
99  {
100  ReverseCellIterator tmp = *this;
101  --fCurrent;
102  return tmp;
103  }
104 
105  ReverseCellIterator& operator--() {++fCurrent; return *this; }
106 
107  ReverseCellIterator operator--(int)
108  {
109  ReverseCellIterator tmp = *this;
110  ++fCurrent;
111  return tmp;
112  }
113 
114 // ReverseCellIterator operator+ (difference_type n) const { return ReverseCellIterator(fCurrent - n); }
115 // ReverseCellIterator& operator+=(difference_type n) { fCurrent -= n; return *this; }
116 
117 // ReverseCellIterator operator- (difference_type n) const { return ReverseCellIterator(fCurrent + n); }
118 // ReverseCellIterator& operator-=(difference_type n) { fCurrent += n; return *this; }
119 // reference operator[](difference_type n) const {return fCurrent[-n-1];}
120 
121 protected:
122  iterator_type fCurrent;
123  mutable iterator_type fCached;
124 };
125 
126 template <typename T>
127 inline bool16 operator==(const ReverseCellIterator<T>& lhs,
128  const ReverseCellIterator<T>& rhs)
129 {
130  return static_cast<bool16>(lhs.base() == rhs.base());
131 }
132 
133 template <typename T>
134 inline
135 bool16
136 operator< (const ReverseCellIterator<T>& lhs,
137  const ReverseCellIterator<T>& rhs)
138 {
139  return static_cast<bool16>(lhs.base() < rhs.base());
140 }
141 
142 template <typename T>
143 inline
144 bool16
145 operator!=(const ReverseCellIterator<T>& lhs,
146  const ReverseCellIterator<T>& rhs)
147 {
148  return static_cast<bool16>(lhs.base() != rhs.base());
149 }
150 
151 /*
152 template <typename T>
153 inline
154 bool16
155 operator> (const ReverseCellIterator<T>& lhs,
156  const ReverseCellIterator<T>& rhs)
157 {
158  return static_cast<bool16>(lhs.base() > rhs.base());
159 }
160 
161 template <typename T>
162 inline
163 bool16
164 operator>=(const ReverseCellIterator<T>& lhs,
165  const ReverseCellIterator<T>& rhs)
166 {
167  return static_cast<bool16>(lhs.base() >= rhs.base());
168 }
169 
170 template <typename T>
171 inline
172 bool16
173 operator<=(const ReverseCellIterator<T>& lhs,
174  const ReverseCellIterator<T>& rhs)
175 {
176  return static_cast<bool16>(lhs.base() <= rhs.base());
177 }
178 
179 template <typename T>
180 inline
181 ReverseCellIterator::difference_type
182 operator-(const ReverseCellIterator<T>& lhs,
183  const ReverseCellIterator<T>& rhs)
184 {
185  return rhs.base() - lhs.base();
186 }
187 
188 template <typename T>
189 inline ReverseCellIterator<T>
190 operator+(ReverseCellIterator<T>::difference_type n,
191  const ReverseCellIterator<T>& lhs)
192 {
193  return ReverseCellIterator(lhs.base() - n);
194 }
195 
196 
197 */
198 
199 #endif //__CellIterator__