SourceForge.jp

singleton.h

説明を見る。
00001 
00002 
00011 #ifndef _dktl_utility__h_
00012 #define _dktl_utility__h_
00013 
00014 #include <dkutil/config/dkutilUserConfig.h>
00015 
00016 namespace dkutil{
00017 
00018 template <class T,class UTIL=DKConfigUtility>
00019 class singleton {
00020 
00021 //やねうらお氏のYTL/singleton.hを参考にしました。
00022 public:
00023     singleton(){
00024         //ODS("OK singleton\n");
00025     }
00026     virtual ~singleton() { Release(); }
00028     T& operator*() { return *get(); }
00029     T* operator->() { return get(); }
00030     T* get() { CheckInstance(); return m_lpObj; }
00031     bool    isNull() const { return m_lpObj == NULL; }
00032     void Release(){
00033         if (m_lpObj!=NULL) {
00034             DKUTIL_LOCKTHREAD(m_util);
00035             if(m_lpObj!=NULL){      
00036                 delete m_lpObj;
00037                 m_lpObj = NULL;
00038             }
00039             DKUTIL_UNLOCKTHREAD(m_util);
00040         }
00041     }
00042     void CheckInstance(){
00043         if (m_lpObj==NULL) {
00044             DKUTIL_LOCKTHREAD(m_util);
00045             if(m_lpObj==NULL){
00046                 m_lpObj = new T;
00047             }
00048             DKUTIL_UNLOCKTHREAD(m_util);
00049         }
00050     }
00051 BOOST_PROTECTED:
00052     static T*   m_lpObj;
00053     UTIL m_util;
00054 };
00055 
00056 //  static なオブジェクト
00057 template <class T,class UTIL> T* singleton<T,UTIL>::m_lpObj = 0;
00058 
00059 
00060 }//end of dkutil namepsace
00061 
00062 #endif //end of include once

dkutil 1.02リリース前 d金魚専用マニュアルバージョンに対してSun Dec 28 21:23:08 2003に生成されました。 doxygen 1.3.5