📄 singleton.h
字号:
/**
* Copyright (c) 2005 Zhejiang University, P.R.China
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
//=============================================================================
/**
* \class PPC_Singleton
*
* \brief Singleton holder
*
* \author Chenfeng Zhou <ini_autumn@163.com>
*
* Last update: <2005-02-09 22:07:06 by Cheney Chow>
*
* $Id: Singleton.h,v 1.1 2005/06/16 06:06:36 qilj Exp $
*/
//=============================================================================
#ifndef _PPC_SINGLETON_H_
#define _PPC_SINGLETON_H_
namespace PPC
{
//! We use template to generalize all the types need to have
//! only one instance;
template<typename TYPE>
class PPC_Singleton
{
public:
static TYPE *instance ()
{
if (NULL == singleton_instance_) {
singleton_instance_ = new PPC_Singleton<TYPE>();
}
return &singleton_instance_->instance_;
}
private:
PPC_Singleton () {}
~PPC_Singleton () {}
private:
static PPC_Singleton<TYPE> *singleton_instance_;
TYPE instance_;
};
template<typename TYPE>
PPC_Singleton<TYPE> *PPC_Singleton<TYPE>::singleton_instance_ = NULL;
} //namespace PPC
#endif // _PPC_SINGLETON_H_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -