Make a KernelObject base class for all Capabilities.

This commit is contained in:
Drew Galbraith 2023-06-06 20:13:07 -07:00
parent d358c1d672
commit 4e278a4664
9 changed files with 50 additions and 21 deletions

View file

@ -6,6 +6,9 @@ class RefPtr;
template <typename T>
RefPtr<T> AdoptPtr(T* ptr);
template <typename T, typename U>
RefPtr<T> StaticCastRefPtr(const RefPtr<U>& ref);
template <typename T>
class RefPtr {
public:
@ -38,6 +41,11 @@ class RefPtr {
return *this;
}
enum DontAdoptTag {
DontAdopt,
};
RefPtr(T* ptr, DontAdoptTag) : ptr_(ptr) { ptr->Acquire(); }
T* get() const { return ptr_; };
T& operator*() const { return *ptr_; }
T* operator->() const { return ptr_; }
@ -74,3 +82,8 @@ template <typename T>
RefPtr<T> AdoptPtr(T* ptr) {
return RefPtr(ptr);
}
template <typename T, typename U>
RefPtr<T> StaticCastRefPtr(const RefPtr<U>& ref) {
return RefPtr(static_cast<T*>(ref.get()), RefPtr<T>::DontAdopt);
}