/* Copyright 2005 Chris Thomasson */ #if ! defined(__cplusplus) #include "refcount.h" #elif ! defined(REFCOUNT_HPP_INCLUDED) #define REFCOUNT_HPP_INCLUDED #if defined(_MSC_VER) #pragma warning(disable : 4505 4514) #endif #include "refcount-sys.hpp" namespace vzsync { static void libinit(); namespace ptr { template class global; template class local; namespace prv { template class base; template class weak_base; template class base : public sys::refcount::ptr_base { public: typedef global global_t; typedef local local_t; public: base() throw() {} base(T *state, int count) : sys::refcount::ptr_base(state, count) {} ~base() throw() {} }; template class weak_base : public base { public: weak_base() throw() {} weak_base(T *state, int count) : base(state, count) {} ~weak_base() throw() {} public: inline T const* operator ->() const { return base::load_ptr(); } inline T* operator ->() { return base::load_ptr(); } inline T const& operator *() const { return base::load_ref(); } inline T& operator *() { return base::load_ref(); } }; } template class global : public prv::base { public: global() throw() {} global(T *state, int count = 1) : prv::base(state, count) {} ~global() throw() {} public: global(global const &rhs) throw() { global_copy_global(rhs, 1); } global(typename prv::base::local_t const &rhs) throw() { global_copy_local(rhs, 1); } public: global const& operator =(global const &rhs) throw() { global_set_global(rhs, 1); return *this; } global const& operator =(typename prv::base::local_t const &rhs) throw() { global_set_local(rhs, 1); return *this; } }; template class local : public prv::weak_base { public: local() throw() {} local(T *state, int count = 1) : prv::weak_base(state, count) {} ~local() throw() {} public: local(local const &rhs) throw() { local_copy_local(rhs, 1); } local(typename prv::base::global_t const &rhs) throw() { local_copy_global(rhs, 1); } public: local const& operator =(local const &rhs) throw() { local_set_local(rhs, 1); return *this; } local const& operator =(typename prv::base::global_t const &rhs) throw() { local_set_global(rhs, 1); return *this; } }; } void libinit() { sys::refcount::libinit(); } } // namespace vzsync::ptr #endif