//===========================================================================// // File: iterator.hh // // Project: MUNGA Brick: Connection Library // // Contents: Interface specifications for the abstract iterator // //---------------------------------------------------------------------------// // Date Who Modification // // -------- --- ---------------------------------------------------------- // // 10/19/94 ECH Initial coding. // // 10/20/94 JMA Fixed style stuff. // // 10/23/94 ECH Added Begin, End, Forward, Backward style iteration // // methods // // 10/23/94 ECH Added higher level of deletion safety // // 10/28/94 JMA Made compatible with SGI CC // // 11/03/94 ECH Made compatible with BC4.0 // // 01/04/95 ECH Added base methods for some iterator methods // //---------------------------------------------------------------------------// // Copyright (C) 1994-1995, Virtual World Entertainment, Inc. // // All Rights reserved worldwide // // This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL // //===========================================================================// #if !defined(ITERATOR_HPP) # define ITERATOR_HPP # if !defined(STYLE_HPP) # include # endif //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Iterator ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ typedef int CollectionSize; typedef int IteratorPosition; class Iterator SIGNATURED { public: // //-------------------------------------------------------------------- //-------------------------------------------------------------------- // Public interface to abstract class // // NOTE: All unsafe, untyped public methods are named XXXItem. The // safe, typed public methods are named XXX and are declared in the // template sub-classes. //-------------------------------------------------------------------- //-------------------------------------------------------------------- // // //-------------------------------------------------------------------- // Destructor and testing //-------------------------------------------------------------------- // virtual ~Iterator(); Logical TestInstance() const; // //-------------------------------------------------------------------- // First - Moves to next item // Last - Moves to last item //-------------------------------------------------------------------- // virtual void First(); virtual void Last(); // //-------------------------------------------------------------------- // Next - Moves to next item // Previous - Moves to previous item //-------------------------------------------------------------------- // virtual void Next(); virtual void Previous(); // //-------------------------------------------------------------------- // ReadAndNextItem - Returns current item and moves to next item // ReadAndPreviousItem - Returns current item and moves to prev item // GetCurrentItem - Returns current item //-------------------------------------------------------------------- // void* ReadAndNextItem() {return ReadAndNextImplementation();} void* ReadAndPreviousItem() {return ReadAndPreviousImplementation();} void* GetCurrentItem() {return GetCurrentImplementation();} // //-------------------------------------------------------------------- // GetSize - Returns number of items // GetNthItem - Returns nth item //-------------------------------------------------------------------- // virtual CollectionSize GetSize(); void* GetNthItem(CollectionSize index) {return GetNthImplementation(index);} // //-------------------------------------------------------------------- // BeginIterator - Moves to first item and returns iterator // EndIterator - Moves to last item and returns iterator //-------------------------------------------------------------------- // virtual Iterator& BeginIterator() {return BeginImplementation();} virtual Iterator& EndIterator() {return EndImplementation();} // //-------------------------------------------------------------------- // ForwardIterator - Moves to next item and returns iterator // BackwardIterator - Moves to previous item and returns iterator //-------------------------------------------------------------------- // virtual Iterator& ForwardIterator() {return ForwardImplementation();} virtual Iterator& BackwardIterator() {return BackwardImplementation();} protected: // //-------------------------------------------------------------------- //-------------------------------------------------------------------- // Protected interface to abstract class //-------------------------------------------------------------------- //-------------------------------------------------------------------- // Iterator(); // //-------------------------------------------------------------------- // Untyped implementations //-------------------------------------------------------------------- // virtual void* ReadAndNextImplementation(); virtual void* ReadAndPreviousImplementation(); virtual void* GetCurrentImplementation(); virtual void* GetNthImplementation(CollectionSize index); virtual Iterator& BeginImplementation() {First(); return *this;} virtual Iterator& EndImplementation() {Last(); return *this;} virtual Iterator& ForwardImplementation() {Next(); return *this;} virtual Iterator& BackwardImplementation() {Previous(); return *this;} }; #endif