ctkSingleton.h File Reference

Go to the source code of this file.

Defines

#define CTK_SINGLETON_DECLARE(NAME)
 Singleton definition and declaration helpers.
#define CTK_SINGLETON_DECLARE_INITIALIZER(EXPORT_DIRECTIVE, NAME)
 Should be added at the bottom of the header file, after the class declaration.
#define CTK_SINGLETON_DECLARE_PRIVATE(PUB)
 Helper macro.
#define CTK_SINGLETON_DEFINE(NAME)
 This should be added at the end of the CXX file.
#define CTK_SINGLETON_DEFINE_INITIALIZER(NAME)
 Implementation of NAME#Initialize class.

Define Documentation

#define CTK_SINGLETON_DECLARE ( NAME   ) 
Value:
static NAME* Instance;                    \
static void classInitialize();            \
static void classFinalize();              \
friend class NAME##Initialize;

Singleton definition and declaration helpers.

See http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.12 and http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Nifty_Counter Inspired from VTK/Utilities/kwsys/SystemTools class Should be included as a class protected member

Definition at line 36 of file ctkSingleton.h.

#define CTK_SINGLETON_DECLARE_INITIALIZER ( EXPORT_DIRECTIVE,
NAME   ) 
Value:
class EXPORT_DIRECTIVE NAME##Initialize                            \
{                                                                  \
public:                                                            \
  typedef NAME##Initialize Self;                                   \
                                                                   \
  NAME##Initialize();                                              \
  ~NAME##Initialize();                                             \
private:                                                           \
  static unsigned int Count;                                       \
};                                                                 \
                                                                   \
static NAME##Initialize NAME##Initializer;

Should be added at the bottom of the header file, after the class declaration.

Help macro allowing to declare the utility class to make sure NAME is initialized before it is used. The instance (NAME#Initializer) will show up in any translation unit that uses NAME. It will make sure NAME is initialized before it is used.

Definition at line 51 of file ctkSingleton.h.

#define CTK_SINGLETON_DECLARE_PRIVATE ( PUB   ) 
Value:
PUB(const PUB&);                                 \
void operator=(const PUB&);                      \
CTK_DECLARE_PRIVATE(PUB);

Helper macro.

TODO Documentation

Definition at line 114 of file ctkSingleton.h.

#define CTK_SINGLETON_DEFINE ( NAME   ) 
Value:
void NAME::classInitialize()                        \
{                                                   \
  Self::Instance = new NAME;                        \
}                                                   \
                                                    \
void NAME::classFinalize()                          \
{                                                   \
  delete Self::Instance;                            \
}                                                   \
                                                    \
CTK_SINGLETON_DEFINE_INITIALIZER(NAME)

This should be added at the end of the CXX file.

Definition at line 94 of file ctkSingleton.h.

#define CTK_SINGLETON_DEFINE_INITIALIZER ( NAME   ) 
Value:
NAME##Initialize::NAME##Initialize()                \
{                                                   \
  if(++Self::Count == 1)                            \
    { NAME::classInitialize(); }                    \
}                                                   \
                                                    \
NAME##Initialize::~NAME##Initialize()               \
{                                                   \
  if(--Self::Count == 0)                            \
    { NAME::classFinalize(); }                      \
}                                                   \
                                                    \
unsigned int NAME##Initialize::Count;               \
NAME* NAME::Instance;

Implementation of NAME#Initialize class.

Note: NAME#Initialize::Count and NAME::Instance Must NOT be initialized. Default initialization to zero is necessary.

Definition at line 73 of file ctkSingleton.h.

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated on 21 May 2010 for CTK by  doxygen 1.6.1