00001 #if !defined(__CORELINUXITERATOR_HPP) 00002 #define __CORELINUXITERATOR_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(__ITERATOR_HPP) 00029 #include <Iterator.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 00049 template< class TraverseType, class ElementType > 00050 class CoreLinuxIterator : public Iterator<ElementType> 00051 { 00052 public: 00053 00054 // 00055 // Constructors and destructor 00056 // 00057 00065 CoreLinuxIterator( void ) 00066 throw(InvalidIteratorException) 00067 : 00068 Iterator<ElementType>() 00069 { 00070 throw InvalidIteratorException(LOCATION); 00071 } 00072 00079 CoreLinuxIterator( TraverseType aBegin, 00080 TraverseType aEnd ) 00081 : 00082 Iterator<ElementType>(), 00083 theBegin( aBegin ), 00084 theEnd( aEnd ), 00085 theCurrent( theBegin ) 00086 { 00087 ; // do nothing 00088 } 00094 CoreLinuxIterator( const CoreLinuxIterator &aRef ) 00095 : 00096 Iterator<ElementType>( aRef ), 00097 theBegin( aRef.theBegin ), 00098 theEnd( aRef.theEnd ), 00099 theCurrent( aRef.theBegin ) 00100 { 00101 ; // do nothing 00102 } 00103 00105 00106 virtual ~CoreLinuxIterator( void ) 00107 { 00108 theBegin = theEnd; 00109 theCurrent = theEnd; 00110 } 00111 00112 // 00113 // Operator overloads 00114 // 00115 00122 CoreLinuxIterator & operator= 00123 ( const CoreLinuxIterator & aRef ) 00124 { 00125 theBegin = aRef.theBegin; 00126 theEnd = aRef.theEnd; 00127 theCurrent = theBegin; 00128 return (*this); 00129 } 00130 00138 bool operator==( const CoreLinuxIterator & aRef ) const 00139 { 00140 return (theBegin == aRef.theBegin && 00141 theEnd == aRef.theEnd); 00142 } 00143 00144 00145 // 00146 // Accessors 00147 // 00155 virtual bool isValid( void ) const 00156 { 00157 return !(theCurrent == theEnd); 00158 } 00159 00168 virtual ElementType getElement( void ) 00169 const throw(IteratorBoundsException) 00170 { 00171 if( this->isValid() == false ) 00172 { 00173 throw IteratorBoundsException(LOCATION); 00174 } 00175 else 00176 { 00177 ; // do nothing 00178 } 00179 return (*theCurrent); 00180 } 00181 00182 // 00183 // Mutators 00184 // 00185 00187 00188 virtual void setFirst( void ) 00189 { 00190 theCurrent = theBegin; 00191 } 00192 00199 virtual void setNext( void ) 00200 throw(IteratorBoundsException) 00201 { 00202 if( theCurrent != theEnd ) 00203 { 00204 ++theCurrent; 00205 } 00206 else 00207 { 00208 throw IteratorBoundsException(LOCATION); 00209 } 00210 } 00211 00218 virtual void setPrevious( void ) 00219 throw(IteratorBoundsException) 00220 { 00221 if( theCurrent != theBegin && 00222 theBegin != theEnd ) 00223 { 00224 --theCurrent; 00225 } 00226 else 00227 { 00228 throw IteratorBoundsException(LOCATION); 00229 } 00230 } 00231 00233 00234 virtual void setLast( void ) 00235 throw(IteratorBoundsException) 00236 { 00237 theCurrent = theEnd; 00238 setPrevious(); 00239 } 00240 00241 // 00242 // Protected methods 00243 // 00244 00245 protected: 00246 00247 // 00248 // Protected members 00249 // 00250 00251 protected: 00252 00254 00255 TraverseType theBegin; 00256 00258 00259 TraverseType theEnd; 00260 00262 00263 TraverseType theCurrent; 00264 00265 }; 00266 } 00267 00268 #endif // if !defined(__CORELINUXITERATOR_HPP) 00269 00270 /* 00271 Common rcs information do not modify 00272 $Author: prudhomm $ 00273 $Revision: 1.1 $ 00274 $Date: 2000/04/23 20:43:13 $ 00275 $Locker: $ 00276 */ 00277 00278