00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef FALCON_ITEMARRAY_H_
00017 #define FALCON_ITEMARRAY_H_
00018
00019 #include <falcon/setup.h>
00020 #include <falcon/sequence.h>
00021 #include <falcon/item.h>
00022 #include <falcon/iterator.h>
00023
00024 namespace Falcon
00025 {
00026
00027 class CoreArray;
00028 class CoreTable;
00029
00030 class FALCON_DYN_CLASS ItemArray: public Sequence
00031 {
00032 uint32 m_alloc;
00033 uint32 m_size;
00034 Item *m_data;
00035 Garbageable* m_owner;
00036
00037
00038
00039 uint32 m_invalidPoint;
00040
00041 friend class CoreArray;
00042 friend class CoreTable;
00043
00044 ItemArray( Item *buffer, uint32 size, uint32 alloc );
00045
00046 public:
00047 ItemArray();
00048 ItemArray( const ItemArray& other );
00049 ItemArray( uint32 prealloc );
00050
00051 virtual ~ItemArray();
00052
00053 virtual const Item &front() const { return m_data[0]; }
00054 virtual const Item &back() const { return m_data[m_size-1]; }
00055
00056 Item *elements() const { return m_data; }
00057 void elements( Item *d ) { m_data = d; }
00058 uint32 allocated() const { return m_alloc; }
00059 uint32 length() const { return m_size; }
00060 void length( uint32 size ) { m_size = size; }
00061 void allocated( uint32 size ) { m_alloc = size; }
00062
00063 virtual void clear() { m_size = 0; }
00064 virtual bool empty() const { return m_size == 0; }
00065
00066 virtual void gcMark( uint32 mark );
00067 virtual FalconData *clone() const ;
00068
00069 virtual void append( const Item &ndata );
00070 virtual void prepend( const Item &ndata );
00071
00072 void merge( const ItemArray &other );
00073 void merge_front( const ItemArray &other );
00074
00075 bool insert( const Item &ndata, int32 pos );
00076 bool insert( const ItemArray &other, int32 pos );
00077 bool remove( int32 pos );
00078 bool remove( int32 first, int32 last );
00079 bool change( const ItemArray &other, int32 begin, int32 end );
00080 int32 find( const Item &itm ) const;
00081 bool insertSpace( uint32 pos, uint32 size );
00082
00083 void resize( uint32 size );
00087 void compact();
00088 void reserve( uint32 size );
00089
00090 ItemArray *partition( int32 start, int32 end ) const;
00091
00114 bool copyOnto( uint32 from, const ItemArray& src, uint32 first=0, uint32 amount=0xFFFFFFFF );
00115
00123 bool copyOnto( const ItemArray& src, uint32 first=0, uint32 amount=0xFFFFFFFF )
00124 {
00125 return copyOnto( 0, src, first, amount );
00126 }
00127
00128 inline virtual const Item &at( int32 pos ) const
00129 {
00130 if ( pos < 0 )
00131 pos = m_size + pos;
00132 if ( pos < 0 || pos > (int32) m_size )
00133 throw "Invalid range while accessing Falcon::CoreArray";
00134 return m_data[pos];
00135 }
00136
00137 inline virtual Item &at( int32 pos )
00138 {
00139 if ( pos < 0 )
00140 pos = m_size + pos;
00141 if ( pos < 0 || pos > (int32)m_size )
00142 throw "Invalid range while accessing Falcon::CoreArray";
00143 return m_data[pos];
00144 }
00145
00146 inline Item &operator[]( int32 pos ) throw()
00147 {
00148 return m_data[pos];
00149 }
00150
00151 inline const Item &operator[]( int32 pos ) const throw()
00152 {
00153 return m_data[pos];
00154 }
00155
00156
00162 int32 esize( int32 count=1 ) const { return sizeof( Item ) * count; }
00163
00164
00165
00166
00167 protected:
00168
00169 virtual void getIterator( Iterator& tgt, bool tail = false ) const;
00170 virtual void copyIterator( Iterator& tgt, const Iterator& source ) const;
00171
00172 virtual void insert( Iterator &iter, const Item &data );
00173 virtual void erase( Iterator &iter );
00174 virtual bool hasNext( const Iterator &iter ) const;
00175 virtual bool hasPrev( const Iterator &iter ) const;
00176 virtual bool hasCurrent( const Iterator &iter ) const;
00177 virtual bool next( Iterator &iter ) const;
00178 virtual bool prev( Iterator &iter ) const;
00179 virtual Item& getCurrent( const Iterator &iter );
00180 virtual Item& getCurrentKey( const Iterator &iter );
00181 virtual bool equalIterator( const Iterator &first, const Iterator &second ) const;
00182
00183 virtual bool onCriterion( Iterator* elem ) const;
00184 };
00185
00186 }
00187
00188 #endif
00189
00190
00191