8 #ifndef COUNTED_PTR_HPP
9 #define COUNTED_PTR_HPP
17 typedef X element_type;
20 : itsCounter(0) {
if (p) itsCounter =
new counter(p);}
24 {acquire(r.itsCounter);}
29 acquire(r.itsCounter);
34 #ifndef NO_MEMBER_TEMPLATES
37 {acquire(r.itsCounter);}
42 acquire(r.itsCounter);
48 X& operator*()
const throw() {
return *itsCounter->ptr;}
49 X* operator->()
const throw() {
return itsCounter->ptr;}
50 X* get()
const throw() {
return itsCounter ? itsCounter->ptr : 0;}
51 bool unique()
const throw()
52 {
return (itsCounter ? itsCounter->count == 1 :
true);}
57 counter(X* p = 0,
unsigned c = 1) : ptr(p), count(c) {}
62 void acquire(counter* c)
throw()
71 if (--itsCounter->count == 0) {
72 delete itsCounter->ptr;
Definition: counted_ptr.hpp:15