Annotation of parser3/src/include/pa_string.h, revision 1.9

1.1       paf         1: /*
1.9     ! paf         2:   $Id: pa_string.h,v 1.8 2001/01/29 12:00:45 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
        !            32: #      define STRING_APPEND_PARAMS char *src, char *origin, uint line
        !            33: #      define APPEND(src, origin, line) real_append(src, origin, line)
        !            34: #else
        !            35: #      define STRING_APPEND_PARAMS char *src
        !            36: #      define APPEND(src, origin, line) real_append(src)
        !            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: 
                     49:        String(String& src);
                     50:        size_t size() { return fsize; }
                     51:        int used_rows() { return fused_rows; }
                     52:        char *c_str();
1.9     ! paf        53:        String& real_append(STRING_APPEND_PARAMS);
1.8       paf        54:        bool operator == (String& src);
                     55: 
                     56:        uint hash_code();
                     57: 
1.1       paf        58: private:
                     59:        friend Pool;
                     60: 
                     61:        // the pool I'm allocated on
                     62:        Pool *pool;
                     63: 
                     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 {
                     70:                                char *ptr;  // pointer to the start of string fragment
                     71:                                size_t size;  // length of the fragment
1.9     ! paf        72: #ifndef NO_STRING_ORIGIN
        !            73:                                char *origin;  // macros file name | load file name | sql query text
        !            74:                                uint line; // file line no | record no
        !            75: #endif
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:        // new&constructors made private to enforce factory manufacturing at pool
                    103:        void *operator new(size_t size, Pool *apool);
                    104: 
1.9     ! paf       105:        String(Pool *apool);
1.1       paf       106: 
                    107:        bool chunk_is_full() {
                    108:                return append_here == link_row;
                    109:        }
                    110:        void expand();
1.7       paf       111: 
                    112: private: //disabled
                    113: 
                    114:        String& operator = (String& src) { return *this; }
                    115: 
1.1       paf       116: };
                    117: 
                    118: #endif

E-mail: