lumiera::SingletonFactory< SI, Create, Life, Threading > Class Template Reference

#include <singletonfactory.hpp>

Inheritance diagram for lumiera::SingletonFactory< SI, Create, Life, Threading >:

Inheritance graph
[legend]

List of all members.


Detailed Description

template<class SI, template< class > class Create = singleton::StaticCreate, template< class > class Life = singleton::AutoDestroy, template< class > class Threading = singleton::IgnoreThreadsafety>
class lumiera::SingletonFactory< SI, Create, Life, Threading >

A configurable Template for implementing Singletons.

Actually this is a Functor object, which could be placed into a static field of the Singleton (target) class or used directly.

Note:
internally uses static fields, so all functor instances share pInstance_

Definition at line 60 of file singletonfactory.hpp.


Public Member Functions

SI & operator() ()
 Interface to be used by SingletonFactory's clients.

Private Types

typedef Threading< SI >
::VolatileType 
SType
typedef Threading< SI >::Lock ThreadLock

Static Private Member Functions

static void destroy ()

Static Private Attributes

static bool isDead_
static SType * pInstance_

Member Function Documentation

template<class SI, template< class > class Create = singleton::StaticCreate, template< class > class Life = singleton::AutoDestroy, template< class > class Threading = singleton::IgnoreThreadsafety>
static void lumiera::SingletonFactory< SI, Create, Life, Threading >::destroy (  )  [inline, static, private]

For internal use only.

helper used to delegate destroying the single instance to the Create policy, at the same time allowing the Life policy to control the point in the Application lifecycle when the destruction of this instance occures.

Definition at line 99 of file singletonfactory.hpp.

Referenced by lumiera::SingletonFactory< SI, lumiera::singleton::Adapter< lumiera::singleton::StaticCreate< S >, SI >::template Adapted, lumiera::singleton::AutoDestroy< S >, lumiera::singleton::IgnoreThreadsafety< S > >::operator()().

00100         {
00101           TRACE (singleton, "Singleton: triggering destruction");
00102           
00103           REQUIRE (!isDead_);
00104           Create<SI>::destroy (pInstance_);
00105           pInstance_ = 0;
00106           isDead_ = true;
00107         }

Here is the caller graph for this function:

template<class SI, template< class > class Create = singleton::StaticCreate, template< class > class Life = singleton::AutoDestroy, template< class > class Threading = singleton::IgnoreThreadsafety>
SI& lumiera::SingletonFactory< SI, Create, Life, Threading >::operator() (  )  [inline]

Interface to be used by SingletonFactory's clients.

Manages internally the instance creation, lifecycle and access handling in a multithreaded context.

Returns:
"the" single instance of class S

Reimplemented in lumiera::test::MockInjector< SI >.

Definition at line 73 of file singletonfactory.hpp.

00074         {
00075           if (!pInstance_)
00076             {
00077               ThreadLock guard  SIDEEFFECT;
00078               if (!pInstance_)
00079                 {
00080                   if (isDead_)
00081                     {
00082                       Life<SI>::onDeadReference();
00083                       isDead_ = false;
00084                     }
00085                   pInstance_ = Create<SI>::create();
00086                   Life<SI>::scheduleDelete (&destroy);
00087             }   }
00088           ENSURE (pInstance_);
00089           ENSURE (!isDead_);
00090           return *pInstance_;
00091         }


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

Generated on Fri Nov 7 22:15:49 2008 for Lumiera by  doxygen 1.5.6