LIBINT  2.6.0
Public Types | Public Member Functions | List of all members
libint2::SingletonStack< T, KeyType > Class Template Reference

SingletonStack<T,KeyType> helps to implement Singleton-like objects of type T. More...

#include <singl_stack.h>

Inheritance diagram for libint2::SingletonStack< T, KeyType >:
Inheritance graph
[legend]
Collaboration diagram for libint2::SingletonStack< T, KeyType >:
Collaboration graph
[legend]

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

- Protected Types inherited from libint2::PurgeableStack< T >
typedef DefaultPurgingPolicy< T > PurgingPolicy
 

Detailed Description

template<class T, class KeyType>
class libint2::SingletonStack< T, KeyType >

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&.

Member Function Documentation

◆ find() [1/2]

template<class T, class KeyType>
const value_type& libint2::SingletonStack< T, KeyType >::find ( const SafePtr< T > &  obj)
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.

◆ find() [2/2]

template<class T, class KeyType>
const value_type& libint2::SingletonStack< T, KeyType >::find ( const key_type &  key)
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.

◆ find_hashed()

template<class T, class KeyType>
const value_type& libint2::SingletonStack< T, KeyType >::find_hashed ( const InstanceID hashed_key) const
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.


The documentation for this class was generated from the following file: