Wt::Singleton< DERIVED > Class Template Reference

#include <singleton.h>

Inheritance diagram for Wt::Singleton< DERIVED >:

Inheritance graph
[legend]
Collaboration diagram for Wt::Singleton< DERIVED >:

Collaboration graph
[legend]
List of all members.

Static Public Member Functions

static DERIVED * instance ()
static DERIVED * existingInstance ()
template<class GRANDCHILD>
static DERIVED * instance ()
 instantiates the pointer compatible child of DERIVED aka grandchild
static void init ()
static void quit ()

Protected Member Functions

 Singleton (DERIVED *d)
 Derived class public constructor.
 ~Singleton ()

Static Protected Member Functions

static DERIVED * load ()
 try to load the instance

Static Protected Attributes

static DERIVED * instance_ = 0

Classes

class  Exception

Detailed Description

template<class DERIVED>
class Wt::Singleton< DERIVED >

Definition at line 30 of file singleton.h.


Constructor & Destructor Documentation

template<class DERIVED>
Wt::Singleton< DERIVED >::Singleton ( DERIVED *  d  )  [inline, protected]

Derived class public constructor.

if the constructor of the derived class is public we have to call this constructor to properly set the instance

Definition at line 71 of file singleton.h.

00071                           {
00072         if (instance_) {
00073             throw Exception();
00074         }
00075         instance_ = d;
00076     }

template<class DERIVED>
Wt::Singleton< DERIVED >::~Singleton (  )  [inline, protected]

Definition at line 78 of file singleton.h.

00078                  {
00079         instance_ = 0;
00080     }


Member Function Documentation

template<class DERIVED>
static DERIVED* Wt::Singleton< DERIVED >::existingInstance (  )  [inline, static]

Definition at line 36 of file singleton.h.

Referenced by Wt::Application::exit(), Wt::Application::postEvent(), Wt::Application::sendEvent(), and Wt::Application::sendPostedEvents().

00036                                        {
00037         return instance_;
00038     }

template<class DERIVED>
static void Wt::Singleton< DERIVED >::init (  )  [inline, static]

Note:
cannot fail

Reimplemented in Wt::Application.

Definition at line 49 of file singleton.h.

Referenced by Wt::Application::Application().

00049                        {
00050         if (!instance()) {
00051             assert(0);
00052         }
00053     }

template<class DERIVED>
template<class GRANDCHILD>
static DERIVED* Wt::Singleton< DERIVED >::instance (  )  [inline, static]

instantiates the pointer compatible child of DERIVED aka grandchild

it is handy in driver like situations

Definition at line 43 of file singleton.h.

00043                                {
00044         return (instance_) ? instance_ : GRANDCHILD::load();
00045     }

template<class DERIVED>
static DERIVED* Wt::Singleton< DERIVED >::instance (  )  [inline, static]

Definition at line 32 of file singleton.h.

Referenced by Wt::Audio::Audio(), Wt::Sound::available(), Wt::SDLMixer::Chunk::channel(), Wt::NullAudio::Chunk::channel(), Wt::SDLSurface::defaultDepth(), Wt::SDLInput::EventInfo::EventInfo(), Wt::Dialog::exec(), Wt::Widget::grabKeyboard(), Wt::Widget::grabMouse(), Wt::Audio::handleAudioEvent(), Wt::SDLInput::handleKeyEvent(), Wt::Singleton< Wt::Audio >::init(), Wt::SDLTimer::init(), Wt::Sound::isAvailable(), Wt::Widget::keyboardGrabber(), Wt::Audio::load(), Wt::Widget::mouseGrabber(), Wt::SDLMixer::onChannelFinish(), Wt::Audio::onChannelFinish(), Wt::Sound::play(), Wt::Singleton< Wt::Audio >::quit(), Wt::Widget::releaseKeyboard(), Wt::Widget::releaseMouse(), Wt::SDLInput::SDLInput(), Wt::SDLMixer::setMusicVolume(), Wt::SDLMixer::Channel::setVolume(), and Wt::SDLMixer::Chunk::setVolume().

00032                                {
00033         return (instance_) ? instance_ : DERIVED::load();
00034     }

template<class DERIVED>
static DERIVED* Wt::Singleton< DERIVED >::load (  )  [inline, static, protected]

try to load the instance

if it fails return NULL if it succeeds must return the newly created object

Reimplemented in Wt::Audio, Wt::NullAudio, and Wt::SDLMixer.

Definition at line 86 of file singleton.h.

00086                            {
00087         instance_ = new DERIVED;
00088         return  instance_;
00089     }

template<class DERIVED>
static void Wt::Singleton< DERIVED >::quit (  )  [inline, static]

Reimplemented in Wt::Application.

Definition at line 55 of file singleton.h.

Referenced by Wt::Application::~Application().

00055                        {
00056         delete instance();
00057     }


Member Data Documentation

template<class DERIVED>
DERIVED * Wt::Singleton< DERIVED >::instance_ = 0 [static, protected]

Definition at line 91 of file singleton.h.

Referenced by Wt::Singleton< Wt::Audio >::existingInstance(), Wt::Singleton< Wt::Audio >::instance(), Wt::Singleton< Wt::Audio >::load(), Wt::SDLDisplay::load(), Wt::Audio::load(), Wt::Singleton< Wt::Audio >::Singleton(), and Wt::Singleton< Wt::Audio >::~Singleton().


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

Generated Fri Jul 28 19:33:02 2006.
Copyright © 1998-2003 by the respective authors.

This document is licensed under the terms of the GNU Free Documentation License and may be freely distributed under the conditions given by this license.