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