CoreLinux++  0.4.32
CoreLinuxIterator.hpp
1 #if !defined(__CORELINUXITERATOR_HPP)
2 #define __CORELINUXITERATOR_HPP
3 
4 /*
5  CoreLinux++
6  Copyright (C) 2000 CoreLinux Consortium
7 
8  The CoreLinux++ Library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Library General Public License as
10  published by the Free Software Foundation; either version 2 of the
11  License, or (at your option) any later version.
12 
13  The CoreLinux++ Library Library is distributed in the hope that it will
14  be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Library General Public License for more details.
17 
18  You should have received a copy of the GNU Library General Public
19  License along with the GNU C Library; see the file COPYING.LIB. If not,
20  write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  Boston, MA 02111-1307, USA.
22 */
23 
24 #if !defined(__COMMON_HPP)
25 #include <Common.hpp>
26 #endif
27 
28 #if !defined(__ITERATOR_HPP)
29 #include <Iterator.hpp>
30 #endif
31 
32 #if !defined(__INVALIDITERATOREXCEPTION_HPP)
33 #include <InvalidIteratorException.hpp>
34 #endif
35 
36 #if !defined(__ITERATORBOUNDSEXCEPTION_HPP)
37 #include <IteratorBoundsException.hpp>
38 #endif
39 
40 namespace corelinux
41 {
42 
49  template< class TraverseType, class ElementType >
50  class CoreLinuxIterator : public Iterator<ElementType>
51  {
52  public:
53 
54  //
55  // Constructors and destructor
56  //
57 
67  :
68  Iterator<ElementType>()
69  {
70  throw InvalidIteratorException(LOCATION);
71  }
72 
79  CoreLinuxIterator( TraverseType aBegin,
80  TraverseType aEnd )
81  :
82  Iterator<ElementType>(),
83  theBegin( aBegin ),
84  theEnd( aEnd ),
86  {
87  ; // do nothing
88  }
95  :
96  Iterator<ElementType>( aRef ),
97  theBegin( aRef.theBegin ),
98  theEnd( aRef.theEnd ),
99  theCurrent( aRef.theBegin )
100  {
101  ; // do nothing
102  }
103 
105 
106  virtual ~CoreLinuxIterator( void )
107  {
108  theBegin = theEnd;
109  theCurrent = theEnd;
110  }
111 
112  //
113  // Operator overloads
114  //
115 
122  CoreLinuxIterator & operator=
123  ( const CoreLinuxIterator & aRef )
124  {
125  theBegin = aRef.theBegin;
126  theEnd = aRef.theEnd;
128  return (*this);
129  }
130 
138  bool operator==( const CoreLinuxIterator & aRef ) const
139  {
140  return (theBegin == aRef.theBegin &&
141  theEnd == aRef.theEnd);
142  }
143 
144 
145  //
146  // Accessors
147  //
155  virtual bool isValid( void ) const
156  {
157  return !(theCurrent == theEnd);
158  }
159 
168  virtual ElementType getElement( void )
169  const throw(IteratorBoundsException)
170  {
171  if( this->isValid() == false )
172  {
173  throw IteratorBoundsException(LOCATION);
174  }
175  else
176  {
177  ; // do nothing
178  }
179  return (*theCurrent);
180  }
181 
182  //
183  // Mutators
184  //
185 
187 
188  virtual void setFirst( void )
189  {
191  }
192 
199  virtual void setNext( void )
201  {
202  if( theCurrent != theEnd )
203  {
204  ++theCurrent;
205  }
206  else
207  {
208  throw IteratorBoundsException(LOCATION);
209  }
210  }
211 
218  virtual void setPrevious( void )
220  {
221  if( theCurrent != theBegin &&
222  theBegin != theEnd )
223  {
224  --theCurrent;
225  }
226  else
227  {
228  throw IteratorBoundsException(LOCATION);
229  }
230  }
231 
233 
234  virtual void setLast( void )
236  {
237  theCurrent = theEnd;
238  setPrevious();
239  }
240 
241  //
242  // Protected methods
243  //
244 
245  protected:
246 
247  //
248  // Protected members
249  //
250 
251  protected:
252 
254 
255  TraverseType theBegin;
256 
258 
259  TraverseType theEnd;
260 
262 
263  TraverseType theCurrent;
264 
265  };
266 }
267 
268 #endif // if !defined(__CORELINUXITERATOR_HPP)
269 
270 /*
271  Common rcs information do not modify
272  $Author: prudhomm $
273  $Revision: 1.1 $
274  $Date: 2000/04/23 20:43:13 $
275  $Locker: $
276 */
277 
278 
InvalidIteratorException is an exception that indicates a Iterator could not be properly formed for s...
Definition: InvalidIteratorException.hpp:43
CoreLinuxIterator(const CoreLinuxIterator &aRef)
Copy constructor.
Definition: CoreLinuxIterator.hpp:94
bool operator==(const CoreLinuxIterator &aRef) const
Equality operator.
Definition: CoreLinuxIterator.hpp:138
IteratorBoundsException is thrown when a Iterator has position before the begining or past the end po...
Definition: IteratorBoundsException.hpp:44
virtual ~CoreLinuxIterator(void)
Destructor.
Definition: CoreLinuxIterator.hpp:106
virtual void setFirst(void)
Set iterator to first element.
Definition: CoreLinuxIterator.hpp:188
virtual ElementType getElement(void) const
getElement returns the ElementType instance that is currently managed by the CoreLinuxIterator ...
Definition: CoreLinuxIterator.hpp:168
virtual void setLast(void)
Set iterator to last element.
Definition: CoreLinuxIterator.hpp:234
TraverseType theEnd
The last position.
Definition: CoreLinuxIterator.hpp:259
virtual void setPrevious(void)
Set iterator to previous element.
Definition: CoreLinuxIterator.hpp:218
CoreLinuxIterator(void)
Default constructor.
Definition: CoreLinuxIterator.hpp:65
The CoreLinuxIterator provides a way to access the elements of any of the non-associative STL collect...
Definition: CoreLinuxIterator.hpp:50
CoreLinuxIterator(TraverseType aBegin, TraverseType aEnd)
Initializing constructor.
Definition: CoreLinuxIterator.hpp:79
virtual bool isValid(void) const
isValid implementation for determining if the current position points to a valid EntityType instance ...
Definition: CoreLinuxIterator.hpp:155
Forward reference the various common classes.
Definition: AbstractAllocator.hpp:32
TraverseType theBegin
The first position.
Definition: CoreLinuxIterator.hpp:255
The Iterator provides a way to access the elements of an collection type sequentially without exposin...
Definition: Iterator.hpp:44
TraverseType theCurrent
The current position.
Definition: CoreLinuxIterator.hpp:263
virtual void setNext(void)
Set iterator to next element.
Definition: CoreLinuxIterator.hpp:199

This is the CoreLinux++ reference manual
Provided by The CoreLinux Consortium