Reduced the number of explicit retain/release method calls on love objects. Less chance of bugs!

This commit is contained in:
Alex Szpakowski
2014-08-07 14:53:17 -03:00
parent a0fff798aa
commit d59c76a55f
38 changed files with 194 additions and 247 deletions
+62
View File
@@ -92,11 +92,73 @@ public:
}; // AutoRelease
/**
* Partial re-implementation + specialization of std::shared_ptr. We can't
* use C++11's stdlib yet...
**/
template <typename T>
class StrongRef
{
public:
StrongRef()
: object(nullptr)
{
}
StrongRef(T *obj)
: object(obj)
{
if (object) object->retain();
}
StrongRef(const StrongRef &other)
: object(other.get())
{
if (object) object->retain();
}
~StrongRef()
{
if (object) object->release();
}
StrongRef &operator = (const StrongRef &other)
{
set(other.get());
return *this;
}
T *operator->() const
{
return object;
}
void set(T *obj)
{
if (obj) obj->retain();
if (object) object->release();
object = obj;
}
T *get() const
{
return object;
}
private:
T *object;
}; // StrongRef
private:
// The reference count.
int count;
}; // Object
} // love
#endif // LOVE_OBJECT_H