include/xot/ref.h in xot-0.1.12 vs include/xot/ref.h in xot-0.1.13

- old
+ new

@@ -9,15 +9,14 @@ #endif #include <limits.h> #include <assert.h> #include <typeinfo> -#include <boost/noncopyable.hpp> -#include <boost/type_traits.hpp> -#include <boost/utility/enable_if.hpp> +#include <type_traits> #include <xot/defs.h> #include <xot/exception.h> +#include <xot/noncopyable.h> #include <xot/debug.h> //#define XOT_REF_DEBUG 1 @@ -28,42 +27,43 @@ class EmptyClass {}; template <typename SuperClass = EmptyClass> - class RefCountable : public SuperClass, public boost::noncopyable + class RefCountable : public SuperClass, public NonCopyable { public: - virtual void retain (void* data = NULL) const + virtual void retain (intptr_t data = 0) const { - refc_update_count(+1); + refc_update_count(true); #ifdef XOT_REF_DEBUG doutln( "%s: %d -> %d", - typeid(this).name(), refc_count() - 1, refc_count()); + typeid(this).name(), refc_count - 1, refc_count); #endif } - virtual void release (void* data = NULL) const + virtual void release (intptr_t data = 0) const { - assert(refc_count() >= 0); - bool del = !refc_retained() || refc_update_count(-1) == 0; + assert(refc_count >= 0); + bool del = refc_count == 0 || refc_update_count(false) == 0; + #ifdef XOT_REF_DEBUG doutln( - "%s: %d -> %d, refcount:%s, delete:%s", - typeid(this).name(), refc_count() + 1, refc_count(), - refc_retained() ? "yes" : "no", del ? "yes" : "no"); + "%s: %d -> %d, delete:%s", + typeid(this).name(), refc_count + 1, refc_count, + del ? "yes" : "no"); #endif if (del) delete this; } - virtual void* rucy_value () const + virtual void* rucy_wrapper_value () const { return NULL; } virtual bool rucy_disable_override () const @@ -79,58 +79,25 @@ virtual ~RefCountable () { } - virtual int refc_count () const - { - return refc.count; - } + private: - virtual bool refc_retained () const - { - return refc.aux & 0x1; - } + mutable int refc_count = 0; - virtual int refc_update_count (int add) const + int refc_update_count (bool increment) const { - assert(add != 0); - if (add >= 0) refc.aux |= 0x1;// bit for retained flag. - - int c = refc.count + add; + int c = refc_count + (increment ? +1 : -1); if (c < 0) - invalid_state_error(__FILE__, __LINE__); - if (c > USHRT_MAX) - xot_error(__FILE__, __LINE__, "refc.count overflow."); + invalid_state_error(__FILE__, __LINE__, "refc_count underflow"); + if (c > INT_MAX) + xot_error(__FILE__, __LINE__, "refc_count overflow."); - return refc.count = c; + return refc_count = c; } - virtual ushort refc_aux () const - { - return refc.aux >> 1; - } - - virtual void refc_set_aux (ushort aux) const - { - if ((0x1 << 15) & aux) - argument_error(__FILE__, __LINE__); - - refc.aux = (refc.aux & 0x1) | (aux << 1); - } - - private: - - mutable struct Data - { - - ushort count, aux; - - Data () : count(0), aux(0) {} - - } refc; - };// RefCountable template <typename T, typename = void> class Ref @@ -230,17 +197,17 @@ };// Ref template <typename T> - class Ref<T, typename boost::enable_if<boost::is_const<T> >::type> + class Ref<T, typename std::enable_if<std::is_const<T>::value>::type> { typedef Ref<T> This; - typedef typename boost::remove_const<T>::type Value; + typedef typename std::remove_const<T>::type Value; - typedef T ConstValue; + typedef T ConstValue; typedef Value& Reference; typedef const Value& ConstReference;