CoreLinux++  0.4.32
CoreLinuxAssociativeIterator.hpp
1 #if !defined(__CORELINUXASSOCIATIVEITERATOR_HPP)
2 #define __CORELINUXASSOCIATIVEITERATOR_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(__ASSOCIATIVEITERATOR_HPP)
29 #include <AssociativeIterator.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 
50  template< class TraverseType, class KeyType, class ElementType >
52  public AssociativeIterator<KeyType,ElementType>
53  {
54  public:
55 
56  //
57  // Constructors and destructor
58  //
59 
69  :
70  AssociativeIterator<KeyType,ElementType>()
71  {
72  throw InvalidIteratorException(LOCATION);
73  }
74 
81  CoreLinuxAssociativeIterator( TraverseType aBegin,
82  TraverseType aEnd )
83  :
84  AssociativeIterator<KeyType,ElementType>(),
85  theBegin( aBegin ),
86  theEnd( aEnd ),
88  {
89  ; // do nothing
90  }
91 
98  (
99  const CoreLinuxAssociativeIterator &aRef
100  )
101  :
103  theBegin( aRef.theBegin ),
104  theEnd( aRef.theEnd ),
105  theCurrent( aRef.theBegin )
106  {
107  ; // do nothing
108  }
109 
111 
113  {
114  theBegin = theEnd;
115  theCurrent = theEnd;
116  }
117 
118  //
119  // Operator overloads
120  //
121 
128  CoreLinuxAssociativeIterator & operator=
130  {
131  theBegin = aRef.theBegin;
132  theEnd = aRef.theEnd;
134  return (*this);
135  }
136 
144  bool operator==
145  (
146  const CoreLinuxAssociativeIterator & aRef
147  ) const
148  {
149  return (theBegin == aRef.theBegin &&
150  theEnd == aRef.theEnd);
151  }
152 
153 
154  //
155  // Accessors
156  //
164  virtual bool isValid( void ) const
165  {
166  return !(theCurrent == theEnd);
167  }
168 
177  virtual ElementType getElement( void )
178  const throw(IteratorBoundsException)
179  {
180  if( this->isValid() == false )
181  {
182  throw IteratorBoundsException(LOCATION);
183  }
184  else
185  {
186  ; // do nothing
187  }
188  return (*theCurrent).second;
189  }
190 
199  virtual KeyType getKey( void )
200  const throw(IteratorBoundsException)
201  {
202  if( this->isValid() == false )
203  {
204  throw IteratorBoundsException(LOCATION);
205  }
206  else
207  {
208  ; // do nothing
209  }
210  return (*theCurrent).first;
211  }
212 
213  //
214  // Mutators
215  //
216 
218 
219  virtual void setFirst( void )
220  {
222  }
223 
230  virtual void setNext( void )
232  {
233  if( theCurrent != theEnd )
234  {
235  ++theCurrent;
236  }
237  else
238  {
239  throw IteratorBoundsException(LOCATION);
240  }
241  }
242 
249  virtual void setPrevious( void )
251  {
252  if( theCurrent != theBegin &&
253  theBegin != theEnd )
254  {
255  --theCurrent;
256  }
257  else
258  {
259  throw IteratorBoundsException(LOCATION);
260  }
261  }
262 
264 
265  virtual void setLast( void )
267  {
268  theCurrent = theEnd;
269  setPrevious();
270  }
271 
272  //
273  // Protected methods
274  //
275 
276  protected:
277 
278  //
279  // Protected members
280  //
281 
282  protected:
283 
285 
286  TraverseType theBegin;
287 
289 
290  TraverseType theEnd;
291 
293 
294  TraverseType theCurrent;
295 
296  };
297 }
298 
299 #endif // if !defined(__CORELINUXASSOCIATIVEITERATOR_HPP)
300 
301 /*
302  Common rcs information do not modify
303  $Author: prudhomm $
304  $Revision: 1.1 $
305  $Date: 2000/04/23 20:43:13 $
306  $Locker: $
307 */
308 
309 
310 
InvalidIteratorException is an exception that indicates a Iterator could not be properly formed for s...
Definition: InvalidIteratorException.hpp:43
IteratorBoundsException is thrown when a Iterator has position before the begining or past the end po...
Definition: IteratorBoundsException.hpp:44
virtual void setLast(void)
Set AssociativeIterator to last element.
Definition: CoreLinuxAssociativeIterator.hpp:265
virtual void setNext(void)
Set AssociativeIterator to next element if attempt to position past end of elements.
Definition: CoreLinuxAssociativeIterator.hpp:230
virtual bool isValid(void) const
isValid implementation for determining if the current position points to a valid EntityType instance ...
Definition: CoreLinuxAssociativeIterator.hpp:164
virtual ~CoreLinuxAssociativeIterator(void)
Destructor.
Definition: CoreLinuxAssociativeIterator.hpp:112
TraverseType theCurrent
The current position.
Definition: CoreLinuxAssociativeIterator.hpp:294
Forward reference the various common classes.
Definition: AbstractAllocator.hpp:32
virtual void setFirst(void)
Set AssociativeIterator to first element.
Definition: CoreLinuxAssociativeIterator.hpp:219
virtual KeyType getKey(void) const
getKey returns the KeyType instance that is currently pointed to by the AssociativeIterator ...
Definition: CoreLinuxAssociativeIterator.hpp:199
The AssociativeIterator that extends Iterator to include the interface for describing an associative ...
Definition: AssociativeIterator.hpp:44
The CoreLinuxAssociativeIterator provides a way to access the elements of any of the associative STL ...
Definition: CoreLinuxAssociativeIterator.hpp:51
CoreLinuxAssociativeIterator(void)
Default constructor - the CoreLinuxAssociativeIterator requires being constructed with a valid collec...
Definition: CoreLinuxAssociativeIterator.hpp:67
TraverseType theEnd
The last position.
Definition: CoreLinuxAssociativeIterator.hpp:290
TraverseType theBegin
The first position.
Definition: CoreLinuxAssociativeIterator.hpp:286
virtual void setPrevious(void)
Set AssociativeIterator to previous element if attempt to position before begining of elements...
Definition: CoreLinuxAssociativeIterator.hpp:249
virtual ElementType getElement(void) const
getElement returns the ElementType instance that is currently managed by the CoreLinuxAssociativeIter...
Definition: CoreLinuxAssociativeIterator.hpp:177
CoreLinuxAssociativeIterator(TraverseType aBegin, TraverseType aEnd)
Initializing constructor.
Definition: CoreLinuxAssociativeIterator.hpp:81

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