cgma
|
00001 #ifndef DYNAMIC_DLI_ITERATOR_HPP 00002 #define DYNAMIC_DLI_ITERATOR_HPP 00003 00004 #include "DLIList.hpp" 00005 00006 template <class ListType, class OutType> class CastingDLIIterator 00007 { 00008 public: 00009 typedef ListType* internal_type; 00010 typedef OutType* output_type; 00011 00012 CastingDLIIterator() 00013 {} 00014 virtual ~CastingDLIIterator() 00015 {} 00016 00017 void watch(const DLIList<internal_type> *dl_i_list) 00018 { mInternal.watch(dl_i_list); } 00019 00020 void reset() 00021 { mInternal.reset(); } 00022 00023 void step( int n = 1 ) 00024 { mInternal.step(n); } 00025 00026 int size() const 00027 { return mInternal.size(); } 00028 00029 output_type get() const 00030 { return dynamic_cast<output_type>(mInternal.next(0)); } 00031 00032 output_type next(int n = 1) const 00033 { return dynamic_cast<output_type>(mInternal.next(n)); } 00034 00035 output_type get_and_step(int n = 1) 00036 { return dynamic_cast<output_type>(mInternal.get_and_step(n)); } 00037 00038 CubitBoolean move_to(output_type item) 00039 { return mInternal.move_to(dynamic_cast<internal_type>(item)); } 00040 00041 CubitBoolean is_in_list(output_type item) const 00042 { return mInternal.is_in_list(dynamic_cast<internal_type>(item)); } 00043 00044 CubitBoolean is_at_end() const 00045 { return mInternal.is_at_end(); } 00046 00047 CubitBoolean is_at_beginning() const 00048 { return mInternal.is_at_beginning(); } 00049 00050 private: 00051 DLIListIterator<internal_type> mInternal; 00052 }; 00053 00054 template <class X> class DynamicDLIIterator 00055 { 00056 public: 00057 DynamicDLIIterator() 00058 {} 00059 virtual ~DynamicDLIIterator() 00060 {} 00061 00062 virtual void reset() = 0; 00063 virtual void step(int n = 1) = 0; 00064 virtual unsigned int size() const = 0; 00065 virtual X* get() const = 0; 00066 virtual X* next(int n = 1) const = 0; 00067 virtual X* get_and_step(int n = 1) = 0; 00068 virtual CubitBoolean move_to(X* item) = 0; 00069 virtual CubitBoolean is_in_list(X* item) const = 0; 00070 virtual CubitBoolean is_at_end() const = 0; 00071 virtual CubitBoolean is_at_beginning() const = 0; 00072 virtual DynamicDLIIterator<X>* clone() const = 0; 00073 }; 00074 00075 template<class ListType, class OutType> class DynamicDLIIteratorImpl : 00076 public DynamicDLIIterator<OutType>, 00077 public CastingDLIIterator<ListType, OutType> 00078 { 00079 public: 00080 DynamicDLIIteratorImpl() 00081 {} 00082 virtual ~DynamicDLIIteratorImpl() 00083 {} 00084 00085 virtual void reset() 00086 { CastingDLIIterator<ListType, OutType>::reset(); } 00087 00088 virtual void step(int n = 1) 00089 { CastingDLIIterator<ListType, OutType>::step(n); } 00090 00091 virtual unsigned int size() const 00092 { return CastingDLIIterator<ListType, OutType>::size(); } 00093 00094 virtual OutType* get() const 00095 { return CastingDLIIterator<ListType, OutType>::get(); } 00096 00097 virtual OutType* next(int n = 1) const 00098 { return CastingDLIIterator<ListType, OutType>::next(n); } 00099 00100 virtual OutType* get_and_step(int n = 1) 00101 { return CastingDLIIterator<ListType, OutType>::get_and_step(n); } 00102 00103 virtual CubitBoolean move_to(OutType* item) 00104 { return CastingDLIIterator<ListType, OutType>::move_to(item); } 00105 00106 virtual CubitBoolean is_in_list(OutType* item) const 00107 { return CastingDLIIterator<ListType, OutType>::is_in_list(item); } 00108 00109 virtual CubitBoolean is_at_end() const 00110 { return CastingDLIIterator<ListType, OutType>::is_at_end(); } 00111 00112 virtual CubitBoolean is_at_beginning() const 00113 { return CastingDLIIterator<ListType, OutType>::is_at_beginning(); } 00114 00115 virtual DynamicDLIIterator<OutType>* clone() const 00116 { 00117 DynamicDLIIteratorImpl<ListType, OutType>* rv = new DynamicDLIIteratorImpl<ListType, OutType>; 00118 *rv = *this; 00119 return rv; 00120 } 00121 }; 00122 00123 template <class ListType, class OutType> class CastingDynamicDLIIterator : 00124 public DynamicDLIIterator<OutType> 00125 { 00126 public: 00127 typedef ListType* internal_type; 00128 typedef OutType* output_type; 00129 00130 CastingDynamicDLIIterator(DynamicDLIIterator<ListType>* internal) 00131 : mInternal(internal) 00132 {} 00133 virtual ~CastingDynamicDLIIterator() 00134 { delete mInternal; } 00135 00136 void reset() 00137 { mInternal->reset(); } 00138 00139 void step( int n = 1 ) 00140 { mInternal->step(n); } 00141 00142 unsigned int size() const 00143 { return mInternal->size(); } 00144 00145 output_type get() const 00146 { return dynamic_cast<output_type>(mInternal->next(0)); } 00147 00148 output_type next(int n = 1) const 00149 { return dynamic_cast<output_type>(mInternal->next(n)); } 00150 00151 output_type get_and_step(int n = 1) 00152 { return dynamic_cast<output_type>(mInternal->get_and_step(n)); } 00153 00154 CubitBoolean move_to(output_type item) 00155 { return mInternal->move_to(dynamic_cast<internal_type>(item)); } 00156 00157 CubitBoolean is_in_list(output_type item) const 00158 { return mInternal->is_in_list(dynamic_cast<internal_type>(item)); } 00159 00160 CubitBoolean is_at_end() const 00161 { return mInternal->is_at_end(); } 00162 00163 CubitBoolean is_at_beginning() const 00164 { return mInternal->is_at_beginning(); } 00165 00166 DynamicDLIIterator<OutType>* clone() const 00167 { return new CastingDynamicDLIIterator(mInternal->clone()); } 00168 00169 00170 private: 00171 DynamicDLIIterator<ListType>* mInternal; 00172 }; 00173 00174 00175 #endif 00176