mirror of
https://github.com/love2d/love.git
synced 2026-08-16 00:02:12 +02:00
Cleaned up some StrongRef-related code.
This commit is contained in:
+21
-12
@@ -75,32 +75,41 @@ private:
|
||||
|
||||
}; // Object
|
||||
|
||||
/**
|
||||
* Partial re-implementation + specialization of std::shared_ptr. We can't
|
||||
* use C++11's stdlib yet...
|
||||
**/
|
||||
|
||||
enum class Acquire
|
||||
{
|
||||
RETAIN,
|
||||
NORETAIN,
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class StrongRef
|
||||
{
|
||||
public:
|
||||
|
||||
StrongRef()
|
||||
: object(nullptr)
|
||||
: object(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
StrongRef(T *obj)
|
||||
: object(obj)
|
||||
StrongRef(T *obj, Acquire acquire = Acquire::RETAIN)
|
||||
: object(obj)
|
||||
{
|
||||
if (object) object->retain();
|
||||
if (object && acquire == Acquire::RETAIN) object->retain();
|
||||
}
|
||||
|
||||
StrongRef(const StrongRef &other)
|
||||
: object(other.get())
|
||||
: object(other.get())
|
||||
{
|
||||
if (object) object->retain();
|
||||
}
|
||||
|
||||
StrongRef(StrongRef &&other)
|
||||
: object(other.object)
|
||||
{
|
||||
other.object = nullptr;
|
||||
}
|
||||
|
||||
~StrongRef()
|
||||
{
|
||||
if (object) object->release();
|
||||
@@ -117,7 +126,7 @@ public:
|
||||
return object;
|
||||
}
|
||||
|
||||
operator bool() const
|
||||
explicit operator bool() const
|
||||
{
|
||||
return object != nullptr;
|
||||
}
|
||||
@@ -127,9 +136,9 @@ public:
|
||||
return object;
|
||||
}
|
||||
|
||||
void set(T *obj)
|
||||
void set(T *obj, Acquire acquire = Acquire::RETAIN)
|
||||
{
|
||||
if (obj) obj->retain();
|
||||
if (obj && acquire == Acquire::RETAIN) obj->retain();
|
||||
if (object) object->release();
|
||||
object = obj;
|
||||
}
|
||||
|
||||
@@ -111,6 +111,14 @@ Variant::Variant(const Variant &v)
|
||||
data.table->retain();
|
||||
}
|
||||
|
||||
Variant::Variant(Variant &&v)
|
||||
: type(std::move(v.type))
|
||||
, udatatype(std::move(v.udatatype))
|
||||
, data(std::move(v.data))
|
||||
{
|
||||
v.type = NIL;
|
||||
}
|
||||
|
||||
Variant::~Variant()
|
||||
{
|
||||
switch (type)
|
||||
|
||||
@@ -43,6 +43,7 @@ public:
|
||||
Variant(love::Type udatatype, void *userdata);
|
||||
Variant(std::vector<std::pair<Variant, Variant>> *table);
|
||||
Variant(const Variant &v);
|
||||
Variant(Variant &&v);
|
||||
~Variant();
|
||||
|
||||
Variant &operator = (const Variant &v);
|
||||
|
||||
Reference in New Issue
Block a user