diff options
Diffstat (limited to 'include/core/SkRefCnt.h')
-rw-r--r-- | include/core/SkRefCnt.h | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/include/core/SkRefCnt.h b/include/core/SkRefCnt.h index 384b3be2eb..d6277fdd83 100644 --- a/include/core/SkRefCnt.h +++ b/include/core/SkRefCnt.h @@ -141,7 +141,25 @@ public: return obj; } - T* operator->() { return fObj; } + /** + * BlockRef<T> is a type which inherits from T, cannot be created, + * and makes ref and unref private. + */ + template<typename T> class BlockRef : public T { + private: + BlockRef(); + void ref() const; + void unref() const; + }; + /** + * SkAutoTUnref assumes ownership of the ref. As a result, it is an error + * for the user to ref or unref through SkAutoTUnref. Therefore + * SkAutoTUnref::operator-> returns BlockRef<T>*. This prevents use of + * skAutoTUnrefInstance->ref() and skAutoTUnrefInstance->unref(). + */ + BlockRef<T> *operator->() const { + return static_cast<BlockRef<T>*>(fObj); + } operator T*() { return fObj; } private: |