Vault  4.1
Public Member Functions | Protected Member Functions
VSingletonShutdownHandler< T > Class Template Reference

This template class allows you to easily register a singleton class T with the shutdown registry, so that it will get cleaned up at shutdown. More...

#include <vshutdownregistry.h>

Inheritance diagram for VSingletonShutdownHandler< T >:
IVShutdownHandler

List of all members.

Public Member Functions

 VSingletonShutdownHandler (bool deleteHandlerAfterShutdown=true)
 Constructs the handler.

Protected Member Functions

virtual void _shutdown ()
 Implementation of IVShutdownHandler interface.

Detailed Description

template<class T>
class VSingletonShutdownHandler< T >

This template class allows you to easily register a singleton class T with the shutdown registry, so that it will get cleaned up at shutdown.

The requirements for the class T are simple:

  1. The class must implement this (public or friend-accessible) function:
    static void deleteInstance();
  2. When you create the instance, also create the shutdown handler; that is, you only create one shutdown handler, so you may as well do it when you create the singleton instance:
    gInstance = new MyClass(params); new VSingletonShutdownHandler<MyClass>();
  3. If you wish to allow deleteInstance() or instance() to be thread-safe, you need to protect the instance with a VMutex. If you can be sure the first call to instance() will be from the main startup thread, you don't need a mutex for it; if you trigger the shutdown registry cleanup after all threads but main have terminated, then you don't need a mutex for deleteInstance() either. Generally I would suggest using a mutex unless you know that removing it is a useful performance optimization and is safe to do.

Definition at line 139 of file vshutdownregistry.h.


Constructor & Destructor Documentation

template<class T >
VSingletonShutdownHandler< T >::VSingletonShutdownHandler ( bool  deleteHandlerAfterShutdown = true) [inline]

Constructs the handler.

Parameters:
deleteHandlerAfterShutdowntrue if the handler (not the T instance) can be deleted after _shutdown() is called; this is true for heap objects, false for global variables

Definition at line 148 of file vshutdownregistry.h.

References VShutdownRegistry::instance(), and VShutdownRegistry::registerHandler().


Member Function Documentation

template<class T >
virtual void VSingletonShutdownHandler< T >::_shutdown ( ) [inline, protected, virtual]

Implementation of IVShutdownHandler interface.

To shut down the singleton means to delete the instance.

Implements IVShutdownHandler.

Definition at line 162 of file vshutdownregistry.h.


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

Copyright ©1997-2014 Trygve Isaacson. All rights reserved. This documentation was generated with Doxygen.