API RefObject : public GenObject

请声明出处:

对象的引用计数的类,基本大部分的类都继承了该类:

/** * A reference counted object. * 引用计数的对象 * Whenever using multiple inheritance you should inherit this class virtually. * 使用多重继承,一般都会继承这个类 */class YATE_API RefObject : public GenObject{YNOCOPY(RefObject); // no automatic copies pleasepublic:/*** The constructor initializes the reference counter to 1!* 构造函数,初始化引用计数器为1.* Use deref() to destruct the object when safe* 使用deref()去销毁这个对象在安全的时候*/RefObject();/*** Destructor.*/virtual ~RefObject();/*** Get a pointer to a derived class given that class name* 获取一个指向派生类的指针,因为类名* @param name Name of the class we are asking for* @参数 name,请求的类名* @return Pointer to the requested class or NULL if this object doesn't implement it* @返回被请求类的地址,为NULL,如果这个对象没有实例化*/virtual void* getObject(const String& name) const;/*** Check if the object is still referenced and safe to access.* 检查对象是否依旧被引用并且安全的访问* Note that you should not trust this result unless the object is locked* 注意,,不能完全相信这个结果,除非对象被其他方法锁定* by other means.* @return True if the object is referenced and safe to access* @返回True,如果对象被引用并且安全的访问*/virtual bool alive() const;/*** Increments the reference counter if not already zero* 增加引用计数器,如果不为0* @return True if the object was successfully referenced and is safe to access* @返回True,如果对象被引用并且安全的访问*/bool ref();/*** Decrements the reference counter, destroys the object if it reaches zero* 减少引用计数器,如果为0则销毁对象* <pre>* // Deref this object, return quickly if the object was deleted* if (deref()) return;* </pre>* @return True if the object may have been deleted, false if it still exists and is safe to access* @返回true,如果对象已经被删除,false,依旧存在并且安全的访问*/bool deref();/*** Get the current value of the reference counter* 获取引用计数器当前的值* @return The value of the reference counter*/inline int refcount() const{ return m_refcount; }/*** Refcounted objects should just have the counter decremented.* 引用计数对象减少计数器* That will destroy them only when the refcount reaches zero.* 当引用计数器为0的时候销毁*/virtual void destruct();/*** Check if reference counter manipulations are efficient on this platform.* 检查在这个平台上引用计数器对象是否有效* If platform does not support atomic operations a mutex pool is used.* 如果该平台不支持原子操作使用互斥对象池* @return True if refcount uses atomic integer operations* @返回true,如果对象计数使用原子整数操作*/static bool efficientIncDec();protected:/*** This method is called when the reference count reaches zero after* 当该应用计数为0之后调用这个方法* unlocking the mutex if the call to zeroRefsTest() returned true.* 如果调用zeroRefsTest() 返回true,解除这个互斥锁* The default behaviour is to delete the object.* 默认删除这个对象*/virtual void zeroRefs();/*** Bring the object back alive by setting the reference counter to one.* Note that it works only if the counter was zero previously* @return True if the object was resurrected – its name may be Lazarus ;-)*/bool resurrect();/*** Pre-destruction notification, called just before the object is deleted.* Unlike in the destructor it is safe to call virtual methods here.* Reimplementing this method allows to perform any object cleanups.*/virtual void destroyed();private:int m_refcount;Mutex* m_mutex;};

夫妇一条心,泥土变黄金。

API RefObject : public GenObject

相关文章:

你感兴趣的文章:

标签云: