Use Refcounted to manage to NativeEntry (bug 5852 part 4, r=ds).

--HG--
extra : rebase_source : 2e08816db6819c9d9957a0e0ade9cd1aa420fd54
This commit is contained in:
David Anderson
2013-08-30 10:16:28 -07:00
parent 3da646f913
commit 4500964394
9 changed files with 227 additions and 208 deletions
+14 -1
View File
@@ -1,4 +1,4 @@
// vim: set sts=8 ts=2 sw=2 tw=99 et:
// vim: set sts=8 ts=4 sw=4 tw=99 et:
//
// Copyright (C) 2013, David Anderson and AlliedModders LLC
// All rights reserved.
@@ -31,6 +31,7 @@
#define _include_amtl_refcounting_h_
#include <am-utility.h>
#include <am-moveable.h>
namespace ke {
@@ -189,6 +190,11 @@ class Ref
{
AddRef();
}
Ref(Moveable<Ref> other)
: thing_(other->thing_)
{
other->thing_ = NULL;
}
template <typename S>
Ref(const Ref<S> &other)
: thing_(*other)
@@ -255,6 +261,13 @@ class Ref
return *this;
}
Ref &operator =(Moveable<Ref> other) {
Release();
thing_ = other->thing_;
other->thing_ = NULL;
return *this;
}
private:
void AddRef() {
if (thing_)
+34
View File
@@ -107,6 +107,26 @@ public:
typedef typename Internal::Insert Insert;
typedef typename Internal::iterator iterator;
Result find(const char *aKey)
{
return table_.find(aKey);
}
Insert findForAdd(const char *aKey)
{
return table_.findForAdd(aKey);
}
void add(Insert &i, const T &value)
{
return table_.add(i, value);
}
void add(Insert &i, ke::Moveable<T> value)
{
return table_.add(i, value);
}
bool retrieve(const char *aKey, T *value)
{
CharsAndLength key(aKey);
@@ -126,6 +146,15 @@ public:
return table_.add(i, value);
}
bool insert(const char *aKey, ke::Moveable<T> value)
{
CharsAndLength key(aKey);
Insert i = table_.findForAdd(key);
if (i.found())
return false;
return table_.add(i, value);
}
bool contains(const char *aKey)
{
CharsAndLength key(aKey);
@@ -143,6 +172,11 @@ public:
return true;
}
void remove(Result &r)
{
table_.remove(r);
}
void clear()
{
table_.clear();