#line 1 "/user/cvsspst/ees1cg/RAVL/RAVL-0.7/Core/Container/Branch/BHashIter.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 RAVL_BHASHITER_HEADER #define RAVL_BHASHITER_HEADER 1 ///////////////////////////////////////////////////////////// //! docentry="Ravl.Core.Branch" //! rcsid="$Id: BHashIter.hh,v 1.2 2002/07/07 21:40:53 craftit Exp $" //! lib=RavlCore //! file="Ravl/Core/Container/Branch/BHashIter.hh" //! author="Charles Galambos" #include "Ravl/BHash.hh" #include "Ravl/HSet.hh" namespace RavlN { template class BHashIterC { public: BHashIterC() {} //: Default constructor. BHashIterC(const BHashC &hashtab) : it(hashtab.table) { First(); } //: Constructor. bool First(); //: Goto first element in table. // Returns false if no element was found. bool IsElm() const { return lit.IsElm(); } //: Is iterator at a valid element ? operator bool() const { return IsElm(); } //: Is iterator at a valid element ? const DataT &Data() const { return lit->Data(); } //: Access current data. const KeyT &Key() const { return lit->Key(); } //: Access current data. bool Next(); //: Goto next element. void operator++(int) { Next(); } //: Goto next element. protected: //: Goto next valid element. SArray1dIterC > > it; // Table iterator. BListIterC > lit; // list iterator. HSetC done; // Set of key;s we've seen. }; template bool BHashIterC::First() { it.First(); lit = *it; done.Empty(); while(!lit) { it++; if(!it) return false; // End of table. lit = *it; } done += lit.Data().Key(); return true; } template bool BHashIterC::Next() { do { lit++; while(!lit) { it++; if(!it) return false; // End of table. lit = *it; } } while(done[lit.Data().Key()]); done += lit.Data().Key(); return true; } } #endif