Annotation of parser3/src/include/pa_pool.h, revision 1.86.2.31

1.34      paf         1: /** @file
1.86.2.31! paf         2:        Parser: Pool class and helper operator decls
1.36      paf         3: 
1.86.2.22  paf         4:        Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com)
1.36      paf         5: 
1.78      paf         6:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.1       paf         7: */
                      8: 
                      9: #ifndef PA_POOL_H
                     10: #define PA_POOL_H
1.82      paf        11: 
1.86.2.31! paf        12: static const char* IDENT_POOL_H="$Date: 2003/02/19 16:19:00 $";
1.86.2.17  paf        13: 
                     14: // include
1.1       paf        15: 
1.52      parser     16: #include "pa_config_includes.h"
1.86.2.31! paf        17: #include "pa_array.h"
1.1       paf        18: 
1.86.2.31! paf        19: /** 
        !            20:        Pool mechanizm allows users not to free up allocated memory,
        !            21:        leaving that problem to 'pools'.
        !            22: */
        !            23: class Pool: public Array<CharPtr> {
1.86.2.2  paf        24: public:
1.86.2.31! paf        25:        char *malloc(size_t size) {
        !            26:                CharPtr result=CharPtr((char *)Array<CharPtr>::malloc(size));
        !            27:                *this += result;
        !            28:                return result.get();
1.86.2.9  paf        29:        }
1.86.2.2  paf        30: 
1.86.2.31! paf        31:        char *copy(const char* buf, size_t size=0) {
        !            32:                if(!size)
        !            33:                        size=strlen(buf)+1;
1.86.2.28  paf        34: 
1.86.2.31! paf        35:                char *result=malloc(size);
        !            36:                memcpy(result, buf, size);
        !            37:                return result;
1.86.2.28  paf        38:        }
                     39: 
1.86.2.31! paf        40:        char *format_integer(int value);
1.86.2.28  paf        41: };
                     42: 
                     43: /** 
1.86.2.31! paf        44:        Allocate something on pool, usage:
        !            45:                Something* something=new(pool) Something[count];
1.86.2.5  paf        46: 
1.86.2.31! paf        47:        with NO corresponding 
        !            48:        operator delete[] (Pool& pool)
        !            49:        it's Pool's responsibility to free that up
        !            50: */
        !            51: inline void *operator new[] (size_t size, Pool& pool) {
        !            52:        return pool.malloc(size);
        !            53: }
1.1       paf        54: 
                     55: #endif

E-mail: