1/*
2    File:       ArrayIterator.h
3
4    Contains:   Interface to the CArrayIterator class
5
6
7*/
8
9#ifndef __CARRAYITERATOR_H
10#define __CARRAYITERATOR_H
11
12#include "IrDATypes.h"
13
14enum IterateDirection { kIterateBackward = 0, kIterateForward = 1 };
15
16
17class CList;
18class CSortedList;
19class CDynamicArray;
20
21
22//--------------------------------------------------------------------------------
23//      CArrayIterator
24//--------------------------------------------------------------------------------
25class CArrayIterator : public OSObject
26{
27    OSDeclareDefaultStructors(CArrayIterator);
28
29public:
30
31	// all four original functions retyped as factories.  probably don't
32	// use more than one style.
33
34	static  CArrayIterator* cArrayIterator();
35	static  CArrayIterator* cArrayIterator(CDynamicArray* itsDynamicArray);
36	static  CArrayIterator* cArrayIterator(CDynamicArray* itsDynamicArray, Boolean itsForward);
37	static  CArrayIterator* cArrayIterator(CDynamicArray* itsDynamicArray,
38			ArrayIndex itsLowBound, ArrayIndex itsHighBound,
39			Boolean itsForward);
40
41	void        free();
42
43	bool        init(void);
44	Boolean     init(CDynamicArray* itsDynamicArray);
45	Boolean     init(CDynamicArray* itsDynamicArray, Boolean itsForward);
46	Boolean     init(CDynamicArray* itsDynamicArray, ArrayIndex itsLowBound,
47			    ArrayIndex itsHighBound, Boolean itsForward);
48
49	void        InitBounds(ArrayIndex itsLowBound, ArrayIndex itsHighBound, Boolean itsForward);
50	void        Reset(void);
51	void        ResetBounds(Boolean goForward = true);
52
53	void        SwitchArray(CDynamicArray* newArray, Boolean itsForward = kIterateForward);
54
55	ArrayIndex  FirstIndex(void);
56	ArrayIndex  NextIndex(void);
57	ArrayIndex  CurrentIndex(void);
58
59	void        RemoveElementsAt(ArrayIndex theIndex, ArrayIndex theCount);
60	void        InsertElementsBefore(ArrayIndex theIndex, ArrayIndex theCount);
61	void        DeleteArray(void);
62
63	Boolean     More(void);
64
65protected:
66
67	void        Advance(void);
68
69	CDynamicArray*      fDynamicArray;          // the associated dynamic array
70
71	ArrayIndex          fCurrentIndex;          // current index of this iteration
72	ArrayIndex          fLowBound;              // lower bound of iteration in progress
73	ArrayIndex          fHighBound;             // upper bound of iteration in progress
74	Boolean             fIterateForward;        // if iteration is forward or backward
75
76private:
77
78friend class CDynamicArray;
79friend class CList;
80
81	CArrayIterator*     AppendToList(CArrayIterator* toList);
82	CArrayIterator*     RemoveFromList(void);
83
84	CArrayIterator*     fPreviousLink;          // link to previous iterator
85	CArrayIterator*     fNextLink;              // link to next iterator
86
87}; // CArrayIterator
88
89
90#endif  /*  __CARRAYITERATOR_H  */
91