|
|
| version 1.34, 2001/04/03 05:23:40 | version 1.38, 2001/05/15 15:51:05 |
|---|---|
| Line 39 public: | Line 39 public: |
| /// Array item type | /// Array item type |
| typedef void Item; | typedef void Item; |
| /*/// for_each iterator function type, const info | |
| typedef void (*For_each_func_const)(Item *value, const void *info); | |
| */ | |
| /// for_each iterator function type | /// for_each iterator function type |
| typedef void (*For_each_func)(Item *value, void *info); | typedef void (*For_each_func)(Item *value, void *info); |
| Line 50 public: | Line 54 public: |
| enum { | enum { |
| CR_INITIAL_ROWS_DEFAULT=10, ///< default preallocated row count | CR_INITIAL_ROWS_DEFAULT=10, ///< default preallocated row count |
| CR_GROW_PERCENT=60 ///< each time the Array chunk_is_full() array expanded() | CR_GROW_COUNT=10 ///< each time the Array chunk_is_full() array expanded() |
| }; | }; |
| public: | public: |
| Line 77 public: | Line 81 public: |
| int size() const { return fused_rows; } | int size() const { return fused_rows; } |
| /// append Item to array | /// append Item to array |
| Array& operator += (Item *src); | Array& operator += (Item *src); |
| /// append int value to array | |
| Array& operator += (int value) { return *this+=reinterpret_cast<Item *>(value); } | |
| /// dirty hack to allow constant items storage. I long for Array<const Item*> | /// dirty hack to allow constant items storage. I long for Array<const Item*> |
| Array& operator += (const Item *src) { return *this+=const_cast<Item*>(src); } | Array& operator += (const Item *src) { return *this+=const_cast<Item *>(src); } |
| /// append other Array portion to this one. starting from offset | /// append other Array portion to this one. starting from offset |
| Array& append_array(const Array& src, int offset=0); | Array& append_array(const Array& src, int offset=0); |
| Line 104 public: | Line 110 public: |
| } | } |
| Item *get(int index) const; | Item *get(int index) const; |
| int get_int(int index) const { return reinterpret_cast<int>(get(index)); } | |
| void put(int index, Item *item); | void put(int index, Item *item); |
| /// convinient way to get strings from Array. I long for Array<const String *> | /// convinient way to get strings from Array. I long for Array<const String *> |
| const String *get_string(int index) const { | const String *get_string(int index) const { |
| Line 113 public: | Line 121 public: |
| return const_cast<const String *>(static_cast<String *>(quick_get(index))); | return const_cast<const String *>(static_cast<String *>(quick_get(index))); |
| } | } |
| /*/// iterate over all elements, const info | |
| void for_each(For_each_func_const func, const void *info=0) const; | |
| /*/ | |
| /// iterate over all elements | /// iterate over all elements |
| void for_each(For_each_func func, void *info=0) const; | void for_each(For_each_func func, void *info=0) const; |
| Line 124 public: | Line 136 public: |
| private: | private: |
| /// several record elements | |
| struct Chunk { | struct Chunk { |
| // the number of rows in chunk | int count; ///< the number of rows in chunk |
| int count; | /// item or a link to next chunk union |
| union Row { | union Row { |
| Item *item; | Item *item; |
| Chunk *link; // link to the next chunk in chain | Chunk *link; ///< link to the next chunk in chain |
| } rows[1]; | } rows[1]; |
| // next rows are here | // next rows are here |
| } | } |
| *head; // the head chunk of the chunk chain | *head; ///< the head chunk of the chunk chain |
| // last allocated chunk | /** last allocated chunk |
| // helps appending Arrays | helps appending Arrays |
| */ | |
| Chunk *tail; | Chunk *tail; |
| // next append would write to this record | /// next append would write to this record |
| Chunk::Row *append_here; | Chunk::Row *append_here; |
| // the address of place where lies address | /** the address of place where lies address |
| // of the link to the next chunk to allocate | of the link to the next chunk to allocate |
| */ | |
| Chunk::Row *link_row; | Chunk::Row *link_row; |
| private: | private: |