⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kstaticdeleter.h

📁 monqueror一个很具有参考价值的源玛
💻 H
字号:
#ifndef _KSTATIC_DELETER_H_#define _KSTATIC_DELETER_H_#include <kglobal.h>class KStaticDeleterBase {public:    virtual void destructObject() = 0;};/** * little helper class to clean up static objects that are * held as pointer. * * A typical use is * static KStaticDeleter<MyClass> sd; * * MyClass::self() { *   if (!_self) { _self = sd.setObject(new MyClass()); } * } */template<class type> class KStaticDeleter : public KStaticDeleterBase {public:    KStaticDeleter() { deleteit = 0; }    /**     * sets the object to delete and registers the object to be     * deleted to KGlobal. if the given object is 0, the former     * registration is unregistred     * @param isArray tells the destructor to delete an array instead of an object     **/    type *setObject( type *obj, bool isArray = false) {        deleteit = obj;	array = isArray;	if (obj)            KGlobal::registerStaticDeleter(this);	else	    KGlobal::unregisterStaticDeleter(this);        return obj;    }    virtual void destructObject() {	if (array)	   delete [] deleteit;	else	   delete deleteit;    	deleteit = 0;    }    virtual ~KStaticDeleter() {    	KGlobal::unregisterStaticDeleter(this);	destructObject();    }private:    type *deleteit;    bool array;};#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -