Add reference counting to IDatabase (bug 5876 part 2, r=ds).
--HG-- extra : rebase_source : 9fef982c3923a2f5cb842b3b8a5cca235ef9c6b9
This commit is contained in:
+15
-1
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* vim: set ts=4 :
|
||||
* vim: set ts=4 sw=4 tw=99 noet :
|
||||
* =============================================================================
|
||||
* SourceMod
|
||||
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
||||
@@ -607,6 +607,20 @@ namespace SourceMod
|
||||
* @param characterset The characterset to switch to. e.g. "utf8".
|
||||
*/
|
||||
virtual bool SetCharacterSet(const char *characterset) =0;
|
||||
|
||||
/**
|
||||
* @brief Wrapper around IncReferenceCount(), for ke::Ref.
|
||||
*/
|
||||
void AddRef() {
|
||||
IncReferenceCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Wrapper around Close(), for ke::Ref.
|
||||
*/
|
||||
void Release() {
|
||||
Close();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -44,19 +44,17 @@ template <typename T>
|
||||
class Newborn
|
||||
{
|
||||
public:
|
||||
Newborn(const T &t)
|
||||
Newborn(T *t)
|
||||
: thing_(t)
|
||||
{
|
||||
}
|
||||
|
||||
T release() const {
|
||||
T temp = thing_;
|
||||
thing_ = T();
|
||||
return temp;
|
||||
T *release() const {
|
||||
return ReturnAndVoid(thing_);
|
||||
}
|
||||
|
||||
private:
|
||||
mutable T thing_;
|
||||
mutable T *thing_;
|
||||
};
|
||||
|
||||
// When returning a value, we'd rather not be needlessly changing the refcount,
|
||||
@@ -110,9 +108,6 @@ class PassRef
|
||||
T *operator *() const {
|
||||
return thing_;
|
||||
}
|
||||
operator bool () const {
|
||||
return !!thing_;
|
||||
}
|
||||
bool operator !() const {
|
||||
return !thing_;
|
||||
}
|
||||
@@ -209,7 +204,7 @@ class Ref
|
||||
: thing_(other.release())
|
||||
{
|
||||
}
|
||||
Ref(const Newborn<T *> &other)
|
||||
Ref(const Newborn<T> &other)
|
||||
: thing_(other.release())
|
||||
{
|
||||
}
|
||||
@@ -227,9 +222,6 @@ class Ref
|
||||
operator T *() {
|
||||
return thing_;
|
||||
}
|
||||
operator bool () const {
|
||||
return !!thing_;
|
||||
}
|
||||
bool operator !() const {
|
||||
return !thing_;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user