#include <OTC/collctn/baseactn.hh> template<class T> class OTC_BaseActions {
public:
inline static T const& add(T const& theItem);
inline static void remove(T&);
static T const& add(T const& theItem);
static void remove(T&);
};
T
is a pointer to a class
derived from OTC_Resource
the actions may increment and
decrement the reference count.
EX_Foo
is derived
from OTC_Resource
.
class OTC_BaseActions<EX_Foo*>
{
public:
EX_Foo* add(EX_Foo* theItem)
{
OTCLIB_ENSURE((theItem != 0),
"OTC_BaseActions<EX_Foo*>::add() - invalid pointer");
theItem->reference();
return theItem;
}
void remove(EX_Foo* theItem)
{ theItem->unReference(); }
};
If the type is a pointer, you may simplify the arguments and
return type to that shown above. If T
is a class object, the
prototype of your add()
and remove()
functions must match
exactly, those shown in the class definition below.
If you need to prevent a null pointer being placed into a
collection, you should include a condition check in the add()
function.
inline static T const& add(T const& theItem);
inline static void remove(T&);
OTC_Bucket