A template class that can be used to implement reference counting.
A template class that can be used to implement reference counting.Example:
class TestClassData { public: int type, id; }; class TestClass { public: TestClass(const TestClass& V) { // copy constructor ref = V.ref; } int GetType() { return ref.GetData().type; } int GetID() { return ref.GetData().id; } protected: TRefCounter<TestClassData> ref; };In this example TestClass reference counts TestClassData. It is very plausible (and in fact very simple), for a class to referece count multiple data classes. Just use two or more TRefCounter members and copy them in the copy constructor.Template arguments:
- ref_data The actual object to be reference counted
- CreateData A functor that takes one argument, a ref_data. This should be used to perform any initialization required by the object. While in most cases, you can pack the all of this into the ref_data's constructor/destructor, that is impossible if ref_data is an abstract class. (Optional)
- DestroyData A functor that takes one argument, a ref_data object. This can be used to perform any clean up required by the ref_data object. This is helpful if ref_data is a dynamically allocated object and needs to have its memory freed. (Optional)
RefCounterObject = RefDataObject
will actually assign to the ref data stored in the RefCounterObject.
Alphabetic index HTML hierarchy of classes or Java