Annotation of parser3/src/include/pa_string.h, revision 1.8
1.1 paf 1: /*
1.8 ! paf 2: $Id: pa_string.h,v 1.7 2001/01/27 15:21:05 paf Exp $
1.1 paf 3: */
4:
5: /*
6:
7: String Chunk0
8: ====== ========
9: head--------->[ptr, size]
10: append_here-------->[ptr, size]
11: link_row ........
12: . .
13: . [ptr, size]
14: ...........>[link to the next chunk]
15:
16: */
17:
18: #ifndef PA_STRING_H
19: #define PA_STRING_H
20:
21: #include <stddef.h>
22:
1.4 paf 23: #include "pa_types.h"
24:
1.1 paf 25: class Pool;
26:
27: class String {
28: public:
29: enum {
30: CR_PREALLOCATED_COUNT=5,
31: CR_GROW_PERCENT=60
32: };
33:
1.8 ! paf 34: public:
! 35:
! 36: String(String& src);
! 37: size_t size() { return fsize; }
! 38: int used_rows() { return fused_rows; }
! 39: char *c_str();
! 40: String& operator += (char *src);
! 41: bool operator == (String& src);
! 42:
! 43: uint hash_code();
! 44:
1.1 paf 45: private:
46: friend Pool;
47:
48: // the pool I'm allocated on
49: Pool *pool;
50:
51: struct Chunk {
1.6 paf 52: // the number of rows in chunk
1.1 paf 53: int count;
54: union Row {
55: // chunk item
56: struct {
57: char *ptr; // pointer to the start of string fragment
58: size_t size; // length of the fragment
59: } item;
60: Chunk *link; // link to the next chunk in chain
1.2 paf 61: } rows[CR_PREALLOCATED_COUNT];
1.1 paf 62: // next rows are here
63: Chunk *preallocated_link;
64: }
65: head; // the head chunk of the chunk chain
66:
67: // next append would write to this record
68: Chunk::Row *append_here;
69:
70: // the address of place where lies address
71: // of the link to the next chunk to allocate
72: Chunk::Row *link_row;
73:
1.5 paf 74: private:
75: // last chank allocated count
76: int curr_chunk_rows;
77:
78: // string size
79: size_t fsize;
80:
81: // used rows in all chunks
82: int fused_rows;
83:
84: private:
1.1 paf 85: // new&constructors made private to enforce factory manufacturing at pool
86: void *operator new(size_t size, Pool *apool);
87:
88: void construct(Pool *apool);
89: String(Pool *apool) {
90: construct(apool);
91: }
92: String(Pool *apool, char *src) {
93: construct(apool);
94: *this+=src;
95: }
96:
97: bool chunk_is_full() {
98: return append_here == link_row;
99: }
100: void expand();
1.7 paf 101:
102: private: //disabled
103:
104: String& operator = (String& src) { return *this; }
105:
1.1 paf 106: };
107:
108: #endif
E-mail: