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