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