33a34,44
> /**
> * @file base/refcnt.hh
> *
> * Classes for managing reference counted objects.
> */
>
> /**
> * Derive from RefCounted if you want to enable reference counting of
> * this class. If you want to use automatic reference counting, you
> * should use RefCountingPtr<T> instead of regular pointers.
> */
36a48,51
> // The reference count is mutable because one may want to
> // reference count a const pointer. This really is OK because
> // const is about logical constness of the object not really about
> // strictly disallowing an object to change.
46a62,68
> /**
> * We initialize the reference count to zero and the first object
> * to take ownership of it must increment it to one.
> *
> * @attention A memory leak will occur if you never assign a newly
> * constructed object to a reference counting pointer.
> */
47a70,79
>
> /**
> * We make the destructor virtual because we're likely to have
> * virtual functions on reference counted objects.
> *
> * @todo Even if this were true, does it matter? Shouldn't the
> * derived class indicate this? This only matters if we would
> * ever choose to delete a "RefCounted *" which I doubt we'd ever
> * do. We don't ever delete a "void *".
> */
49a82
> /// Increment the reference count
50a84,86
>
> /// Decrement the reference count and destroy the object if all
> /// references are gone.
53a90,104
> /**
> * If you want a reference counting pointer to a mutable object,
> * create it like this:
> * @code
> * typedef RefCountingPtr<Foo> FooPtr;
> * @endcode
> *
> * @attention Do not use "const FooPtr"
> * To create a reference counting pointer to a const object, use this:
> * @code
> * typedef RefCountingPtr<const Foo> ConstFooPtr;
> * @endcode
> *
> * These two usages are analogous to iterator and const_iterator in the stl.
> */
57a109,110
> /// The stored pointer.
> /// Arguably this should be private.
60c113,120
< void copy(T *d)
---
> /**
> * Copy a new pointer value and increment the reference count if
> * it is a valid pointer. Note, this does not delete the
> * reference any existing object.
> * @param d Pointer to store.
> */
> void
> copy(T *d)
66c126,133
< void del()
---
>
> /**
> * Delete the reference to any existing object if it is non NULL.
> * @attention this doesn't clear the pointer value, so a double
> * decref could happen if not careful.
> */
> void
> del()
71,74d137
< void set(T *d)
< {
< if (data == d)
< return;
76,77c139,151
< del();
< copy(d);
---
> /**
> * Drop the old reference and change it to something new.
> */
> void
> set(T *d)
> {
> // Need to check if we're actually changing because otherwise
> // we could delete the last reference before adding the new
> // reference.
> if (data != d) {
> del();
> copy(d);
> }
80d153
<
81a155
> /// Create an empty reference counting pointer.
82a157,159
>
> /// Create a new reference counting pointer to some object
> /// (probably something newly created). Adds a reference.
83a161,163
>
> /// Create a new reference counting pointer by copying another
> /// one. Adds a reference.
84a165,166
>
> /// Destroy the pointer and any reference it may hold.
86a169,173
> // The following pointer access functions are const because they
> // don't actually change the pointer, though the user could change
> // what is pointed to. This is analagous to a "Foo * const".
>
> /// Access a member variable.
87a175,176
>
> /// Dereference the pointer.
88a178,179
>
> /// Directly access the pointer itself without taking a reference.
90a182
> /// Assign a new value to the pointer
91a184,185
>
> /// Copy the pointer from another RefCountingPtr
94a189
> /// Check if the pointer is empty
95a191,192
>
> /// Check if the pointer is non-empty
98a196
> /// Check for equality of two reference counting pointers.
102a201,202
> /// Check for equality of of a reference counting pointers and a
> /// regular pointer
106a207,208
> /// Check for equality of of a reference counting pointers and a
> /// regular pointer
110a213
> /// Check for inequality of two reference counting pointers.
114a218,219
> /// Check for inequality of of a reference counting pointers and a
> /// regular pointer
118a224,225
> /// Check for inequality of of a reference counting pointers and a
> /// regular pointer