Commit 1f40291c by Geoff Lang

Remove the non-templated RefCountObjectBindingPointer class.

This allows the regular BindingPointer class to template on const types. Also added assignment and copy operators that don't leak the resources. BUG=angleproject:880 Change-Id: If3efa26a7fa89306d783c3e8a5fb92b16861d77a Reviewed-on: https://chromium-review.googlesource.com/257670Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 6341939f
......@@ -37,11 +37,3 @@ void RefCountObject::release() const
}
}
void RefCountObjectBindingPointer::set(RefCountObject *newObject)
{
// addRef first in case newObject == mObject and this is the last reference to it.
if (newObject != NULL) newObject->addRef();
if (mObject != NULL) mObject->release();
mObject = newObject;
}
......@@ -35,48 +35,66 @@ class RefCountObject
mutable std::size_t mRefCount;
};
class RefCountObjectBindingPointer
template <class ObjectType>
class BindingPointer
{
protected:
RefCountObjectBindingPointer() : mObject(NULL) { }
~RefCountObjectBindingPointer() { ASSERT(mObject == NULL); } // Objects have to be released before the resource manager is destroyed, so they must be explicitly cleaned up.
public:
BindingPointer()
: mObject(nullptr)
{
}
void set(RefCountObject *newObject);
RefCountObject *get() const { return mObject; }
BindingPointer(const BindingPointer<ObjectType> &other)
: mObject(nullptr)
{
set(other.mObject);
}
public:
GLuint id() const { return (mObject != NULL) ? mObject->id() : 0; }
bool operator!() const { return (get() == NULL); }
void operator=(const BindingPointer<ObjectType> &other)
{
set(other.mObject);
}
private:
RefCountObject *mObject;
};
virtual ~BindingPointer()
{
// Objects have to be released before the resource manager is destroyed, so they must be explicitly cleaned up.
ASSERT(mObject == nullptr);
}
template <class ObjectType>
class BindingPointer : public RefCountObjectBindingPointer
{
public:
void set(ObjectType *newObject) { RefCountObjectBindingPointer::set(newObject); }
ObjectType *get() const { return static_cast<ObjectType*>(RefCountObjectBindingPointer::get()); }
ObjectType *operator->() const { return get(); }
virtual void set(ObjectType *newObject)
{
// addRef first in case newObject == mObject and this is the last reference to it.
if (newObject != nullptr) reinterpret_cast<const RefCountObject*>(newObject)->addRef();
if (mObject != nullptr) reinterpret_cast<const RefCountObject*>(mObject)->release();
mObject = newObject;
}
ObjectType *get() const { return mObject; }
ObjectType *operator->() const { return mObject; }
GLuint id() const { return (mObject != nullptr) ? mObject->id() : 0; }
bool operator!() const { return (mObject == nullptr); }
private:
ObjectType *mObject;
};
template <class ObjectType>
class OffsetBindingPointer : public RefCountObjectBindingPointer
class OffsetBindingPointer : public BindingPointer<ObjectType>
{
public:
OffsetBindingPointer() : mOffset(0), mSize(0) { }
void set(ObjectType *newObject)
void set(ObjectType *newObject) override
{
RefCountObjectBindingPointer::set(newObject);
BindingPointer<ObjectType>::set(newObject);
mOffset = 0;
mSize = 0;
}
void set(ObjectType *newObject, GLintptr offset, GLsizeiptr size)
{
RefCountObjectBindingPointer::set(newObject);
BindingPointer<ObjectType>::set(newObject);
mOffset = offset;
mSize = size;
}
......@@ -84,9 +102,6 @@ class OffsetBindingPointer : public RefCountObjectBindingPointer
GLintptr getOffset() const { return mOffset; }
GLsizeiptr getSize() const { return mSize; }
ObjectType *get() const { return static_cast<ObjectType*>(RefCountObjectBindingPointer::get()); }
ObjectType *operator->() const { return get(); }
private:
GLintptr mOffset;
GLsizeiptr mSize;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment