Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef GNASH_REF_COUNTED_H
00020 #define GNASH_REF_COUNTED_H
00021
00022 #include "dsodefs.h"
00023
00024 #include <cassert>
00025 #include <boost/detail/atomic_count.hpp>
00026
00027 namespace gnash {
00028
00034 class DSOEXPORT ref_counted
00035 {
00036
00037 private:
00038
00039
00040
00041
00042
00043
00044 typedef boost::detail::atomic_count Counter;
00045
00046
00047 mutable Counter m_ref_count;
00048
00049 protected:
00050
00051
00052
00053 virtual ~ref_counted()
00054 {
00055 assert(m_ref_count == 0);
00056 }
00057
00058 public:
00059 ref_counted()
00060 :
00061 m_ref_count(0)
00062 {
00063 }
00064
00065 ref_counted(const ref_counted&)
00066 :
00067 m_ref_count(0)
00068 {
00069 }
00070
00071 void add_ref() const
00072 {
00073 assert(m_ref_count >= 0);
00074 ++m_ref_count;
00075 }
00076
00077 void drop_ref() const
00078 {
00079 assert(m_ref_count > 0);
00080 if (!--m_ref_count)
00081 {
00082
00083 delete this;
00084 }
00085 }
00086
00087 long get_ref_count() const { return m_ref_count; }
00088 };
00089
00090 }
00091
00092 #endif // GNASH_REF_COUNTED_H