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

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.32! paf        12: static const char* IDENT_POOL_H="$Date: 2003/02/21 10:55:43 $";
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.32! paf        41: 
1.86.2.28  paf        42: };
                     43: 
                     44: /** 
1.86.2.31  paf        45:        Allocate something on pool, usage:
                     46:                Something* something=new(pool) Something[count];
1.86.2.5  paf        47: 
1.86.2.31  paf        48:        with NO corresponding 
                     49:        operator delete[] (Pool& pool)
                     50:        it's Pool's responsibility to free that up
                     51: */
                     52: inline void *operator new[] (size_t size, Pool& pool) {
                     53:        return pool.malloc(size);
                     54: }
1.1       paf        55: 
                     56: #endif

E-mail: