divyang4481 / firebreath

Automatically exported from code.google.com/p/firebreath
0 stars 0 forks source link

Need an AutoPtr template class that supports reference counting #4

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
We need a simple, template-driven auto pointer class that supports
reference counting.

i.e.

template <class T>
class AutoPtr
{
...
}

It needs to:
- Contain a protected member of type T*
- Overload the * and -> pointer operators to allow access through to the
encapsulated T*
- Support reference counting (see below)
- Contain a copy constructor
- overload the = assignment operator (both to assign a T* and a AutoPtr<T>)
- Allow a NULL value to be assigned to it without crashing

Reference Counting:
When a pointer value is loaded, call addRef() on that pointer
when the autoptr is done with it, call release()

be sure that if you assign a different pointer value to an existing
autoptr, we call addRef on the new one *before* calling release() on the old.

If NULL is assigned to it, don't try to call anything on the NULL value,
but still release the old one (if needed)

Original issue reported on code.google.com by taxilian on 21 Sep 2009 at 4:05

GoogleCodeExporter commented 8 years ago

Original comment by kc7...@gmail.com on 21 Sep 2009 at 4:11

GoogleCodeExporter commented 8 years ago

Original comment by kc7...@gmail.com on 27 Sep 2009 at 3:48

GoogleCodeExporter commented 8 years ago
I'm reopening this; one of us needs to make the change we discussed the other
night,and consolidate all reference counting into a single "assign" function 
that is
used from all other parts of the class when an assignment is made (even 
destructor;
assign(NULL) )

Original comment by taxilian on 29 Sep 2009 at 3:10

GoogleCodeExporter commented 8 years ago
Made changes are per taxilian comment.

Original comment by kc7...@gmail.com on 1 Oct 2009 at 9:43