Scopira 20080306

singleton.h

00001 
00002 /*
00003  *  Copyright (c) 2004    National Research Council
00004  *
00005  *  All rights reserved.
00006  *
00007  *  This material is confidential and proprietary information of
00008  *  National Research Council Canada ("Confidential Information").
00009  *  This Confidential Information may only be used and reproduced
00010  *  in accordance with the terms of the license agreement.
00011  *
00012  */
00013 
00014 #ifndef __INCLUDED_SCOPIRA_TOOL_SINGLETON_H__
00015 #define __INCLUDED_SCOPIRA_TOOL_SINGLETON_H__
00016 
00017 #include <assert.h>
00018 
00019 namespace scopira
00020 {
00021   namespace tool
00022   {
00023     template <class T> class singleton;
00024   }
00025 }
00026 
00038 template <class T> class scopira::tool::singleton
00039 {
00040   protected:
00041     typedef scopira::tool::singleton<T> singleton_type;
00042 
00043   public:
00045     static T * instance(void) { return dm_instance; }
00046 
00047   protected:
00049     singleton(T *here) {
00050       assert(!dm_instance);
00051       dm_instance = here;
00052     }
00054     ~singleton(void) {
00055       assert(dm_instance);
00056       dm_instance = 0;
00057     }
00058 
00059   private:
00060     static T * dm_instance; 
00061 };
00062 
00063 #endif
00064