File:  [parser3project] / parser3 / src / include / pa_pool.h
Revision 1.89: download - view: text, annotated - select for diffs - revision graph
Thu Nov 20 16:32:12 2003 UTC (22 years, 7 months ago) by paf
Branches: MAIN
CVS tags: release_3_4_1, release_3_4_0, release_3_3_0, release_3_2_3, release_3_2_2, release_3_2_1, release_3_2_0, release_3_1_6, release_3_1_5, release_3_1_4, release_3_1_3, release_3_1_2, paf_left, HEAD
more warnings --

/** @file
	Parser: pool class decl.

	Copyright (c) 2001, 2003 ArtLebedev Group (http://www.artlebedev.com)

	Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
*/

#ifndef PA_POOL_H
#define PA_POOL_H

static const char * const IDENT_POOL_H="$Date: 2003/11/20 16:32:12 $";

#include "pa_config_includes.h"
#include "pa_array.h"

/** 
	Pool mechanizm allows users not to free up allocated objects,
	leaving that problem to 'pools'.

	@see Pooled
*/

class Pool {
public:

	struct Cleanup {
		void (*cleanup) (void *);
		void *data;

		Cleanup(void (*acleanup) (void *), void *adata): cleanup(acleanup), data(adata) {}
	};

	Pool();
	~Pool();

	/// registers a routine to clean up non-pooled allocations
	void register_cleanup(void (*cleanup) (void *), void *data);
	/// unregister it, looking it up by it's data
	void unregister_cleanup(void *cleanup_data);

private:

	Array<Cleanup> cleanups;

private: 
	
	//{
	/// @name implementation defined
	bool real_register_cleanup(void (*cleanup) (void *), void *data);
	//}

private: 

	/// throws register cleanup exception
	void fail_register_cleanup() const;

private: //disabled

	Pool(const Pool&);
	Pool& operator= (const Pool&);
};

/** 
	Base for all classes that are allocated in 'pools'.
	Holds Pool object.
*/
class Pooled {
	// the pool i'm allocated on
	Pool& fpool;
public:

	Pooled(Pool& apool);

	/// my pool
	//Pool& pool() const { return *fpool; }

	/// Sole: this got called automatically from Pool::~Pool()
	virtual ~Pooled();

};

#endif

E-mail: