/**
* An object with just a public virtual destructor
* 一个对象只有一个公共的虚拟析构函数
*/
class YATE_API GenObject
{
YNOCOPY(GenObject); // no automatic copies please 请不要自动拷贝
public:
/**
* Default constructor
* 默认构造函数
*/
GenObject();
/**
* Destructor.
* 析构函数
*/
virtual ~GenObject() { setObjCounter(0); }
/**
* Check if the object is still valid 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 still useable
* @返回True,如果对象仍然是可用的
*/
virtual bool alive() const;
/**
* Destroys the object, disposes the memory.
* 销毁这个对象,释放内存。
*/
virtual void destruct();
/**
* Get a string representation of this object
* 获得该对象的字符串表示
* @return A reference to a String representing this object
* which is either null, the object itself (for objects derived from
* String) or some form of identification
* 返回一个引用字符串表示这个对象,
* 要么是null,对象本身(对于对象来自字
* 符串)或某种形式的识别
*/
virtual const String& toString() const;
/**
* 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;
/**
* Helper method to get the pointer to a derived class
* 助手方法指向派生类的指针
* @param name Name of the class we are asking for
* @param obj Pointer to the object to get derived class from
* @参数obj是指向派生类的对象的指针
* @return Pointer to the requested class or NULL if this object doesn't implement it
* @返回请求的类的指针或者NULL(如果这个对象没有实现)
*/
static inline void* getObject(const String& name, const GenObject* obj)
{ return obj ? obj->getObject(name) : 0; }
/**
* Get the global state of object counting
* 获得对象的全局状态计数
* @return True if object counting is enabled
* @返回True如果对象状态是使能的
*/
static inline bool getObjCounting()
{ return s_counting; }
/**
* Set the global state of object counting
* 设置全局的对象计数状态
* @param enable True to enable object counting, false to disable
* @参数enable,True启用对象计数,false禁用
*/
static inline void setObjCounting(bool enable)
{ s_counting = enable; }
/**
* Get the counter of this object
* 得到这个对象的计数器
* @return Pointer to current counter object
* @返回当前的计数器指针对象
*/
inline NamedCounter* getObjCounter() const
{ return m_counter; }
/**
* Set the counter of this object
* 设置这个对象的计数器数
* @param counter New counter object or NULL
* @参数counter 新的计数器对象或NUL
* @return Pointer to old counter object
* @返回旧计数器指针对象
*/
NamedCounter* setObjCounter(NamedCounter* counter);
/**
* Retrieve or allocate an object counter
* 检索或分配一个对象计数器
* @param name Name of the counter
* @参数name 计数器的名字
* @param create True to create a new counter if needed
* @参数create, True 如果需要创建一个新的计数器
* @return Pointer to existing or new counter object
* @返回指向现有或新的计数器指针对象
*/
static NamedCounter* getObjCounter(const String& name, bool create = true);
/**
* Access the object counters list
* 访问对象计数器列表
* @return Reference to the global object counters list
* @返回列表全局对象的引用计数器
*/
static ObjList& getObjCounters();
private:
NamedCounter* m_counter;
static bool s_counting;
};