Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Examples  

CoreLinuxAssociativeIterator.hpp

00001 #if   !defined(__CORELINUXASSOCIATIVEITERATOR_HPP)
00002 #define  __CORELINUXASSOCIATIVEITERATOR_HPP
00003 
00004 /*
00005   CoreLinux++ 
00006   Copyright (C) 2000 CoreLinux Consortium
00007   
00008    The CoreLinux++ Library is free software; you can redistribute it and/or
00009    modify it under the terms of the GNU Library General Public License as
00010    published by the Free Software Foundation; either version 2 of the
00011    License, or (at your option) any later version.
00012 
00013    The CoreLinux++ Library Library is distributed in the hope that it will 
00014    be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016    Library General Public License for more details.
00017 
00018    You should have received a copy of the GNU Library General Public
00019    License along with the GNU C Library; see the file COPYING.LIB.  If not,
00020    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00021    Boston, MA 02111-1307, USA.  
00022 */   
00023 
00024 #if   !defined(__COMMON_HPP)
00025 #include <Common.hpp>
00026 #endif
00027 
00028 #if   !defined(__ASSOCIATIVEITERATOR_HPP)
00029 #include <AssociativeIterator.hpp>
00030 #endif
00031 
00032 #if   !defined(__INVALIDITERATOREXCEPTION_HPP)
00033 #include <InvalidIteratorException.hpp>
00034 #endif
00035 
00036 #if   !defined(__ITERATORBOUNDSEXCEPTION_HPP)
00037 #include <IteratorBoundsException.hpp>
00038 #endif
00039 
00040 namespace   corelinux
00041 {
00042 
00050    template< class TraverseType, class KeyType, class ElementType >
00051       class CoreLinuxAssociativeIterator : 
00052          public AssociativeIterator<KeyType,ElementType>
00053       {
00054       public:
00055 
00056          //
00057          // Constructors and destructor
00058          //
00059 
00067                      CoreLinuxAssociativeIterator( void ) 
00068                         throw(InvalidIteratorException)
00069                         :
00070                         AssociativeIterator<KeyType,ElementType>()
00071                      {
00072                         throw InvalidIteratorException(LOCATION);
00073                      }
00074 
00081                      CoreLinuxAssociativeIterator( TraverseType aBegin,
00082                                         TraverseType aEnd )
00083                         :
00084                         AssociativeIterator<KeyType,ElementType>(),
00085                         theBegin( aBegin ),
00086                         theEnd( aEnd ),
00087                         theCurrent( theBegin )
00088                      {
00089                         ;  // do nothing
00090                      }
00091 
00097                      CoreLinuxAssociativeIterator
00098                         ( 
00099                            const CoreLinuxAssociativeIterator &aRef 
00100                         )
00101                         :
00102                         AssociativeIterator<KeyType,ElementType>( aRef ),
00103                         theBegin( aRef.theBegin ),
00104                         theEnd( aRef.theEnd ),
00105                         theCurrent( aRef.theBegin )
00106                      {
00107                         ;  // do nothing
00108                      }
00109 
00111 
00112          virtual     ~CoreLinuxAssociativeIterator( void )
00113          {
00114             theBegin = theEnd;  
00115             theCurrent = theEnd;
00116          }
00117 
00118          //
00119          // Operator overloads
00120          //
00121 
00128                   CoreLinuxAssociativeIterator & operator=
00129                      ( const CoreLinuxAssociativeIterator & aRef )
00130                   {
00131                      theBegin = aRef.theBegin;
00132                      theEnd = aRef.theEnd;
00133                      theCurrent = theBegin;
00134                      return (*this);
00135                   }
00136 
00144                   bool  operator==
00145                      ( 
00146                         const CoreLinuxAssociativeIterator & aRef 
00147                      ) const
00148                   {
00149                      return (theBegin == aRef.theBegin &&
00150                              theEnd == aRef.theEnd);
00151                   }
00152                   
00153 
00154          //
00155          // Accessors
00156          //
00164          virtual  bool  isValid( void ) const 
00165          {
00166             return !(theCurrent == theEnd);
00167          }
00168 
00177          virtual  ElementType  getElement( void ) 
00178                          const throw(IteratorBoundsException) 
00179                   {
00180                      if( this->isValid() == false )
00181                      {
00182                         throw IteratorBoundsException(LOCATION);
00183                      }
00184                      else
00185                      {
00186                         ;  // do nothing
00187                      }
00188                      return (*theCurrent).second;
00189                   }
00190 
00199          virtual  KeyType  getKey( void ) 
00200                          const throw(IteratorBoundsException)
00201                   {
00202                      if( this->isValid() == false )
00203                      {
00204                         throw IteratorBoundsException(LOCATION);
00205                      }
00206                      else
00207                      {
00208                         ;  // do nothing
00209                      }
00210                      return (*theCurrent).first;
00211                   }
00212 
00213          //
00214          // Mutators
00215          //
00216 
00218 
00219          virtual  void  setFirst( void ) 
00220          {
00221             theCurrent = theBegin;
00222          }
00223 
00230          virtual  void  setNext( void ) 
00231                            throw(IteratorBoundsException) 
00232          {
00233             if( theCurrent != theEnd )
00234             {
00235                ++theCurrent;
00236             }
00237             else
00238             {
00239                throw IteratorBoundsException(LOCATION);
00240             }
00241          }
00242 
00249          virtual  void  setPrevious( void ) 
00250                            throw(IteratorBoundsException)
00251          {
00252             if( theCurrent != theBegin &&
00253                 theBegin != theEnd )
00254             {
00255                --theCurrent;
00256             }
00257             else
00258             {
00259                throw IteratorBoundsException(LOCATION);
00260             }
00261          }
00262 
00264 
00265          virtual  void  setLast( void ) 
00266                         throw(IteratorBoundsException)
00267          {
00268             theCurrent = theEnd;
00269             setPrevious();
00270          }
00271 
00272       //
00273       // Protected methods
00274       //
00275 
00276       protected:
00277 
00278       //
00279       // Protected members
00280       //
00281 
00282       protected:
00283 
00285 
00286                   TraverseType   theBegin;
00287 
00289 
00290                   TraverseType   theEnd;
00291 
00293 
00294                   TraverseType   theCurrent;
00295    
00296       };
00297 }
00298 
00299 #endif   // if !defined(__CORELINUXASSOCIATIVEITERATOR_HPP)
00300 
00301 /*
00302    Common rcs information do not modify
00303    $Author: prudhomm $
00304    $Revision: 1.1 $
00305    $Date: 2000/04/23 20:43:13 $
00306    $Locker:  $
00307 */
00308 
00309 
00310 

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