00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00020 #ifndef flc_iterator_H
00021 #define flc_iterator_H
00022
00023 #include <falcon/setup.h>
00024 #include <falcon/types.h>
00025 #include <falcon/falcondata.h>
00026 #include <falcon/sequence.h>
00027 #include <falcon/fassert.h>
00028
00029 namespace Falcon {
00030 class Sequence;
00031 class CoreTable;
00032 class Garbageable;
00033 class Item;
00034
00100 class FALCON_DYN_CLASS Iterator: public FalconData
00101 {
00102
00103 public:
00104 typedef void(*t_deletor_func)(Iterator*);
00105
00106 private:
00107 Sequence* m_owner;
00108
00109 typedef union t_position_holder {
00110 int64 pos;
00111 void* ptr;
00112 } u_idata;
00113
00114 u_idata m_idata;
00115
00116 t_deletor_func m_deletor;
00117 Iterator* m_next;
00118
00119 public:
00120 Iterator( Sequence* owner, bool tail = false ):
00121 m_owner( owner ),
00122 m_deletor(0),
00123 m_next(0)
00124 {
00125 m_idata.ptr = 0;
00126 owner->getIterator( *this, tail );
00127 }
00128
00129 Iterator( const Iterator& other ):
00130 m_owner( other.m_owner ),
00131 m_deletor( other.m_deletor ),
00132 m_next(0)
00133 {
00134 m_idata.ptr = 0;
00135 m_owner->copyIterator( *this, other );
00136 }
00137
00138
00139 public:
00140 virtual ~Iterator();
00141 virtual void gcMark( uint32 mark );
00142 virtual FalconData *clone() const;
00143
00151 void deletor( t_deletor_func f ) { m_deletor = f; }
00152 t_deletor_func deletor() const { return m_deletor; }
00156 inline bool next() {
00157 fassert( m_owner != 0 );
00158 return m_owner->next( *this );
00159 }
00160
00164 inline bool prev() {
00165 fassert( m_owner != 0 );
00166 return m_owner->prev( *this );
00167 }
00168
00169 inline bool hasNext() const {
00170 return m_owner != 0 && m_owner->hasNext( *this );
00171 }
00172
00173 inline bool hasPrev() const {
00174 return m_owner != 0 && m_owner->hasPrev( *this );
00175 }
00176
00182 inline bool hasCurrent() const {
00183 return m_owner != 0 && m_owner->hasCurrent( *this );
00184 }
00185
00187 inline Item &getCurrent() const {
00188 fassert( m_owner != 0 );
00189 return m_owner->getCurrent( *this );
00190 }
00191
00195 inline Item &getCurrentKey() const {
00196 fassert( m_owner != 0 );
00197 return m_owner->getCurrentKey( *this );
00198 }
00199
00200 inline bool isValid() const { return m_owner != 0; }
00201 inline bool isOwner( void *collection ) const { return collection == static_cast<void*>(m_owner); }
00202
00203 inline bool equal( const Iterator &other ) const {
00204 fassert( m_owner != 0 );
00205 return m_owner == other.m_owner && m_owner->equalIterator( *this, other );
00206 }
00207
00218 inline void erase() {
00219 fassert( m_owner != 0 );
00220 m_owner->erase( *this );
00221 }
00222
00231 inline void insert( const Item &item ) {
00232 fassert( m_owner != 0 );
00233 m_owner->insert( *this, item );
00234 }
00235
00239 void invalidate() { m_owner = 0; }
00240
00241 Sequence* sequence() const { return m_owner; }
00242
00243 void sequence( Sequence* s ) { m_owner = s; }
00244
00245 void *data() const { return m_idata.ptr; }
00246 void data( void* dt ) { m_idata.ptr = dt; }
00247
00248 int64 position() const { return m_idata.pos; }
00249 void position( int64 pos ) { m_idata.pos = pos; }
00250
00251 Iterator* nextIter() const { return m_next; }
00252 void nextIter( Iterator* n ) { m_next = n; }
00253 };
00254
00255 }
00256
00257 #endif