#line 1 "/user/cvsspst/ees1cg/RAVL/RAVL-0.7/Core/Container/Buffer/BfAccIter.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_RBFACCITER_HEADER #define RAVL_RBFACCITER_HEADER 1 /////////////////////////////////////////////////// //! userlevel=Normal //! rcsid="$Id: BfAccIter.hh,v 1.6 2002/06/18 10:37:00 craftit Exp $" //! file="Ravl/Core/Container/Buffer/BfAccIter.hh" //! lib=RavlCore //! author="Charles Galambos" //! date="24/01/2001" //! docentry="Ravl.Core.Arrays.Buffer" #include "Ravl/BufferAccess.hh" #include "Ravl/Assert.hh" namespace RavlN { template class RangeBufferAccessC ; template class SizeBufferAccessC ; class IndexRangeC; //! userlevel=Advanced //: Iterator for access buffer. template class BufferAccessIterC { public: inline BufferAccessIterC(); //: Default constructor. inline BufferAccessIterC(const BufferAccessC &buff,const IndexRangeC &rng) { First(buff,rng); } //: Constructor. inline BufferAccessIterC(const BufferAccessC &buff,UIntT size) { First(buff,size); } //: Constructor. inline BufferAccessIterC(const RangeBufferAccessC &buff) { First(buff); } //: Constructor. inline BufferAccessIterC(const SizeBufferAccessC &buff) { First(buff); } //: Constructor. inline BufferAccessIterC &operator=(const RangeBufferAccessC &buff); //: Assignment to a buffer. inline BufferAccessIterC &operator=(const SizeBufferAccessC &buff); //: Assignment to a buffer. inline bool First(const BufferAccessC &buff,const IndexRangeC &rng); //: Goto fist element. inline bool First(const BufferAccessC &buff,UIntT size); //: Goto fist element. inline bool First(const RangeBufferAccessC &buff); //: Goto fist element. inline bool First(const SizeBufferAccessC &buff); //: Goto fist element. inline bool IsElm() const { return at < endOfRow; } //: At valid element ? inline bool IsLast() const { return (at+1) == endOfRow; } //: Test if we're at the last valid element in the range. // Note: This is slightly slower than IsElm(). inline operator bool() const { return at < endOfRow; } //: At valid element ? inline bool operator!() const { return at >= endOfRow; } //: Not at valid element ? inline void Next() { RavlAssert(at != endOfRow); at++; } //: Goto next element. // Call ONLY if IsElm() is valid. inline void Next(int skip) { at += skip; } //: Advance 'skip' elements. // Call ONLY if you know this will not go past the end of the array. inline void operator++(int) { RavlAssert(at != endOfRow); at++; } //: Goto next element. // Call ONLY if IsElm() is valid. inline void operator++() { RavlAssert(at != endOfRow); at++; } //: Goto next element. // Call ONLY if IsElm() is valid. DataT &operator*() { return *at; } //: Access data. const DataT &operator*() const { return *at; } //: Access data. DataT *operator->() { return at; } //: Access data. const DataT *operator->() const { return at; } //: Access data. inline DataT &Data() { return *at; } //: Access data. inline const DataT &Data() const { return *at; } //: Access data. inline DataT &Data1() { return *at; } //: Access data. // Equivelent to .Data(), for compatability with other iterators. inline const DataT &Data1() const { return *at; } //: Const access data. // Equivelent to .Data(), for compatability with other iterators. inline void Invalidate(); //: Make IsElm() return false. protected: DataT *at; const DataT *endOfRow; }; ////////////////////////////////////////////////////// template inline BufferAccessIterC::BufferAccessIterC() : at(0), endOfRow(0) {} template inline bool BufferAccessIterC::First(const BufferAccessC &buff,const IndexRangeC &rng) { if(rng.Size() <= 0) { at = 0; endOfRow = 0; return false; } at = const_cast(&buff[rng.Min()]); endOfRow = &(at[rng.Size()]); return true; } template inline bool BufferAccessIterC::First(const BufferAccessC &buff,UIntT size) { if(size <= 0) { at = 0; endOfRow = 0; return false; } at = const_cast(buff.ReferenceElm()); endOfRow = &(at[size]); return true; } template inline bool BufferAccessIterC::First(const RangeBufferAccessC &buff) { if(buff.Size() <= 0) { at = 0; endOfRow = 0; return false; } at = const_cast(&buff[buff.IMin()]); endOfRow = &(at[buff.Size()]); return true; } template inline bool BufferAccessIterC::First(const SizeBufferAccessC &buff) { if(buff.Size() <= 0) { at = 0; endOfRow = 0; return false; } at = const_cast(buff.ReferenceElm()); endOfRow = &(at[buff.Size()]); return true; } template inline BufferAccessIterC & BufferAccessIterC::operator=(const RangeBufferAccessC &buff) { First(buff); return *this; } template inline BufferAccessIterC & BufferAccessIterC::operator=(const SizeBufferAccessC &buff) { First(buff); return *this; } template inline void BufferAccessIterC::Invalidate() { at = 0; endOfRow = 0; } } #endif