Annotation of parser3/src/include/pa_array.h, revision 1.5
1.1 paf 1: /*
1.5 ! paf 2: $Id: pa_array.h,v 1.4 2001/01/29 09:38:33 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"
24:
25: class Pool;
26:
27: class Array {
28: public:
29: typedef void *Item;
30:
31: enum {
32: CR_PREALLOCATED_COUNT=10,
33: CR_GROW_PERCENT=60
34: };
35:
36: private:
37: friend Pool;
38:
39: // the pool I'm allocated on
40: Pool *pool;
41:
42: struct Chunk {
43: // the number of rows in chunk
44: int count;
45: union Row {
46: Item item;
47: Chunk *link; // link to the next chunk in chain
48: } rows[1];
49: // next rows are here
50: }
51: *head; // the head chunk of the chunk chain
52:
1.5 ! paf 53: // last allocated chunk
! 54: // helps appending Arrays
! 55: Chunk *tail;
! 56:
1.1 paf 57: // next append would write to this record
58: Chunk::Row *append_here;
59:
60: // the address of place where lies address
61: // of the link to the next chunk to allocate
62: Chunk::Row *link_row;
63:
64: private:
65: // array size
66: int fused_rows;
67:
1.3 paf 68: int cache_chunk_base;
69: Chunk *cache_chunk;
1.2 paf 70:
1.1 paf 71: private:
72: // new&constructors made private to enforce factory manufacturing at pool
73: void *operator new(size_t size, Pool *apool);
74:
75: void construct(Pool *apool, int initial_rows);
76: Array(Pool *apool) {
77: construct(apool, CR_PREALLOCATED_COUNT);
78: }
79: Array(Pool *apool, int initial_rows) {
80: construct(apool, initial_rows);
81: }
82:
83:
84: bool chunk_is_full() {
85: return append_here == link_row;
86: }
1.5 ! paf 87: void expand(int chunk_rows);
1.1 paf 88:
1.2 paf 89: public:
90:
91: int size() { return fused_rows; }
92: Array& operator += (Item src);
93: Item& operator [] (int index);
1.4 paf 94: Array& operator += (Array& src);
1.2 paf 95:
1.1 paf 96: private: //disabled
97:
98: Array& operator = (Array& src) { return *this; }
99: Array(Array& src) {}
100: };
101:
102: #endif
E-mail: