#line 1 "/user/cvsspst/ees1cg/RAVL/RAVL-0.7/Core/Container/Hash/HashIter.hh" // This file is part of RAVL, Recognition And Vision Library // Copyright (C) 2001, University of Surrey // This code may be redistributed under the terms of the GNU Lesser // General Public License (LGPL). See the lgpl.licence file for details or // see http://www.gnu.org/copyleft/lesser.html // file-header-ends-here #ifndef RAVLHASHITERT_HEADER #define RAVLHASHITERT_HEADER 1 /////////////////////////////////////////////////////////////// //! file="Ravl/Core/Container/Hash/HashIter.hh" //! lib=RavlCore //! userlevel=Normal //! author="Charles Galambos" //! date="1/9/1996" //! example=exHash.cc //! docentry="Ravl.Core.Hash Tables" //! rcsid="$Id: HashIter.hh,v 1.3 2001/12/02 11:42:47 craftit Exp $" #include "Ravl/Hash.hh" #define HASHITER_ALLOW_DELETE 0 namespace RavlN { //: Hash table iterator. // This iterator works with both HashC and HashARC.

// Small object ! template class HashIterC { public: HashIterC() {} // Don't use this if you can help it. HashIterC(const HashC &nTab) : bIt(nTab.table) { First(); } // Normal constructor. HashIterC(const HashIterC &Oth) : lIt(Oth.lIt), bIt(Oth.bIt) {} // Copy constructor. bool First(void) { bIt.First(); RavlAssert(bIt); lIt = *bIt; return CheckValid(); } // Goto first item in table. bool Next(void) { lIt.Next(); return CheckValid(); } // Goto next iterm in table. // Once this returns false (or IsElm() is false) this // should not be called again. void operator++(int) { lIt.Next(); CheckValid(); } //: Goto next element. void operator++() { lIt.Next(); CheckValid(); } //: Goto next element. bool IsElm() const { return lIt.IsElm(); } // Pointing to valid element ? operator bool() const { return lIt.IsElm(); } //: At a valid element ? const K &Key(void) const { return lIt.Data().GetKey(); } // Key for current item. IsElm() Must be true. const T &Data(void) const { return lIt.Data().Data(); } //: Data for current item.IsElm() Must be true. T &Data(void) { return const_cast(lIt.Data().Data()); } //: Data for current item.IsElm() Must be true. T &operator*() { return const_cast(lIt.Data().Data()); } //: Access data. const T &operator*() const { return const_cast(lIt.Data().Data()); } //: Access data. #if HASHITER_ALLOW_DELETE void Del(void); // Delete current item from table, move to next. // -> this breaks HashAR, if required I'll // make a new non-constant iterator which can do this. #endif HashIterC &operator=(const HashC &oth) { bIt = oth.table; First(); return *this; } // Assign to another table. HashIterC &operator=(const HashIterC &oth) { bIt = oth.bIt; lIt = oth.lIt; return *this; } // Assign to another iterator. //const HashC &GetTable() const { return hashTab; } // Which table ? protected: bool CheckValid(void); private: IntrDLIterC > lIt; // List iterator. SArray1dIterC > > bIt; // Current bin. }; ////////////////////////////////// // Check current iterator is valid, if not // move to next valid one. template bool HashIterC::CheckValid(void) { while(!lIt.IsElm()) { bIt.Next(); if(!bIt) return false; lIt = *bIt; } return true; } #if HASHITER_ALLOW_DELETE /////////////////////////////////// // Delete current item from table, move to next. template void HashIterC::Del(void) { HashC::HashElemConstIter Oldie(lIt); Next(); Oldie.Del();// Delete old member from list. } #endif } #endif