#include <RefBank.h>
Description
template<typename T>
class Dynacoe::RefBank< T >
A simple, generic reference counter.
Refbank represents a generic, multi-instance reference counter. RefBank manages a number of accounts. Each account signifies a set of references. Accounts are uniquely identified by the user supplied object T and are automatically created once Deposit() is called. Each account has a reference balance associated with it. Once an account balance has reached 0 or less, the account is removed. If an AccountRemover is set , the AccountRemover callback will be run on the account before removal.
Data Structures | |
class | AccountRemover |
Functions | |
void | Deposit (const T &account, uint32_t amount=1) |
void | Withdraw (const T &account, uint32_t amount=1) |
uint32_t | GetBalance (const T &account) |
void | WithdrawAll () |
void | SetAccountRemover (AccountRemover *) |
Member Function Documentation
void Deposit | ( | const T & | account, |
uint32_t | amount = 1 |
||
) |
Adds a reference count amount.
If a reference count deposite call would yeild a deposit greater than UINT32_MAX, the account is set to UINT32_MAX. (UINT32_MAX is defined in cstdint.h)
- Parameters
-
account The object representing the reference to add counts to amount The reference count amount to add. The default is one.
void Withdraw | ( | const T & | account, |
uint32_t | amount = 1 |
||
) |
Deduct a reference count amount.
If a reference withdrawl would result in a balance of 0 or lower, the AccountHandler is called with the account and is removed.
- Parameters
-
account The object representing the reference to remove counts from. amount The reference count amount to deduct. The default is one.
uint32_t GetBalance | ( | const T & | account | ) |
Returns the number of reference counts accumulated in the account.
If the count does not exist, 0 is returned.
void WithdrawAll | ( | ) |
Removes all accounts and runs the AccountRemover on all accounts.
void SetAccountRemover | ( | AccountRemover * | ) |
Sets the account remover callback.
The lifetime of the source object should match the lifetime of this RefBank
The documentation for this class was generated from the following file:
- /home/jc/git/Dynacoe/DynacoeSrc/includes/Dynacoe/Util/RefBank.h