ROSE  0.9.9.139
SharedObject.h
1 // WARNING: Changes to this file must be contributed back to Sawyer or else they will
2 // be clobbered by the next update from Sawyer. The Sawyer repository is at
3 // https://github.com/matzke1/sawyer.
4 
5 
6 
7 
8 #ifndef Sawyer_SharedObject_H
9 #define Sawyer_SharedObject_H
10 
11 #include <Sawyer/Sawyer.h>
12 #include <Sawyer/Synchronization.h>
13 
14 namespace Sawyer {
15 
22 class SAWYER_EXPORT SharedObject {
23  template<class U> friend class SharedPointer;
24  mutable SAWYER_THREAD_TRAITS::Mutex mutex_;
25  mutable size_t nrefs_;
26 public:
28  SharedObject(): nrefs_(0) {}
29 
34  SharedObject(const SharedObject&): nrefs_(0) {}
35 
37  virtual ~SharedObject() {
38  ASSERT_require(nrefs_==0);
39  }
40 
45  return *this;
46  }
47 };
48 
49 } // namespace
50 
51 #endif
SharedObject()
Default constructor.
Definition: SharedObject.h:28
SharedObject(const SharedObject &)
Copy constructor.
Definition: SharedObject.h:34
SharedObject & operator=(const SharedObject &)
Assignment.
Definition: SharedObject.h:44
Reference-counting smart pointer.
Definition: SharedPointer.h:34
Name space for the entire library.
Definition: Access.h:11
virtual ~SharedObject()
Virtual destructor.
Definition: SharedObject.h:37
Base class for reference counted objects.
Definition: SharedObject.h:22