include/am-refcounting.h
changeset 17 563aea5eba06
parent 16 c513ef40773e
child 18 9b30f80f6e49
     1.1 --- a/include/am-refcounting.h	Thu Aug 29 23:51:30 2013 -0700
     1.2 +++ b/include/am-refcounting.h	Sat Aug 31 19:52:41 2013 -0700
     1.3 @@ -58,6 +58,13 @@
     1.4      mutable T *thing_;
     1.5  };
     1.6  
     1.7 +template <typename T>
     1.8 +static inline Newborn<T>
     1.9 +NoAddRef(T *t)
    1.10 +{
    1.11 +    return Newborn<T>(t);
    1.12 +}
    1.13 +
    1.14  // When returning a value, we'd rather not be needlessly changing the refcount,
    1.15  // so we have a special type to use for returns.
    1.16  template <typename T>
    1.17 @@ -191,9 +198,9 @@
    1.18          AddRef();
    1.19      }
    1.20      Ref(Moveable<Ref> other)
    1.21 -      : thing_(other.thing_)
    1.22 +      : thing_(other->thing_)
    1.23      {
    1.24 -        other.thing_ = NULL;
    1.25 +        other->thing_ = NULL;
    1.26      }
    1.27      template <typename S>
    1.28      Ref(const Ref<S> &other)
    1.29 @@ -261,6 +268,13 @@
    1.30          return *this;
    1.31      }
    1.32  
    1.33 +    Ref &operator =(Moveable<Ref> other) {
    1.34 +        Release();
    1.35 +        thing_ = other->thing_;
    1.36 +        other->thing_ = NULL;
    1.37 +        return *this;
    1.38 +    }
    1.39 +
    1.40    private:
    1.41      void AddRef() {
    1.42          if (thing_)