src/oldpool.h
author rubidium
Tue, 18 Dec 2007 19:52:14 +0000
changeset 8100 6bc08f98ec16
parent 7974 dfe3185a62d2
child 8113 31b7784db761
permissions -rw-r--r--
(svn r11661) -Codechange: some header reworks in order to try to reduce the compile time of OpenTTD by reduce the amount of circular-ish dependencies.
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 1259
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 1259
diff changeset
     2
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6248
diff changeset
     3
/** @file oldpool.h */
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6248
diff changeset
     4
5224
df36f84cbb6c (svn r7341) - Codechange: Also rename the POOL_H define to OLDPOOL_H (forgotten in r7331).
matthijs
parents: 5216
diff changeset
     5
#ifndef OLDPOOL_H
df36f84cbb6c (svn r7341) - Codechange: Also rename the POOL_H define to OLDPOOL_H (forgotten in r7331).
matthijs
parents: 5216
diff changeset
     6
#define OLDPOOL_H
1259
8d8515e3da29 (svn r1763) -Add: pool.c / pool.h: generalized routines for dynamic arrays (MemoryPools)
truelight
parents:
diff changeset
     7
8d8515e3da29 (svn r1763) -Add: pool.c / pool.h: generalized routines for dynamic arrays (MemoryPools)
truelight
parents:
diff changeset
     8
/* The function that is called after a new block is added
8d8515e3da29 (svn r1763) -Add: pool.c / pool.h: generalized routines for dynamic arrays (MemoryPools)
truelight
parents:
diff changeset
     9
     start_item is the first item of the new made block */
5216
8bd14ee39af2 (svn r7331) - Codechange: Rename all memory pool macro's and types to "old pool", so the new pool implementation can be committed alongside it.
matthijs
parents: 4986
diff changeset
    10
typedef void OldMemoryPoolNewBlock(uint start_item);
3585
43461f26b729 (svn r4471) - Pools: Add a facility for calling a custom function during pool block clean up.
peter1138
parents: 3173
diff changeset
    11
/* The function that is called before a block is cleaned up */
5216
8bd14ee39af2 (svn r7331) - Codechange: Rename all memory pool macro's and types to "old pool", so the new pool implementation can be committed alongside it.
matthijs
parents: 4986
diff changeset
    12
typedef void OldMemoryPoolCleanBlock(uint start_item, uint end_item);
1259
8d8515e3da29 (svn r1763) -Add: pool.c / pool.h: generalized routines for dynamic arrays (MemoryPools)
truelight
parents:
diff changeset
    13
8d8515e3da29 (svn r1763) -Add: pool.c / pool.h: generalized routines for dynamic arrays (MemoryPools)
truelight
parents:
diff changeset
    14
/**
5216
8bd14ee39af2 (svn r7331) - Codechange: Rename all memory pool macro's and types to "old pool", so the new pool implementation can be committed alongside it.
matthijs
parents: 4986
diff changeset
    15
 * Stuff for dynamic vehicles. Use the wrappers to access the OldMemoryPool
1259
8d8515e3da29 (svn r1763) -Add: pool.c / pool.h: generalized routines for dynamic arrays (MemoryPools)
truelight
parents:
diff changeset
    16
 *  please try to avoid manual calls!
8d8515e3da29 (svn r1763) -Add: pool.c / pool.h: generalized routines for dynamic arrays (MemoryPools)
truelight
parents:
diff changeset
    17
 */
7375
961ab798c4b6 (svn r10744) -Codechange: make the pool a little more OO, so it can be easier in other places.
rubidium
parents: 6351
diff changeset
    18
struct OldMemoryPoolBase {
961ab798c4b6 (svn r10744) -Codechange: make the pool a little more OO, so it can be easier in other places.
rubidium
parents: 6351
diff changeset
    19
	void CleanPool();
961ab798c4b6 (svn r10744) -Codechange: make the pool a little more OO, so it can be easier in other places.
rubidium
parents: 6351
diff changeset
    20
	bool AddBlockToPool();
961ab798c4b6 (svn r10744) -Codechange: make the pool a little more OO, so it can be easier in other places.
rubidium
parents: 6351
diff changeset
    21
	bool AddBlockIfNeeded(uint index);
961ab798c4b6 (svn r10744) -Codechange: make the pool a little more OO, so it can be easier in other places.
rubidium
parents: 6351
diff changeset
    22
961ab798c4b6 (svn r10744) -Codechange: make the pool a little more OO, so it can be easier in other places.
rubidium
parents: 6351
diff changeset
    23
protected:
961ab798c4b6 (svn r10744) -Codechange: make the pool a little more OO, so it can be easier in other places.
rubidium
parents: 6351
diff changeset
    24
	OldMemoryPoolBase(const char *name, uint max_blocks, uint block_size_bits, uint item_size,
961ab798c4b6 (svn r10744) -Codechange: make the pool a little more OO, so it can be easier in other places.
rubidium
parents: 6351
diff changeset
    25
				OldMemoryPoolNewBlock *new_block_proc, OldMemoryPoolCleanBlock *clean_block_proc) :
7385
69832b54e5af (svn r10754) -Fix: MorphOS does not like sizeof in the templated pool item class, so use the item size that is set in the pool.
rubidium
parents: 7383
diff changeset
    26
		name(name), max_blocks(max_blocks), block_size_bits(block_size_bits),
7375
961ab798c4b6 (svn r10744) -Codechange: make the pool a little more OO, so it can be easier in other places.
rubidium
parents: 6351
diff changeset
    27
		new_block_proc(new_block_proc), clean_block_proc(clean_block_proc), current_blocks(0),
7413
a590f7f0edb3 (svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium
parents: 7402
diff changeset
    28
		total_items(0), cleaning_pool(false), item_size(item_size), first_free_index(0), blocks(NULL) {}
7375
961ab798c4b6 (svn r10744) -Codechange: make the pool a little more OO, so it can be easier in other places.
rubidium
parents: 6351
diff changeset
    29
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5475
diff changeset
    30
	const char* name;     ///< Name of the pool (just for debugging)
1259
8d8515e3da29 (svn r1763) -Add: pool.c / pool.h: generalized routines for dynamic arrays (MemoryPools)
truelight
parents:
diff changeset
    31
7377
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
    32
	const uint max_blocks;      ///< The max amount of blocks this pool can have
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
    33
	const uint block_size_bits; ///< The size of each block in bits
1259
8d8515e3da29 (svn r1763) -Add: pool.c / pool.h: generalized routines for dynamic arrays (MemoryPools)
truelight
parents:
diff changeset
    34
3173
f56ca618721b (svn r3805) - [FS#62] Fix doxygen comments to refer to the correct parameter. (sulai)
peter1138
parents: 2436
diff changeset
    35
	/// Pointer to a function that is called after a new block is added
7383
864c7b8e1c52 (svn r10752) -Fix: apparantly const on function pointers is ignored.
rubidium
parents: 7381
diff changeset
    36
	OldMemoryPoolNewBlock *new_block_proc;
3585
43461f26b729 (svn r4471) - Pools: Add a facility for calling a custom function during pool block clean up.
peter1138
parents: 3173
diff changeset
    37
	/// Pointer to a function that is called to clean a block
7383
864c7b8e1c52 (svn r10752) -Fix: apparantly const on function pointers is ignored.
rubidium
parents: 7381
diff changeset
    38
	OldMemoryPoolCleanBlock *clean_block_proc;
1259
8d8515e3da29 (svn r1763) -Add: pool.c / pool.h: generalized routines for dynamic arrays (MemoryPools)
truelight
parents:
diff changeset
    39
3173
f56ca618721b (svn r3805) - [FS#62] Fix doxygen comments to refer to the correct parameter. (sulai)
peter1138
parents: 2436
diff changeset
    40
	uint current_blocks;        ///< How many blocks we have in our pool
f56ca618721b (svn r3805) - [FS#62] Fix doxygen comments to refer to the correct parameter. (sulai)
peter1138
parents: 2436
diff changeset
    41
	uint total_items;           ///< How many items we now have in this pool
f56ca618721b (svn r3805) - [FS#62] Fix doxygen comments to refer to the correct parameter. (sulai)
peter1138
parents: 2436
diff changeset
    42
7413
a590f7f0edb3 (svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium
parents: 7402
diff changeset
    43
	bool cleaning_pool;         ///< Are we currently cleaning the pool?
7375
961ab798c4b6 (svn r10744) -Codechange: make the pool a little more OO, so it can be easier in other places.
rubidium
parents: 6351
diff changeset
    44
public:
7385
69832b54e5af (svn r10754) -Fix: MorphOS does not like sizeof in the templated pool item class, so use the item size that is set in the pool.
rubidium
parents: 7383
diff changeset
    45
	const uint item_size;       ///< How many bytes one block is
7378
7e7a9122b7b1 (svn r10747) -Codechange: add a variable that points to some index in the pool that is not beyond the first free pool item. It does not necessarily point to the first free item, but it reduces allocation time as it does not have to start at the first item in the pool to find the first free item.
rubidium
parents: 7377
diff changeset
    46
	uint first_free_index;      ///< The index of the first free pool item in this pool
3173
f56ca618721b (svn r3805) - [FS#62] Fix doxygen comments to refer to the correct parameter. (sulai)
peter1138
parents: 2436
diff changeset
    47
	byte **blocks;              ///< An array of blocks (one block hold all the items)
7375
961ab798c4b6 (svn r10744) -Codechange: make the pool a little more OO, so it can be easier in other places.
rubidium
parents: 6351
diff changeset
    48
7377
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
    49
	/**
7974
dfe3185a62d2 (svn r11530) -Codechange: do not update Tpool->first_free_index for PoolItems allocated on stack
smatz
parents: 7496
diff changeset
    50
	 * Check if the index of pool item being deleted is lower than cached first_free_index
dfe3185a62d2 (svn r11530) -Codechange: do not update Tpool->first_free_index for PoolItems allocated on stack
smatz
parents: 7496
diff changeset
    51
	 * @param index index of pool item
dfe3185a62d2 (svn r11530) -Codechange: do not update Tpool->first_free_index for PoolItems allocated on stack
smatz
parents: 7496
diff changeset
    52
	 * @note usage of min() will result in better code on some architectures
dfe3185a62d2 (svn r11530) -Codechange: do not update Tpool->first_free_index for PoolItems allocated on stack
smatz
parents: 7496
diff changeset
    53
	 */
dfe3185a62d2 (svn r11530) -Codechange: do not update Tpool->first_free_index for PoolItems allocated on stack
smatz
parents: 7496
diff changeset
    54
	inline void UpdateFirstFreeIndex(uint index)
dfe3185a62d2 (svn r11530) -Codechange: do not update Tpool->first_free_index for PoolItems allocated on stack
smatz
parents: 7496
diff changeset
    55
	{
dfe3185a62d2 (svn r11530) -Codechange: do not update Tpool->first_free_index for PoolItems allocated on stack
smatz
parents: 7496
diff changeset
    56
		first_free_index = min(first_free_index, index);
dfe3185a62d2 (svn r11530) -Codechange: do not update Tpool->first_free_index for PoolItems allocated on stack
smatz
parents: 7496
diff changeset
    57
	}
dfe3185a62d2 (svn r11530) -Codechange: do not update Tpool->first_free_index for PoolItems allocated on stack
smatz
parents: 7496
diff changeset
    58
dfe3185a62d2 (svn r11530) -Codechange: do not update Tpool->first_free_index for PoolItems allocated on stack
smatz
parents: 7496
diff changeset
    59
	/**
7377
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
    60
	 * Get the size of this pool, i.e. the total number of items you
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
    61
	 * can put into it at the current moment; the pool might still
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
    62
	 * be able to increase the size of the pool.
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
    63
	 * @return the size of the pool
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
    64
	 */
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
    65
	inline uint GetSize() const
7375
961ab798c4b6 (svn r10744) -Codechange: make the pool a little more OO, so it can be easier in other places.
rubidium
parents: 6351
diff changeset
    66
	{
961ab798c4b6 (svn r10744) -Codechange: make the pool a little more OO, so it can be easier in other places.
rubidium
parents: 6351
diff changeset
    67
		return this->total_items;
961ab798c4b6 (svn r10744) -Codechange: make the pool a little more OO, so it can be easier in other places.
rubidium
parents: 6351
diff changeset
    68
	}
961ab798c4b6 (svn r10744) -Codechange: make the pool a little more OO, so it can be easier in other places.
rubidium
parents: 6351
diff changeset
    69
7377
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
    70
	/**
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
    71
	 * Can this pool allocate more blocks, i.e. is the maximum amount
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
    72
	 * of allocated blocks not yet reached?
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
    73
	 * @return the if and only if the amount of allocable blocks is
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
    74
	 *         less than the amount of allocated blocks.
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
    75
	 */
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
    76
	inline bool CanAllocateMoreBlocks() const
7375
961ab798c4b6 (svn r10744) -Codechange: make the pool a little more OO, so it can be easier in other places.
rubidium
parents: 6351
diff changeset
    77
	{
961ab798c4b6 (svn r10744) -Codechange: make the pool a little more OO, so it can be easier in other places.
rubidium
parents: 6351
diff changeset
    78
		return this->current_blocks < this->max_blocks;
961ab798c4b6 (svn r10744) -Codechange: make the pool a little more OO, so it can be easier in other places.
rubidium
parents: 6351
diff changeset
    79
	}
961ab798c4b6 (svn r10744) -Codechange: make the pool a little more OO, so it can be easier in other places.
rubidium
parents: 6351
diff changeset
    80
7377
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
    81
	/**
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
    82
	 * Get the maximum number of allocable blocks.
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
    83
	 * @return the numebr of blocks
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
    84
	 */
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
    85
	inline uint GetBlockCount() const
7375
961ab798c4b6 (svn r10744) -Codechange: make the pool a little more OO, so it can be easier in other places.
rubidium
parents: 6351
diff changeset
    86
	{
961ab798c4b6 (svn r10744) -Codechange: make the pool a little more OO, so it can be easier in other places.
rubidium
parents: 6351
diff changeset
    87
		return this->current_blocks;
961ab798c4b6 (svn r10744) -Codechange: make the pool a little more OO, so it can be easier in other places.
rubidium
parents: 6351
diff changeset
    88
	}
7377
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
    89
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
    90
	/**
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
    91
	 * Get the name of this pool.
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
    92
	 * @return the name
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
    93
	 */
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
    94
	inline const char *GetName() const
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
    95
	{
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
    96
		return this->name;
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
    97
	}
7413
a590f7f0edb3 (svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium
parents: 7402
diff changeset
    98
a590f7f0edb3 (svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium
parents: 7402
diff changeset
    99
	/**
a590f7f0edb3 (svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium
parents: 7402
diff changeset
   100
	 * Is the pool in the cleaning phase?
a590f7f0edb3 (svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium
parents: 7402
diff changeset
   101
	 * @return true if it is
a590f7f0edb3 (svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium
parents: 7402
diff changeset
   102
	 */
a590f7f0edb3 (svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium
parents: 7402
diff changeset
   103
	inline bool CleaningPool() const
a590f7f0edb3 (svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium
parents: 7402
diff changeset
   104
	{
a590f7f0edb3 (svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium
parents: 7402
diff changeset
   105
		return this->cleaning_pool;
a590f7f0edb3 (svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium
parents: 7402
diff changeset
   106
	}
7375
961ab798c4b6 (svn r10744) -Codechange: make the pool a little more OO, so it can be easier in other places.
rubidium
parents: 6351
diff changeset
   107
};
961ab798c4b6 (svn r10744) -Codechange: make the pool a little more OO, so it can be easier in other places.
rubidium
parents: 6351
diff changeset
   108
961ab798c4b6 (svn r10744) -Codechange: make the pool a little more OO, so it can be easier in other places.
rubidium
parents: 6351
diff changeset
   109
template <typename T>
961ab798c4b6 (svn r10744) -Codechange: make the pool a little more OO, so it can be easier in other places.
rubidium
parents: 6351
diff changeset
   110
struct OldMemoryPool : public OldMemoryPoolBase {
961ab798c4b6 (svn r10744) -Codechange: make the pool a little more OO, so it can be easier in other places.
rubidium
parents: 6351
diff changeset
   111
	OldMemoryPool(const char *name, uint max_blocks, uint block_size_bits, uint item_size,
961ab798c4b6 (svn r10744) -Codechange: make the pool a little more OO, so it can be easier in other places.
rubidium
parents: 6351
diff changeset
   112
				OldMemoryPoolNewBlock *new_block_proc, OldMemoryPoolCleanBlock *clean_block_proc) :
961ab798c4b6 (svn r10744) -Codechange: make the pool a little more OO, so it can be easier in other places.
rubidium
parents: 6351
diff changeset
   113
		OldMemoryPoolBase(name, max_blocks, block_size_bits, item_size, new_block_proc, clean_block_proc) {}
961ab798c4b6 (svn r10744) -Codechange: make the pool a little more OO, so it can be easier in other places.
rubidium
parents: 6351
diff changeset
   114
7377
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   115
	/**
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   116
	 * Get the pool entry at the given index.
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   117
	 * @param index the index into the pool
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   118
	 * @pre index < this->GetSize()
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   119
	 * @return the pool entry.
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   120
	 */
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   121
	inline T *Get(uint index) const
7375
961ab798c4b6 (svn r10744) -Codechange: make the pool a little more OO, so it can be easier in other places.
rubidium
parents: 6351
diff changeset
   122
	{
961ab798c4b6 (svn r10744) -Codechange: make the pool a little more OO, so it can be easier in other places.
rubidium
parents: 6351
diff changeset
   123
		assert(index < this->GetSize());
961ab798c4b6 (svn r10744) -Codechange: make the pool a little more OO, so it can be easier in other places.
rubidium
parents: 6351
diff changeset
   124
		return (T*)(this->blocks[index >> this->block_size_bits] +
7385
69832b54e5af (svn r10754) -Fix: MorphOS does not like sizeof in the templated pool item class, so use the item size that is set in the pool.
rubidium
parents: 7383
diff changeset
   125
				(index & ((1 << this->block_size_bits) - 1)) * this->item_size);
7375
961ab798c4b6 (svn r10744) -Codechange: make the pool a little more OO, so it can be easier in other places.
rubidium
parents: 6351
diff changeset
   126
	}
1259
8d8515e3da29 (svn r1763) -Add: pool.c / pool.h: generalized routines for dynamic arrays (MemoryPools)
truelight
parents:
diff changeset
   127
};
8d8515e3da29 (svn r1763) -Add: pool.c / pool.h: generalized routines for dynamic arrays (MemoryPools)
truelight
parents:
diff changeset
   128
8d8515e3da29 (svn r1763) -Add: pool.c / pool.h: generalized routines for dynamic arrays (MemoryPools)
truelight
parents:
diff changeset
   129
/**
7376
066596e64cd5 (svn r10745) -Codechange: generalize the pool cleanup/initialize functions for stations (in such a manner that they can be used for other pools too).
rubidium
parents: 7375
diff changeset
   130
 * Generic function to initialize a new block in a pool.
066596e64cd5 (svn r10745) -Codechange: generalize the pool cleanup/initialize functions for stations (in such a manner that they can be used for other pools too).
rubidium
parents: 7375
diff changeset
   131
 * @param start_item the first item that needs to be initialized
066596e64cd5 (svn r10745) -Codechange: generalize the pool cleanup/initialize functions for stations (in such a manner that they can be used for other pools too).
rubidium
parents: 7375
diff changeset
   132
 */
066596e64cd5 (svn r10745) -Codechange: generalize the pool cleanup/initialize functions for stations (in such a manner that they can be used for other pools too).
rubidium
parents: 7375
diff changeset
   133
template <typename T, OldMemoryPool<T> *Tpool>
066596e64cd5 (svn r10745) -Codechange: generalize the pool cleanup/initialize functions for stations (in such a manner that they can be used for other pools too).
rubidium
parents: 7375
diff changeset
   134
static void PoolNewBlock(uint start_item)
066596e64cd5 (svn r10745) -Codechange: generalize the pool cleanup/initialize functions for stations (in such a manner that they can be used for other pools too).
rubidium
parents: 7375
diff changeset
   135
{
066596e64cd5 (svn r10745) -Codechange: generalize the pool cleanup/initialize functions for stations (in such a manner that they can be used for other pools too).
rubidium
parents: 7375
diff changeset
   136
	for (T *t = Tpool->Get(start_item); t != NULL; t = (t->index + 1U < Tpool->GetSize()) ? Tpool->Get(t->index + 1U) : NULL) {
7377
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   137
		t = new (t) T();
7376
066596e64cd5 (svn r10745) -Codechange: generalize the pool cleanup/initialize functions for stations (in such a manner that they can be used for other pools too).
rubidium
parents: 7375
diff changeset
   138
		t->index = start_item++;
066596e64cd5 (svn r10745) -Codechange: generalize the pool cleanup/initialize functions for stations (in such a manner that they can be used for other pools too).
rubidium
parents: 7375
diff changeset
   139
	}
066596e64cd5 (svn r10745) -Codechange: generalize the pool cleanup/initialize functions for stations (in such a manner that they can be used for other pools too).
rubidium
parents: 7375
diff changeset
   140
}
066596e64cd5 (svn r10745) -Codechange: generalize the pool cleanup/initialize functions for stations (in such a manner that they can be used for other pools too).
rubidium
parents: 7375
diff changeset
   141
066596e64cd5 (svn r10745) -Codechange: generalize the pool cleanup/initialize functions for stations (in such a manner that they can be used for other pools too).
rubidium
parents: 7375
diff changeset
   142
/**
066596e64cd5 (svn r10745) -Codechange: generalize the pool cleanup/initialize functions for stations (in such a manner that they can be used for other pools too).
rubidium
parents: 7375
diff changeset
   143
 * Generic function to free a new block in a pool.
066596e64cd5 (svn r10745) -Codechange: generalize the pool cleanup/initialize functions for stations (in such a manner that they can be used for other pools too).
rubidium
parents: 7375
diff changeset
   144
 * @param start_item the first item that needs to be cleaned
066596e64cd5 (svn r10745) -Codechange: generalize the pool cleanup/initialize functions for stations (in such a manner that they can be used for other pools too).
rubidium
parents: 7375
diff changeset
   145
 * @param end_item   the last item that needs to be cleaned
066596e64cd5 (svn r10745) -Codechange: generalize the pool cleanup/initialize functions for stations (in such a manner that they can be used for other pools too).
rubidium
parents: 7375
diff changeset
   146
 */
066596e64cd5 (svn r10745) -Codechange: generalize the pool cleanup/initialize functions for stations (in such a manner that they can be used for other pools too).
rubidium
parents: 7375
diff changeset
   147
template <typename T, OldMemoryPool<T> *Tpool>
066596e64cd5 (svn r10745) -Codechange: generalize the pool cleanup/initialize functions for stations (in such a manner that they can be used for other pools too).
rubidium
parents: 7375
diff changeset
   148
static void PoolCleanBlock(uint start_item, uint end_item)
066596e64cd5 (svn r10745) -Codechange: generalize the pool cleanup/initialize functions for stations (in such a manner that they can be used for other pools too).
rubidium
parents: 7375
diff changeset
   149
{
066596e64cd5 (svn r10745) -Codechange: generalize the pool cleanup/initialize functions for stations (in such a manner that they can be used for other pools too).
rubidium
parents: 7375
diff changeset
   150
	for (uint i = start_item; i <= end_item; i++) {
066596e64cd5 (svn r10745) -Codechange: generalize the pool cleanup/initialize functions for stations (in such a manner that they can be used for other pools too).
rubidium
parents: 7375
diff changeset
   151
		T *t = Tpool->Get(i);
7413
a590f7f0edb3 (svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium
parents: 7402
diff changeset
   152
		delete t;
7376
066596e64cd5 (svn r10745) -Codechange: generalize the pool cleanup/initialize functions for stations (in such a manner that they can be used for other pools too).
rubidium
parents: 7375
diff changeset
   153
	}
066596e64cd5 (svn r10745) -Codechange: generalize the pool cleanup/initialize functions for stations (in such a manner that they can be used for other pools too).
rubidium
parents: 7375
diff changeset
   154
}
066596e64cd5 (svn r10745) -Codechange: generalize the pool cleanup/initialize functions for stations (in such a manner that they can be used for other pools too).
rubidium
parents: 7375
diff changeset
   155
066596e64cd5 (svn r10745) -Codechange: generalize the pool cleanup/initialize functions for stations (in such a manner that they can be used for other pools too).
rubidium
parents: 7375
diff changeset
   156
7377
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   157
/**
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   158
 * Generalization for all pool items that are saved in the savegame.
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   159
 * It specifies all the mechanics to access the pool easily.
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   160
 */
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   161
template <typename T, typename Tid, OldMemoryPool<T> *Tpool>
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   162
struct PoolItem {
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   163
	/**
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   164
	 * The pool-wide index of this object.
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   165
	 */
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   166
	Tid index;
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   167
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   168
	/**
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   169
	 * We like to have the correct class destructed.
7974
dfe3185a62d2 (svn r11530) -Codechange: do not update Tpool->first_free_index for PoolItems allocated on stack
smatz
parents: 7496
diff changeset
   170
	 * @warning It is called even for object allocated on stack,
dfe3185a62d2 (svn r11530) -Codechange: do not update Tpool->first_free_index for PoolItems allocated on stack
smatz
parents: 7496
diff changeset
   171
	 *          so it is not present in the TPool!
dfe3185a62d2 (svn r11530) -Codechange: do not update Tpool->first_free_index for PoolItems allocated on stack
smatz
parents: 7496
diff changeset
   172
	 *          Then, index is undefined, not associated with TPool in any way.
dfe3185a62d2 (svn r11530) -Codechange: do not update Tpool->first_free_index for PoolItems allocated on stack
smatz
parents: 7496
diff changeset
   173
	 * @note    The idea is to free up allocated memory etc.
7377
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   174
	 */
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   175
	virtual ~PoolItem()
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   176
	{
7974
dfe3185a62d2 (svn r11530) -Codechange: do not update Tpool->first_free_index for PoolItems allocated on stack
smatz
parents: 7496
diff changeset
   177
dfe3185a62d2 (svn r11530) -Codechange: do not update Tpool->first_free_index for PoolItems allocated on stack
smatz
parents: 7496
diff changeset
   178
	}
dfe3185a62d2 (svn r11530) -Codechange: do not update Tpool->first_free_index for PoolItems allocated on stack
smatz
parents: 7496
diff changeset
   179
dfe3185a62d2 (svn r11530) -Codechange: do not update Tpool->first_free_index for PoolItems allocated on stack
smatz
parents: 7496
diff changeset
   180
	/**
dfe3185a62d2 (svn r11530) -Codechange: do not update Tpool->first_free_index for PoolItems allocated on stack
smatz
parents: 7496
diff changeset
   181
	 * Constructor of given class.
dfe3185a62d2 (svn r11530) -Codechange: do not update Tpool->first_free_index for PoolItems allocated on stack
smatz
parents: 7496
diff changeset
   182
	 * @warning It is called even for object allocated on stack,
dfe3185a62d2 (svn r11530) -Codechange: do not update Tpool->first_free_index for PoolItems allocated on stack
smatz
parents: 7496
diff changeset
   183
	 *          so it may not be present in TPool!
dfe3185a62d2 (svn r11530) -Codechange: do not update Tpool->first_free_index for PoolItems allocated on stack
smatz
parents: 7496
diff changeset
   184
	 *          Then, index is undefined, not associated with TPool in any way.
dfe3185a62d2 (svn r11530) -Codechange: do not update Tpool->first_free_index for PoolItems allocated on stack
smatz
parents: 7496
diff changeset
   185
	 * @note    The idea is to initialize variables (except index)
dfe3185a62d2 (svn r11530) -Codechange: do not update Tpool->first_free_index for PoolItems allocated on stack
smatz
parents: 7496
diff changeset
   186
	 */
dfe3185a62d2 (svn r11530) -Codechange: do not update Tpool->first_free_index for PoolItems allocated on stack
smatz
parents: 7496
diff changeset
   187
	PoolItem()
dfe3185a62d2 (svn r11530) -Codechange: do not update Tpool->first_free_index for PoolItems allocated on stack
smatz
parents: 7496
diff changeset
   188
	{
dfe3185a62d2 (svn r11530) -Codechange: do not update Tpool->first_free_index for PoolItems allocated on stack
smatz
parents: 7496
diff changeset
   189
7377
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   190
	}
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   191
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   192
	/**
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   193
	 * An overriden version of new that allocates memory on the pool.
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   194
	 * @param size the size of the variable (unused)
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   195
	 * @return the memory that is 'allocated'
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   196
	 */
7381
d7991ec3f19d (svn r10750) -Codechange: make the waypoint struct use the new poolitem class as super class.
rubidium
parents: 7378
diff changeset
   197
	void *operator new(size_t size)
7377
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   198
	{
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   199
		return AllocateRaw();
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   200
	}
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   201
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   202
	/**
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   203
	 * 'Free' the memory allocated by the overriden new.
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   204
	 * @param p the memory to 'free'
7974
dfe3185a62d2 (svn r11530) -Codechange: do not update Tpool->first_free_index for PoolItems allocated on stack
smatz
parents: 7496
diff changeset
   205
	 * @note we only update Tpool->first_free_index
7377
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   206
	 */
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   207
	void operator delete(void *p)
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   208
	{
7974
dfe3185a62d2 (svn r11530) -Codechange: do not update Tpool->first_free_index for PoolItems allocated on stack
smatz
parents: 7496
diff changeset
   209
		Tpool->UpdateFirstFreeIndex(((T*)p)->index);
7377
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   210
	}
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   211
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   212
	/**
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   213
	 * An overriden version of new, so you can directly allocate a new object with
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   214
	 * the correct index when one is loading the savegame.
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   215
	 * @param size  the size of the variable (unused)
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   216
	 * @param index the index of the object
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   217
	 * @return the memory that is 'allocated'
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   218
	 */
7381
d7991ec3f19d (svn r10750) -Codechange: make the waypoint struct use the new poolitem class as super class.
rubidium
parents: 7378
diff changeset
   219
	void *operator new(size_t size, int index)
7377
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   220
	{
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   221
		if (!Tpool->AddBlockIfNeeded(index)) error("%s: failed loading savegame: too many %s", Tpool->GetName(), Tpool->GetName());
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   222
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   223
		return Tpool->Get(index);
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   224
	}
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   225
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   226
	/**
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   227
	 * 'Free' the memory allocated by the overriden new.
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   228
	 * @param p     the memory to 'free'
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   229
	 * @param index the original parameter given to create the memory
7974
dfe3185a62d2 (svn r11530) -Codechange: do not update Tpool->first_free_index for PoolItems allocated on stack
smatz
parents: 7496
diff changeset
   230
	 * @note we only update Tpool->first_free_index
7377
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   231
	 */
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   232
	void operator delete(void *p, int index)
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   233
	{
7974
dfe3185a62d2 (svn r11530) -Codechange: do not update Tpool->first_free_index for PoolItems allocated on stack
smatz
parents: 7496
diff changeset
   234
		Tpool->UpdateFirstFreeIndex(index);
7377
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   235
	}
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   236
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   237
	/**
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   238
	 * An overriden version of new, so you can use the vehicle instance
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   239
	 * instead of a newly allocated piece of memory.
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   240
	 * @param size the size of the variable (unused)
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   241
	 * @param pn   the already existing object to use as 'storage' backend
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   242
	 * @return the memory that is 'allocated'
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   243
	 */
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   244
	void *operator new(size_t size, T *pn)
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   245
	{
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   246
		return pn;
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   247
	}
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   248
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   249
	/**
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   250
	 * 'Free' the memory allocated by the overriden new.
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   251
	 * @param p  the memory to 'free'
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   252
	 * @param pn the pointer that was given to 'new' on creation.
7974
dfe3185a62d2 (svn r11530) -Codechange: do not update Tpool->first_free_index for PoolItems allocated on stack
smatz
parents: 7496
diff changeset
   253
	 * @note we only update Tpool->first_free_index
7377
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   254
	 */
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   255
	void operator delete(void *p, T *pn)
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   256
	{
7974
dfe3185a62d2 (svn r11530) -Codechange: do not update Tpool->first_free_index for PoolItems allocated on stack
smatz
parents: 7496
diff changeset
   257
		Tpool->UpdateFirstFreeIndex(pn->index);
7377
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   258
	}
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   259
7426
e8dd555767bd (svn r10827) -Fix [FS#1112]: out of bounds access in corner case of list allocations of vehicles.
rubidium
parents: 7413
diff changeset
   260
private:
7397
d39548123fbd (svn r10768) -Codechange: allow to specify from which index to search for a free pool item.
rubidium
parents: 7385
diff changeset
   261
	/**
d39548123fbd (svn r10768) -Codechange: allow to specify from which index to search for a free pool item.
rubidium
parents: 7385
diff changeset
   262
	 * Allocate a pool item; possibly allocate a new block in the pool.
d39548123fbd (svn r10768) -Codechange: allow to specify from which index to search for a free pool item.
rubidium
parents: 7385
diff changeset
   263
	 * @param first the first pool item to start searching
7426
e8dd555767bd (svn r10827) -Fix [FS#1112]: out of bounds access in corner case of list allocations of vehicles.
rubidium
parents: 7413
diff changeset
   264
	 * @pre first <= Tpool->GetSize()
7397
d39548123fbd (svn r10768) -Codechange: allow to specify from which index to search for a free pool item.
rubidium
parents: 7385
diff changeset
   265
	 * @return the allocated pool item (or NULL when the pool is full).
d39548123fbd (svn r10768) -Codechange: allow to specify from which index to search for a free pool item.
rubidium
parents: 7385
diff changeset
   266
	 */
7426
e8dd555767bd (svn r10827) -Fix [FS#1112]: out of bounds access in corner case of list allocations of vehicles.
rubidium
parents: 7413
diff changeset
   267
	static inline T *AllocateSafeRaw(uint &first)
7397
d39548123fbd (svn r10768) -Codechange: allow to specify from which index to search for a free pool item.
rubidium
parents: 7385
diff changeset
   268
	{
7402
8c221b48168a (svn r10774) -Fix (r10768): obiwan pleased us with a visit.
rubidium
parents: 7401
diff changeset
   269
		uint last_minus_one = Tpool->GetSize() - 1;
7397
d39548123fbd (svn r10768) -Codechange: allow to specify from which index to search for a free pool item.
rubidium
parents: 7385
diff changeset
   270
d39548123fbd (svn r10768) -Codechange: allow to specify from which index to search for a free pool item.
rubidium
parents: 7385
diff changeset
   271
		for (T *t = Tpool->Get(first); t != NULL; t = (t->index < last_minus_one) ? Tpool->Get(t->index + 1U) : NULL) {
7377
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   272
			if (!t->IsValid()) {
7397
d39548123fbd (svn r10768) -Codechange: allow to specify from which index to search for a free pool item.
rubidium
parents: 7385
diff changeset
   273
				first = t->index;
7377
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   274
				Tid index = t->index;
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   275
7385
69832b54e5af (svn r10754) -Fix: MorphOS does not like sizeof in the templated pool item class, so use the item size that is set in the pool.
rubidium
parents: 7383
diff changeset
   276
				memset(t, 0, Tpool->item_size);
7377
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   277
				t->index = index;
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   278
				return t;
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   279
			}
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   280
		}
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   281
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   282
		/* Check if we can add a block to the pool */
7397
d39548123fbd (svn r10768) -Codechange: allow to specify from which index to search for a free pool item.
rubidium
parents: 7385
diff changeset
   283
		if (Tpool->AddBlockToPool()) return AllocateRaw(first);
7377
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   284
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   285
		return NULL;
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   286
	}
7413
a590f7f0edb3 (svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium
parents: 7402
diff changeset
   287
7426
e8dd555767bd (svn r10827) -Fix [FS#1112]: out of bounds access in corner case of list allocations of vehicles.
rubidium
parents: 7413
diff changeset
   288
protected:
e8dd555767bd (svn r10827) -Fix [FS#1112]: out of bounds access in corner case of list allocations of vehicles.
rubidium
parents: 7413
diff changeset
   289
	/**
e8dd555767bd (svn r10827) -Fix [FS#1112]: out of bounds access in corner case of list allocations of vehicles.
rubidium
parents: 7413
diff changeset
   290
	 * Allocate a pool item; possibly allocate a new block in the pool.
e8dd555767bd (svn r10827) -Fix [FS#1112]: out of bounds access in corner case of list allocations of vehicles.
rubidium
parents: 7413
diff changeset
   291
	 * @return the allocated pool item (or NULL when the pool is full).
e8dd555767bd (svn r10827) -Fix [FS#1112]: out of bounds access in corner case of list allocations of vehicles.
rubidium
parents: 7413
diff changeset
   292
	 */
e8dd555767bd (svn r10827) -Fix [FS#1112]: out of bounds access in corner case of list allocations of vehicles.
rubidium
parents: 7413
diff changeset
   293
	static inline T *AllocateRaw()
e8dd555767bd (svn r10827) -Fix [FS#1112]: out of bounds access in corner case of list allocations of vehicles.
rubidium
parents: 7413
diff changeset
   294
	{
e8dd555767bd (svn r10827) -Fix [FS#1112]: out of bounds access in corner case of list allocations of vehicles.
rubidium
parents: 7413
diff changeset
   295
		return AllocateSafeRaw(Tpool->first_free_index);
e8dd555767bd (svn r10827) -Fix [FS#1112]: out of bounds access in corner case of list allocations of vehicles.
rubidium
parents: 7413
diff changeset
   296
	}
e8dd555767bd (svn r10827) -Fix [FS#1112]: out of bounds access in corner case of list allocations of vehicles.
rubidium
parents: 7413
diff changeset
   297
e8dd555767bd (svn r10827) -Fix [FS#1112]: out of bounds access in corner case of list allocations of vehicles.
rubidium
parents: 7413
diff changeset
   298
	/**
e8dd555767bd (svn r10827) -Fix [FS#1112]: out of bounds access in corner case of list allocations of vehicles.
rubidium
parents: 7413
diff changeset
   299
	 * Allocate a pool item; possibly allocate a new block in the pool.
e8dd555767bd (svn r10827) -Fix [FS#1112]: out of bounds access in corner case of list allocations of vehicles.
rubidium
parents: 7413
diff changeset
   300
	 * @param first the first pool item to start searching
e8dd555767bd (svn r10827) -Fix [FS#1112]: out of bounds access in corner case of list allocations of vehicles.
rubidium
parents: 7413
diff changeset
   301
	 * @return the allocated pool item (or NULL when the pool is full).
e8dd555767bd (svn r10827) -Fix [FS#1112]: out of bounds access in corner case of list allocations of vehicles.
rubidium
parents: 7413
diff changeset
   302
	 */
e8dd555767bd (svn r10827) -Fix [FS#1112]: out of bounds access in corner case of list allocations of vehicles.
rubidium
parents: 7413
diff changeset
   303
	static inline T *AllocateRaw(uint &first)
e8dd555767bd (svn r10827) -Fix [FS#1112]: out of bounds access in corner case of list allocations of vehicles.
rubidium
parents: 7413
diff changeset
   304
	{
e8dd555767bd (svn r10827) -Fix [FS#1112]: out of bounds access in corner case of list allocations of vehicles.
rubidium
parents: 7413
diff changeset
   305
		if (first >= Tpool->GetSize() && !Tpool->AddBlockToPool()) return NULL;
e8dd555767bd (svn r10827) -Fix [FS#1112]: out of bounds access in corner case of list allocations of vehicles.
rubidium
parents: 7413
diff changeset
   306
e8dd555767bd (svn r10827) -Fix [FS#1112]: out of bounds access in corner case of list allocations of vehicles.
rubidium
parents: 7413
diff changeset
   307
		return AllocateSafeRaw(first);
e8dd555767bd (svn r10827) -Fix [FS#1112]: out of bounds access in corner case of list allocations of vehicles.
rubidium
parents: 7413
diff changeset
   308
	}
e8dd555767bd (svn r10827) -Fix [FS#1112]: out of bounds access in corner case of list allocations of vehicles.
rubidium
parents: 7413
diff changeset
   309
7413
a590f7f0edb3 (svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium
parents: 7402
diff changeset
   310
	/**
a590f7f0edb3 (svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium
parents: 7402
diff changeset
   311
	 * Are we cleaning this pool?
a590f7f0edb3 (svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium
parents: 7402
diff changeset
   312
	 * @return true if we are
a590f7f0edb3 (svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium
parents: 7402
diff changeset
   313
	 */
a590f7f0edb3 (svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium
parents: 7402
diff changeset
   314
	static inline bool CleaningPool()
a590f7f0edb3 (svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium
parents: 7402
diff changeset
   315
	{
a590f7f0edb3 (svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium
parents: 7402
diff changeset
   316
		return Tpool->CleaningPool();
a590f7f0edb3 (svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium
parents: 7402
diff changeset
   317
	}
7377
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   318
};
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   319
7376
066596e64cd5 (svn r10745) -Codechange: generalize the pool cleanup/initialize functions for stations (in such a manner that they can be used for other pools too).
rubidium
parents: 7375
diff changeset
   320
5216
8bd14ee39af2 (svn r7331) - Codechange: Rename all memory pool macro's and types to "old pool", so the new pool implementation can be committed alongside it.
matthijs
parents: 4986
diff changeset
   321
#define OLD_POOL_ENUM(name, type, block_size_bits, max_blocks) \
4970
eb2c0fde4b02 (svn r6973) Add macros to easily create a pool with less code duplication and more opportunities for constant expression evaluation
tron
parents: 3585
diff changeset
   322
	enum { \
eb2c0fde4b02 (svn r6973) Add macros to easily create a pool with less code duplication and more opportunities for constant expression evaluation
tron
parents: 3585
diff changeset
   323
		name##_POOL_BLOCK_SIZE_BITS = block_size_bits, \
eb2c0fde4b02 (svn r6973) Add macros to easily create a pool with less code duplication and more opportunities for constant expression evaluation
tron
parents: 3585
diff changeset
   324
		name##_POOL_MAX_BLOCKS      = max_blocks \
eb2c0fde4b02 (svn r6973) Add macros to easily create a pool with less code duplication and more opportunities for constant expression evaluation
tron
parents: 3585
diff changeset
   325
	};
eb2c0fde4b02 (svn r6973) Add macros to easily create a pool with less code duplication and more opportunities for constant expression evaluation
tron
parents: 3585
diff changeset
   326
eb2c0fde4b02 (svn r6973) Add macros to easily create a pool with less code duplication and more opportunities for constant expression evaluation
tron
parents: 3585
diff changeset
   327
5216
8bd14ee39af2 (svn r7331) - Codechange: Rename all memory pool macro's and types to "old pool", so the new pool implementation can be committed alongside it.
matthijs
parents: 4986
diff changeset
   328
#define OLD_POOL_ACCESSORS(name, type) \
7375
961ab798c4b6 (svn r10744) -Codechange: make the pool a little more OO, so it can be easier in other places.
rubidium
parents: 6351
diff changeset
   329
	static inline type* Get##name(uint index) { return _##name##_pool.Get(index);  } \
961ab798c4b6 (svn r10744) -Codechange: make the pool a little more OO, so it can be easier in other places.
rubidium
parents: 6351
diff changeset
   330
	static inline uint Get##name##PoolSize()  { return _##name##_pool.GetSize(); }
4970
eb2c0fde4b02 (svn r6973) Add macros to easily create a pool with less code duplication and more opportunities for constant expression evaluation
tron
parents: 3585
diff changeset
   331
eb2c0fde4b02 (svn r6973) Add macros to easily create a pool with less code duplication and more opportunities for constant expression evaluation
tron
parents: 3585
diff changeset
   332
5216
8bd14ee39af2 (svn r7331) - Codechange: Rename all memory pool macro's and types to "old pool", so the new pool implementation can be committed alongside it.
matthijs
parents: 4986
diff changeset
   333
#define DECLARE_OLD_POOL(name, type, block_size_bits, max_blocks) \
8bd14ee39af2 (svn r7331) - Codechange: Rename all memory pool macro's and types to "old pool", so the new pool implementation can be committed alongside it.
matthijs
parents: 4986
diff changeset
   334
	OLD_POOL_ENUM(name, type, block_size_bits, max_blocks) \
7375
961ab798c4b6 (svn r10744) -Codechange: make the pool a little more OO, so it can be easier in other places.
rubidium
parents: 6351
diff changeset
   335
	extern OldMemoryPool<type> _##name##_pool; \
5216
8bd14ee39af2 (svn r7331) - Codechange: Rename all memory pool macro's and types to "old pool", so the new pool implementation can be committed alongside it.
matthijs
parents: 4986
diff changeset
   336
	OLD_POOL_ACCESSORS(name, type)
4970
eb2c0fde4b02 (svn r6973) Add macros to easily create a pool with less code duplication and more opportunities for constant expression evaluation
tron
parents: 3585
diff changeset
   337
eb2c0fde4b02 (svn r6973) Add macros to easily create a pool with less code duplication and more opportunities for constant expression evaluation
tron
parents: 3585
diff changeset
   338
5216
8bd14ee39af2 (svn r7331) - Codechange: Rename all memory pool macro's and types to "old pool", so the new pool implementation can be committed alongside it.
matthijs
parents: 4986
diff changeset
   339
#define DEFINE_OLD_POOL(name, type, new_block_proc, clean_block_proc) \
7375
961ab798c4b6 (svn r10744) -Codechange: make the pool a little more OO, so it can be easier in other places.
rubidium
parents: 6351
diff changeset
   340
	OldMemoryPool<type> _##name##_pool( \
4970
eb2c0fde4b02 (svn r6973) Add macros to easily create a pool with less code duplication and more opportunities for constant expression evaluation
tron
parents: 3585
diff changeset
   341
		#name, name##_POOL_MAX_BLOCKS, name##_POOL_BLOCK_SIZE_BITS, sizeof(type), \
7375
961ab798c4b6 (svn r10744) -Codechange: make the pool a little more OO, so it can be easier in other places.
rubidium
parents: 6351
diff changeset
   342
		new_block_proc, clean_block_proc);
4970
eb2c0fde4b02 (svn r6973) Add macros to easily create a pool with less code duplication and more opportunities for constant expression evaluation
tron
parents: 3585
diff changeset
   343
7376
066596e64cd5 (svn r10745) -Codechange: generalize the pool cleanup/initialize functions for stations (in such a manner that they can be used for other pools too).
rubidium
parents: 7375
diff changeset
   344
#define DEFINE_OLD_POOL_GENERIC(name, type) \
066596e64cd5 (svn r10745) -Codechange: generalize the pool cleanup/initialize functions for stations (in such a manner that they can be used for other pools too).
rubidium
parents: 7375
diff changeset
   345
	OldMemoryPool<type> _##name##_pool( \
066596e64cd5 (svn r10745) -Codechange: generalize the pool cleanup/initialize functions for stations (in such a manner that they can be used for other pools too).
rubidium
parents: 7375
diff changeset
   346
		#name, name##_POOL_MAX_BLOCKS, name##_POOL_BLOCK_SIZE_BITS, sizeof(type), \
066596e64cd5 (svn r10745) -Codechange: generalize the pool cleanup/initialize functions for stations (in such a manner that they can be used for other pools too).
rubidium
parents: 7375
diff changeset
   347
		PoolNewBlock<type, &_##name##_pool>, PoolCleanBlock<type, &_##name##_pool>);
066596e64cd5 (svn r10745) -Codechange: generalize the pool cleanup/initialize functions for stations (in such a manner that they can be used for other pools too).
rubidium
parents: 7375
diff changeset
   348
4970
eb2c0fde4b02 (svn r6973) Add macros to easily create a pool with less code duplication and more opportunities for constant expression evaluation
tron
parents: 3585
diff changeset
   349
5216
8bd14ee39af2 (svn r7331) - Codechange: Rename all memory pool macro's and types to "old pool", so the new pool implementation can be committed alongside it.
matthijs
parents: 4986
diff changeset
   350
#define STATIC_OLD_POOL(name, type, block_size_bits, max_blocks, new_block_proc, clean_block_proc) \
8bd14ee39af2 (svn r7331) - Codechange: Rename all memory pool macro's and types to "old pool", so the new pool implementation can be committed alongside it.
matthijs
parents: 4986
diff changeset
   351
	OLD_POOL_ENUM(name, type, block_size_bits, max_blocks) \
8bd14ee39af2 (svn r7331) - Codechange: Rename all memory pool macro's and types to "old pool", so the new pool implementation can be committed alongside it.
matthijs
parents: 4986
diff changeset
   352
	static DEFINE_OLD_POOL(name, type, new_block_proc, clean_block_proc) \
8bd14ee39af2 (svn r7331) - Codechange: Rename all memory pool macro's and types to "old pool", so the new pool implementation can be committed alongside it.
matthijs
parents: 4986
diff changeset
   353
	OLD_POOL_ACCESSORS(name, type)
4970
eb2c0fde4b02 (svn r6973) Add macros to easily create a pool with less code duplication and more opportunities for constant expression evaluation
tron
parents: 3585
diff changeset
   354
5224
df36f84cbb6c (svn r7341) - Codechange: Also rename the POOL_H define to OLDPOOL_H (forgotten in r7331).
matthijs
parents: 5216
diff changeset
   355
#endif /* OLDPOOL_H */