Annotation of parser3/src/include/pa_string.h, revision 1.4
1.1 paf 1: /*
1.4 ! paf 2: $Id: pa_string.h,v 1.3 2001/01/26 18:55:55 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:
34: private:
35: friend Pool;
36:
37: // the pool I'm allocated on
38: Pool *pool;
39:
40: // last chank allocated count cache
41: int curr_chunk_rows;
42: struct Chunk {
43: // the number of rows per chunk
44: int count;
45: union Row {
46: // chunk item
47: struct {
48: char *ptr; // pointer to the start of string fragment
49: size_t size; // length of the fragment
50: } item;
51: Chunk *link; // link to the next chunk in chain
1.2 paf 52: } rows[CR_PREALLOCATED_COUNT];
1.1 paf 53: // next rows are here
54: Chunk *preallocated_link;
55: }
56: head; // the head chunk of the chunk chain
57:
58: // next append would write to this record
59: Chunk::Row *append_here;
60:
61: // the address of place where lies address
62: // of the link to the next chunk to allocate
63: Chunk::Row *link_row;
64:
65: // new&constructors made private to enforce factory manufacturing at pool
66: void *operator new(size_t size, Pool *apool);
67:
68: void construct(Pool *apool);
1.2 paf 69: String() { /* never */}
1.1 paf 70: String(Pool *apool) {
71: construct(apool);
72: }
73: String(Pool *apool, char *src) {
74: construct(apool);
75: *this+=src;
76: }
77:
78: bool chunk_is_full() {
79: return append_here == link_row;
80: }
81: void expand();
1.2 paf 82: int used_rows();
1.1 paf 83:
84: public:
85:
1.2 paf 86: String(String& src);
1.1 paf 87: size_t size();
88: char *c_str();
89: String& operator += (char *src);
1.2 paf 90: bool operator == (String& src);
1.3 paf 91: String& operator = (String& src);
1.2 paf 92:
1.4 ! paf 93: uint hash_code();
1.1 paf 94: };
95:
96: #endif
E-mail: