00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00020 #ifndef flc_flc_carray_H
00021 #define flc_flc_carray_H
00022
00023 #include <falcon/types.h>
00024 #include <falcon/garbageable.h>
00025 #include <falcon/item.h>
00026 #include <falcon/deepitem.h>
00027 #include <falcon/sequence.h>
00028 #include <falcon/itemarray.h>
00029 #include <falcon/callpoint.h>
00030
00031 #define flc_ARRAY_GROWTH 128
00032
00033 namespace Falcon {
00034
00035 class Item;
00036 class Bindings;
00037 class LinearDict;
00038
00039
00040
00044 class FALCON_DYN_CLASS CoreArray: public DeepItem, public CallPoint
00045 {
00046 ItemArray m_itemarray;
00047 CoreDict *m_bindings;
00048 CoreObject *m_table;
00058 uint32 m_tablePos;
00059
00060 CoreArray( Item *buffer, uint32 size, uint32 alloc );
00061
00062 public:
00063
00065 CoreArray();
00066 CoreArray( const CoreArray& other );
00067 CoreArray( uint32 prealloc );
00068
00069 ~CoreArray();
00070
00071 virtual void gcMark( uint32 gen );
00072
00073 const ItemArray& items() const { return m_itemarray; }
00074 ItemArray& items() { return m_itemarray; }
00075
00076 void append( const Item &ndata ) {
00077 if ( m_table != 0 )
00078 return;
00079 m_itemarray.append( ndata );
00080 }
00081 void prepend( const Item &ndata ) {
00082 if ( m_table != 0 )
00083 return;
00084
00085 m_itemarray.prepend( ndata );
00086 }
00087
00088 void merge( const CoreArray &other ) {
00089 if ( m_table != 0 )
00090 return;
00091 m_itemarray.merge( other.m_itemarray );
00092 }
00093
00094 void merge_front( const CoreArray &other ) {
00095 if ( m_table != 0 )
00096 return;
00097 m_itemarray.merge( other.m_itemarray );
00098 }
00099
00100 bool insert( const Item &ndata, int32 pos ) {
00101 if ( m_table != 0 )
00102 return false;
00103 return m_itemarray.insert( ndata, pos );
00104 }
00105
00106 bool insert( const CoreArray &other, int32 pos ) {
00107 if ( m_table != 0 )
00108 return false;
00109 return m_itemarray.insert( other.m_itemarray, pos );
00110 }
00111
00112 bool remove( int32 pos ) {
00113 if ( m_table != 0 )
00114 return false;
00115 return m_itemarray.remove( pos );
00116 }
00117
00118 bool remove( int32 first, int32 last ) {
00119 if ( m_table != 0 )
00120 return false;
00121 return m_itemarray.remove( first, last );
00122 }
00123
00124 bool change( const CoreArray &other, int32 begin, int32 end ) {
00125 if ( m_table != 0 )
00126 return false;
00127
00128 return m_itemarray.change( other.m_itemarray, begin, end );
00129 }
00130
00131 int32 find( const Item &itm ) const { return m_itemarray.find( itm ); }
00132
00133 bool insertSpace( uint32 pos, uint32 size ) {
00134 if ( m_table != 0 )
00135 return false;
00136 return m_itemarray.insertSpace( pos, size );
00137 }
00138
00139 void resize( uint32 size ) {
00140 if ( m_table != 0 )
00141 return;
00142 m_itemarray.resize( size );
00143 }
00144
00145 void reserve( uint32 size ) {
00146 m_itemarray.reserve( size );
00147 }
00148
00149 CoreArray *partition( int32 start, int32 end ) const;
00150 CoreArray *clone() const;
00151
00152 uint32 length() const { return m_itemarray.length(); }
00153 void length( uint32 size ) { return m_itemarray.length( size ); }
00154
00156 CoreDict *makeBindings();
00157 CoreDict *bindings() const { return m_bindings; }
00158 void setBindings( CoreDict *binds ) { m_bindings = binds; }
00159
00168 Item* getProperty( const String &name );
00169
00179 void setProperty( const String &name, const Item &data );
00180
00185 bool checkPosBound( int32 &pos )
00186 {
00187 register int s = length();
00188 if ( pos < 0 )
00189 pos = s + pos;
00190 if ( pos < 0 || pos >= s )
00191 return false;
00192 return true;
00193 }
00194
00195 const Item &at( int32 pos ) const
00196 {
00197 return m_itemarray.at( pos );
00198 }
00199
00200 Item &at( int32 pos )
00201 {
00202 return m_itemarray.at( pos );
00203 }
00204
00205 Item &operator[]( int32 pos ) throw()
00206 {
00207 return m_itemarray[pos];
00208 }
00209
00210 const Item &operator[]( int32 pos ) const throw()
00211 {
00212 return m_itemarray[pos];
00213 }
00214
00215 CoreObject *table() const { return m_table; }
00216 void table( CoreObject *t ) { m_table = t; }
00217
00218 uint32 tablePos() const { return m_tablePos; }
00219 void tablePos( uint32 tp ) { m_tablePos = tp; }
00220
00221 virtual bool isFunc() const { return false; }
00222 virtual void readyFrame( VMachine* vm, uint32 paramCount );
00223 virtual const String& name() const;
00224
00225 virtual void readProperty( const String &prop, Item &item );
00226 virtual void writeProperty( const String &prop, const Item &item );
00227 virtual void readIndex( const Item &pos, Item &target );
00228 virtual void writeIndex( const Item &pos, const Item &target );
00229
00236 void canBeMethod( bool b ) {
00237 if ( m_table == 0 )
00238 m_tablePos = b ? 0 : (uint32) -1;
00239 }
00240
00244 bool canBeMethod() const { return m_table == 0 && m_tablePos == 0; }
00245 };
00246
00247 }
00248
00249 #endif
00250
00251