template
{
adopted(p);
return PassRefPtr
}
同时值得说明的是,在RefPtr和PassRefPtr对象中对引用计数的操作,统一调用了
void refIfNotNull(T*ptr)和void derefIfNotNull(T* ptr),在PassRefPtr中对这两个函数的实现如下:
template
{
if (LIKELY(ptr != 0))
ptr->ref();
}
template
{
if (LIKELY(ptr != 0))
ptr->deref();
}
在RefCountedBase中实现了ref和deref方法,从而实现了智能指针对其保存的引用计数的操作。
而RefPtr和PassRefPtr智能指针并不是只能用于RefCountedBase类对象的,只要重现实现void refIfNotNull(T* ptr)和void derefIfNotNull(T* ptr)函数,就能将智能指针用于其他有引用计数的对象或者结构,在WebCore中,RefPtrCairo.h中就定义了一系列这样的函数,这样在包含该头文件以后,我们就可以使用RefPtr和PassRefPtr管理Cairo的对象了
智能指针:
http://baike.baidu.com/view/1391603.htm
http://zh.wikipedia.org/wiki/%E6%99%BA%E8%83%BD%E6%8C%87%E9%92%88