00001 //------------------------------------------------------------------------------ 00002 #ifndef d_Iterator_h 00003 #define d_Iterator_h 1 00004 //------------------------------------------------------------------------------ 00005 00006 #include "oCollBlock.h" 00007 //------------------------------------------------------------------------------ 00008 00009 template <class T> class d_Collection; 00010 //------------------------------------------------------------------------------ 00011 00012 /** 00013 * This is the class used for iterating over the elements of a generic collection. 00014 * 00015 * LOCATION: 00016 * d_Iterator.h 00017 * 00018 * USAGE: 00019 * d_Iterator< <type-name> > <variable-name>; 00020 * 00021 * Where: 00022 * 00023 * <type-name>: Type to iterate. Can be a literal or a user type 00024 * <variable-name>: is the name of d_Iterator object 00025 * 00026 * EXAMPLES: 00027 * d_Varray<d_String> stringColl; * Collection 00028 * d_Iterator<d_String> iter = stringColl.create_iterator(); 00029 * 00030 * SEE ALSO: 00031 * d_Bag, d_Collection, d_Dictionary, d_List, d_Set, d_Varray 00032 * 00033 * ODMG: 00034 * Compliant 00035 */ 00036 00037 template <class T> 00038 class d_Iterator 00039 { 00040 public: 00041 00042 /** 00043 * Default Constructor. 00044 * 00045 * ODMG : Compliant 00046 */ 00047 d_Iterator (); 00048 00049 /** 00050 * Copy Constructor. 00051 * 00052 * Current iterator object and <iSource> are totally independent, thus 00053 * they can browse the same collection with no conflict. 00054 * 00055 * ODMG : Compliant 00056 */ 00057 d_Iterator (const d_Iterator<T>& iSource); 00058 00059 /** 00060 * Create a d_Iterator object by a collection. 00061 * 00062 * The new iterator point at the first element of collection. 00063 * 00064 * SEE ALSO: d_Collection::create_iterator() 00065 * ODMG : Extension 00066 */ 00067 d_Iterator (d_Collection<T>* iColl); 00068 00069 /** 00070 * Destructor. 00071 * 00072 * ODMG : Compliant 00073 */ 00074 ~d_Iterator(); 00075 00076 /** 00077 * Replaces current element. 00078 * 00079 * Replaces the value of the current element pointed by the iterator with 00080 * <iValue>. This method can be used only with d_List and d_Varray 00081 * collections. 00082 * 00083 * ODMG : Compliant 00084 */ 00085 void replace_element (const T &iValue); 00086 00087 /** 00088 * Removes the current element pointed by the iterator. 00089 * 00090 * ODMG : Compliant 00091 */ 00092 void remove_element (); 00093 00094 /** 00095 * Returns the value of current element. 00096 * 00097 * SEE ALSO: get_element() 00098 * ODMG : Compliant 00099 */ 00100 T operator * (); 00101 00102 /** 00103 * Returns the value of current element. 00104 * 00105 * SEE ALSO: operator*() 00106 * ODMG : Compliant 00107 */ 00108 T get_element (); 00109 00110 /** 00111 * Returns true if the iteration is not completed and there are some 00112 * elements to visit. 00113 * 00114 * Call this method to determine whether iteration is complete (usually 00115 * in a loop). 00116 * 00117 * ODMG : Compliant 00118 */ 00119 d_Boolean not_done (); 00120 00121 /** 00122 * Advances the iterator to the next element of collection. 00123 * 00124 * Use it without specifying <current> parameter (default = false). 00125 * 00126 * SEE ALSO: operator ++(), next() 00127 * ODMG : Compliant 00128 */ 00129 void advance (d_Boolean current = d_False); 00130 00131 /** 00132 * This is the prefix increment operator. 00133 * 00134 * It advances to the next element in the collection and returns it. If 00135 * this method is called after that the iterator has reached the end of 00136 * iteration, a d_Error_IteratorExhausted exception is thrown. 00137 * 00138 * SEE ALSO: advance(), next() 00139 * ODMG : Compliant 00140 */ 00141 d_Iterator<T>& operator ++ (); 00142 00143 /** 00144 * This is the postfix increment operator. 00145 * 00146 * It advances to the next element in the collection and returns the 00147 * element pointed by iterator before the advancing. If this method is 00148 * called after that the iterator has reached the end of iteration, a 00149 * d_Error_IteratorExhausted exception is thrown. 00150 * 00151 * SEE ALSO: advance(), next() 00152 * ODMG : Compliant 00153 */ 00154 d_Iterator<T> operator ++ (const int iStep); 00155 00156 /** 00157 * Checks the end of iteration and returns current value. 00158 * 00159 * It returns false if the iterator is positioned past the last element of 00160 * iteration, otherwise assigns current value to <iValue> parameter, 00161 * advances the iterator, and returns true. 00162 * 00163 * SEE ALSO: advance(), operator ++() 00164 * ODMG : Compliant 00165 */ 00166 d_Boolean next (T& iValue); 00167 00168 00169 // Internal. 00170 void assign (const d_Collection<T>* iColl, d_Ref<oCollBlock<T> >& iBlock, const oUInt2 iPos); 00171 00172 // Internal. 00173 d_Collection<T> *collection; 00174 // Internal. 00175 d_Ref<oCollBlock< T > > currBlock; 00176 00177 private: 00178 // Internal. 00179 d_UShort posInBlock; 00180 }; 00181 //------------------------------------------------------------------------------ 00182 00183 #include "d_Iterator.cti" 00184 //------------------------------------------------------------------------------ 00185 //------------------------------------------------------------------------------ 00186 00187 #endif
1.3-rc1