Annotation of parser3/src/include/pa_string.h, revision 1.14
1.1 paf 1: /*
1.14 ! paf 2: $Id: pa_string.h,v 1.13 2001/01/29 21:51:51 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.14 ! paf 51: String(const String& src);
! 52: size_t size() const { return fsize; }
! 53: int used_rows() const { return fused_rows; }
! 54: char *cstr() const;
1.9 paf 55: String& real_append(STRING_APPEND_PARAMS);
1.14 ! paf 56: bool operator == (const String& src) const;
1.8 paf 57:
1.14 ! paf 58: uint hash_code() const;
1.13 paf 59:
60: const Origin& origin() const { return head.rows[0].item.origin; }
1.8 paf 61:
1.10 paf 62: protected:
1.1 paf 63:
64: // the pool I'm allocated on
1.11 paf 65: Pool& pool;
1.1 paf 66:
1.10 paf 67: private:
68:
1.1 paf 69: struct Chunk {
1.6 paf 70: // the number of rows in chunk
1.1 paf 71: int count;
72: union Row {
73: // chunk item
74: struct {
1.12 paf 75: const char *ptr; // pointer to the start of string fragment
1.1 paf 76: size_t size; // length of the fragment
1.10 paf 77: Origin origin; // origin of this fragment
1.1 paf 78: } item;
79: Chunk *link; // link to the next chunk in chain
1.2 paf 80: } rows[CR_PREALLOCATED_COUNT];
1.1 paf 81: // next rows are here
82: Chunk *preallocated_link;
83: }
84: head; // the head chunk of the chunk chain
85:
86: // next append would write to this record
87: Chunk::Row *append_here;
88:
89: // the address of place where lies address
90: // of the link to the next chunk to allocate
91: Chunk::Row *link_row;
92:
1.5 paf 93: private:
94: // last chank allocated count
95: int curr_chunk_rows;
96:
97: // string size
98: size_t fsize;
99:
100: // used rows in all chunks
101: int fused_rows;
102:
103: private:
1.1 paf 104:
105: bool chunk_is_full() {
106: return append_here == link_row;
107: }
108: void expand();
1.7 paf 109:
110: private: //disabled
111:
1.12 paf 112: String& operator = (const String&) { return *this; }
1.7 paf 113:
1.1 paf 114: };
115:
116: #endif
E-mail: