LIBINT
2.6.0
|
SingletonStack<T,KeyType> helps to implement Singleton-like objects of type T. More...
#include <singl_stack.h>
Public Types | |
typedef KeyType | key_type |
typedef SafePtr< T > | data_type |
typedef KeyTypes::InstanceID | InstanceID |
Specifies type for the instance index variables. | |
typedef std::pair< InstanceID, SafePtr< T > > | value_type |
typedef std::map< key_type, value_type > | map_type |
typedef map_type::iterator | iter_type |
use iter_type objects to iterate over the stack | |
typedef map_type::const_iterator | citer_type |
const version of iter_type | |
typedef KeyTraits< key_type >::ReturnType | key_return_type |
hashing function returns keys as key_return_type | |
typedef key_return_type(T::* | HashingFunction) () const |
Specifies the type of callback which computes hashes. | |
typedef PurgeableStack< T >::PurgingPolicy | PurgingPolicy |
PurgingPolicy determines whether and which objects on this stack are obsolete and can be removed. | |
Public Member Functions | |
SingletonStack (HashingFunction callback) | |
callback to compute hash values is the only parameter | |
const value_type & | find (const SafePtr< T > &obj) |
Returns the pointer to the unique instance of object obj. More... | |
const value_type & | find (const key_type &key) |
Returns the pointer to the unique instance of object corresponding to key. More... | |
const value_type & | find_hashed (const InstanceID &hashed_key) const |
Returns the pointer to the unique instance of object corresponding to the hashed_key. More... | |
void | remove (const SafePtr< T > &obj) |
Searches for obj on the stack and, if found, removes the unique instance. | |
citer_type | begin () const |
Returns iterator to the beginning of the stack. | |
citer_type | end () const |
Returns iterator to the end of the stack. | |
virtual void | purge () |
Additional Inherited Members | |
![]() | |
typedef DefaultPurgingPolicy< T > | PurgingPolicy |
SingletonStack<T,KeyType> helps to implement Singleton-like objects of type T.
SingletonStack maintains a map of keys of type KeyType to smart pointers to objects of type T. Keys are computed from T by calling a callback of type HashingFunction passed to the constructor to SingletonStack – hence HashingFunction is a member function T which takes no arguments and returns a const KeyType&.
|
inline |
Returns the pointer to the unique instance of object obj.
find() computes obj->*callback_(), searches it in hstack_, if found – returns the pointer to the corresponding object on ostack_, otherwise pushes obj to the end of ostack_ and returns obj.
|
inline |
Returns the pointer to the unique instance of object corresponding to key.
if found returns the pointer to the corresponding object on ostack_, else returns a null value_type.
|
inline |
Returns the pointer to the unique instance of object corresponding to the hashed_key.
if found returns the pointer to the corresponding object on ostack_, else returns a null value_type.