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