Annotation of parser3/src/include/pa_array.h, revision 1.12
1.1 paf 1: /*
1.12 ! paf 2: $Id: pa_array.h,v 1.11 2001/01/29 20:10:31 paf Exp $
1.1 paf 3: */
4:
5: /*
6:
7: Array Chunk0
8: ====== ========
9: head--------------->[ptr]
10: append_here-------->[ptr]
11: link_row ........
12: . .
13: . [ptr]
14: ...........>[link to the next chunk]
15:
16: */
17:
18: #ifndef PA_ARRAY_H
19: #define PA_ARRAY_H
20:
21: #include <stddef.h>
22:
23: #include "pa_types.h"
1.11 paf 24: #include "pa_string.h"
1.1 paf 25:
26: class Pool;
27:
1.10 paf 28: class Array {
1.1 paf 29: public:
1.7 paf 30:
1.11 paf 31: typedef void Item;
1.10 paf 32:
1.1 paf 33: enum {
1.7 paf 34: CR_INITIAL_ROWS_DEFAULT=10,
1.1 paf 35: CR_GROW_PERCENT=60
36: };
37:
1.6 paf 38: public:
39:
1.11 paf 40: void *operator new(size_t size, Pool& apool);
41: Array(Pool& apool, int initial_rows=CR_INITIAL_ROWS_DEFAULT);
1.7 paf 42:
1.12 ! paf 43: int size() const { return fused_rows; }
! 44: Array& operator += (const Item *src);
! 45: Array& append_array(const Array& src);
! 46: const Item *get(int index) const;
! 47: const char *get_cstr(int index) const {
! 48: return static_cast<const char *>(get(index));
! 49: }
! 50: const String *get_string(int index) const {
! 51: return static_cast<const String *>(get(index));
! 52: }
1.6 paf 53:
1.7 paf 54: protected:
1.1 paf 55:
56: // the pool I'm allocated on
1.11 paf 57: Pool& pool;
1.1 paf 58:
1.7 paf 59: private:
60:
1.1 paf 61: struct Chunk {
62: // the number of rows in chunk
63: int count;
64: union Row {
1.12 ! paf 65: const Item *item;
1.1 paf 66: Chunk *link; // link to the next chunk in chain
67: } rows[1];
68: // next rows are here
69: }
70: *head; // the head chunk of the chunk chain
71:
1.5 paf 72: // last allocated chunk
73: // helps appending Arrays
74: Chunk *tail;
75:
1.1 paf 76: // next append would write to this record
77: Chunk::Row *append_here;
78:
79: // the address of place where lies address
80: // of the link to the next chunk to allocate
81: Chunk::Row *link_row;
82:
83: private:
1.7 paf 84:
1.1 paf 85: // array size
86: int fused_rows;
87:
1.12 ! paf 88: mutable int cache_chunk_base;
! 89: mutable Chunk *cache_chunk;
1.2 paf 90:
1.1 paf 91: private:
92:
93: bool chunk_is_full() {
94: return append_here == link_row;
95: }
1.5 paf 96: void expand(int chunk_rows);
1.2 paf 97:
1.1 paf 98: private: //disabled
99:
1.11 paf 100: //Array(Array&) { }
1.12 ! paf 101: Array& operator = (const Array&) { return *this; }
1.1 paf 102: };
103:
104: #endif
E-mail: