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

📄 refcounted.h

📁 java实现的简单的分形树。简单易学!是学习分形知识的很好的例子。其java语法简单
💻 H
字号:
// --------------------------------------------------------------------------
// Dingus project - a collection of subsystems for game/graphics applications
// --------------------------------------------------------------------------

#ifndef __CREFCOUNTED_H
#define __CREFCOUNTED_H


#define DingusSmartPtr boost::intrusive_ptr


namespace dingus {

/**
 *  Reference counted non-copyable object.
 *
 *  Has zero ref count when constructed.
 *  
 *  Intended for use with boost::intrusive_ptr.
 */
class CRefCounted : public boost::noncopyable {
public:
	CRefCounted() : mRefCount(0) { }
	virtual ~CRefCounted() { }

	/** Recrements refcount. Deletes self if refcount reaches zero. */
	int decRef();
	/** Increments refcount. */
	int incRef();
	/** Gets reference count. */
	int getRefCount() const { return mRefCount; }

private:
	int	mRefCount;
};


inline int CRefCounted::incRef() {
	return ++mRefCount;
}

inline int CRefCounted::decRef() {
	assert(mRefCount>0);
	int refs = --mRefCount;
	if(!mRefCount)
		delete this;
	return refs;
}

}; // namespace


//
// for boost::intrusive_ptr<clazz>

#define IMPLEMENT_INTRUSIVE_PTR(clazz) \
namespace boost { \
inline void intrusive_ptr_add_ref( clazz* p ) { p->incRef(); } \
inline void intrusive_ptr_release( clazz* p ) { p->decRef(); } \
}

IMPLEMENT_INTRUSIVE_PTR(dingus::CRefCounted);


#endif

⌨️ 快捷键说明

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