Annotation of parser3/src/include/pa_string.h, revision 1.12
1.1 paf 1: /*
1.12 ! paf 2: $Id: pa_string.h,v 1.11 2001/01/29 20:10:32 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:
1.9 paf 21: #ifdef HAVE_CONFIG_H
22: #include "pa_config.h"
23: #endif
24:
1.1 paf 25: #include <stddef.h>
26:
1.4 paf 27: #include "pa_types.h"
28:
1.1 paf 29: class Pool;
30:
1.9 paf 31: #ifndef NO_STRING_ORIGIN
1.12 ! paf 32: # define STRING_APPEND_PARAMS const char *src, char *file, uint line
1.10 paf 33: # define APPEND(src, file, line) real_append(src, file, line)
1.9 paf 34: #else
1.12 ! paf 35: # define STRING_APPEND_PARAMS const char *src
1.10 paf 36: # define APPEND(src, file, line) real_append(src)
1.9 paf 37: #endif
38:
39:
1.1 paf 40: class String {
41: public:
42: enum {
43: CR_PREALLOCATED_COUNT=5,
44: CR_GROW_PERCENT=60
45: };
46:
1.8 paf 47: public:
48:
1.11 paf 49: void *operator new(size_t size, Pool& apool);
50: String(Pool& apool);
1.8 paf 51: String(String& src);
52: size_t size() { return fsize; }
53: int used_rows() { return fused_rows; }
1.11 paf 54: char *cstr();
1.9 paf 55: String& real_append(STRING_APPEND_PARAMS);
1.8 paf 56: bool operator == (String& src);
57:
58: uint hash_code();
59:
1.10 paf 60: protected:
1.1 paf 61:
62: // the pool I'm allocated on
1.11 paf 63: Pool& pool;
1.1 paf 64:
1.10 paf 65: private:
66:
1.1 paf 67: struct Chunk {
1.6 paf 68: // the number of rows in chunk
1.1 paf 69: int count;
70: union Row {
71: // chunk item
72: struct {
1.12 ! paf 73: const char *ptr; // pointer to the start of string fragment
1.1 paf 74: size_t size; // length of the fragment
1.10 paf 75: Origin origin; // origin of this fragment
1.1 paf 76: } item;
77: Chunk *link; // link to the next chunk in chain
1.2 paf 78: } rows[CR_PREALLOCATED_COUNT];
1.1 paf 79: // next rows are here
80: Chunk *preallocated_link;
81: }
82: head; // the head chunk of the chunk chain
83:
84: // next append would write to this record
85: Chunk::Row *append_here;
86:
87: // the address of place where lies address
88: // of the link to the next chunk to allocate
89: Chunk::Row *link_row;
90:
1.5 paf 91: private:
92: // last chank allocated count
93: int curr_chunk_rows;
94:
95: // string size
96: size_t fsize;
97:
98: // used rows in all chunks
99: int fused_rows;
100:
101: private:
1.1 paf 102:
103: bool chunk_is_full() {
104: return append_here == link_row;
105: }
106: void expand();
1.7 paf 107:
108: private: //disabled
109:
1.12 ! paf 110: String& operator = (const String&) { return *this; }
1.7 paf 111:
1.1 paf 112: };
113:
114: #endif
E-mail: