Many of my c++ objects implement rerfrence counting through AddRef and FreeRef methods. If FreeRef reduces the refrence count to 0 then the object deletes its self.
All methods which return a refrence counted object dont increment the refrence. This makes it simple since a smart pointer can then simply increment the count apon recieving a pointer and decrement the count when they no longer refrence it. eg:
template<class T> FlPtr
{
T *p;
public:
FlPtr(T *p=0):p(p){if(p)p->AddRef();}
~FlPtr(){if(p)p->FreeRef();}
FlPtr<T>& operator =(T *newP)
{
if(newP)newP->AddRef();
if(p)p->FreeRef();
p = newP;
return *this;
}
operator T*(){return p;}
};
I was thinking mayby if I could tell SWIG to just use my existing smart pointer internally for these objects that may work however im not sure how to do that either :(