-
template
class
PortableRef<class Item>
(Return to index)
-
This class implements reference counting on any object or arrayyou give it, so that your object will be automatically deleted when your last reference to it goes away.
Type:
Include file:
../../refcount/PortableRefCount.h
Synopsis:
Public methods:
- public uint32
GetItemCount () const
Returns the number of items in the array we are tracking (i.e.
one if we are tracking just a single object)
- public Item *
GetItemPointer () const
Returns the ref-counted data. Please don't hold on to the
returned pointer as it is only guaranteed valid as long as this
PortableRef object exists.
- public typedef ObjectPool<Item>
ItemPool
- public
PortableRef ()
Creates a NULL reference (suitable for initializing with the = operator)
- public
PortableRef (PortableRef & copyMe)
Creates a new reference-count for the given item.
Once this reference count has been created, (item) will be automatically
deleted when the last PortableRef that references it has dissappeared.
Note that it is an error to call this constructor twice with the same (item).
To obtain additional tracked references to (item), use PortableRef's copy
constructor, or the PortableRef equals operator.
(refPool) may be NULL, or if you wish to be more efficient, it may point to a RefPool
that you are using to recycle ref-count memory for this PortableRef class. (Note that
the calling code retains ownership of the RefPool object)
(itemPool) may be NULL, or if you wish to be more efficient, it may point to a ItemPool
that you are using to recycle your (item)s. (Note that
the calling code retains ownership of the ItemPool object)
If (item) is a pointer to a single item, and not an array of items, then
the default value of one is appropriate.
(numItems) is the number of (Item) objects that (item) points to. In general,
this will be one, but for arrays it might be more.
If (doRefCounting) is set false, then (item) will NOT be deleted automatically.
It then remains the responsibility of the calling code to delete it. (This is useful
if e.g. you need to put a non-new'd item into a PortableRef, and want to
handle the cleanup issues yourself)
Usage example
Create an additional reference to the object specified by (copyMe)
- public class
RefCountMem
- public typedef ObjectPool<RefCountMem>
RefPool
type of an ObjectPool of our internal data structures
- public void
Reset ()
Convenience method: Turns this object back into a NULL reference.
(same as *this = PortableRef();)
- public int
operator == (const PortableRef &rhs) const
Returns true iff both PortableRefs are referencing the same data
- public PortableRef &
operator= (const PortableRef &r)
Unreferences the old held data, and references the new.
- public
~PortableRef ()
Unreferences the held data