--- parser3/src/include/pa_pool.h 2001/01/27 15:00:04 1.7 +++ parser3/src/include/pa_pool.h 2003/02/21 10:55:43 1.86.2.31 @@ -1,38 +1,55 @@ -/* - $Id: pa_pool.h,v 1.7 2001/01/27 15:00:04 paf Exp $ +/** @file + Parser: Pool class and helper operator decls + + Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com) + + Author: Alexandr Petrosian (http://paf.design.ru) */ #ifndef PA_POOL_H #define PA_POOL_H -#include +static const char* IDENT_POOL_H="$Date: 2003/02/21 10:55:43 $"; + +// include -#include "pa_string.h" -#include "pa_hash.h" +#include "pa_config_includes.h" #include "pa_array.h" -class Pool { +/** + Pool mechanizm allows users not to free up allocated memory, + leaving that problem to 'pools'. +*/ +class Pool: public Array { public: - Pool(); - ~Pool(); - void *malloc(size_t size); - void *calloc(size_t size); - - String *make_string() { - return new(this) String(this); - } - String *make_string(char *src) { - return new(this) String(this, src); + char *malloc(size_t size) { + CharPtr result=CharPtr((char *)Array::malloc(size)); + *this += result; + return result.get(); } - Hash *make_hash() { - return new(this) Hash(this); - } - Array *make_array() { - return new(this) Array(this); - } - Array *make_array(int initial_rows) { - return new(this) Array(this, initial_rows); + + char *copy(const char* buf, size_t size=0) { + if(!size) + size=strlen(buf)+1; + + char *result=malloc(size); + memcpy(result, buf, size); + return result; } + + char *format_integer(int value); }; +/** + Allocate something on pool, usage: + Something* something=new(pool) Something[count]; + + with NO corresponding + operator delete[] (Pool& pool) + it's Pool's responsibility to free that up +*/ +inline void *operator new[] (size_t size, Pool& pool) { + return pool.malloc(size); +} + #endif