00001 #ifndef _REFERENCE_COUNTED_H_ 00002 #define _REFERENCE_COUNTED_H_ 00003 00005 00011 class ReferenceCounted 00012 { 00013 private: 00014 int ref_count_; 00015 00016 public: 00018 ReferenceCounted() 00019 { 00020 ref_count_ = 0; 00021 } 00022 00024 virtual ~ReferenceCounted() 00025 { 00026 } 00027 00029 inline void inc_ref() 00030 { 00031 ref_count_++; 00032 } 00033 00035 00039 inline void dec_ref() 00040 { 00041 ref_count_--; 00042 if (ref_count_ <= 0) 00043 delete this; 00044 } 00045 00047 inline int get_ref_count() 00048 { 00049 return ref_count_; 00050 } 00051 }; 00052 00053 #endif /* _REFERENCE_COUNTED_H_ */