00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef SGReferenced_HXX
00022 #define SGReferenced_HXX
00023
00024 #include "SGAtomic.hxx"
00025
00030
00031 class SGReferenced {
00032 public:
00033 SGReferenced(void) : _refcount(0u)
00034 {}
00036 SGReferenced(const SGReferenced&) : _refcount(0u)
00037 {}
00039 SGReferenced& operator=(const SGReferenced&)
00040 { return *this; }
00041
00042 static unsigned get(const SGReferenced* ref)
00043 { if (ref) return ++(ref->_refcount); else return ~0u; }
00044 static unsigned put(const SGReferenced* ref)
00045 { if (ref) return --(ref->_refcount); else return ~0u; }
00046 static unsigned count(const SGReferenced* ref)
00047 { if (ref) return ref->_refcount; else return ~0u; }
00048 static bool shared(const SGReferenced* ref)
00049 { if (ref) return 1u < ref->_refcount; else return false; }
00050
00051 private:
00052 mutable SGAtomic _refcount;
00053 };
00054
00055 #endif