/////////////////////////////////////////////////////////////////////////////
-// Name: wx/mac/corefoundation/cfref.h
+// Name: wx/osx/core/cfref.h
// Purpose: wxCFRef template class
// Author: David Elliott <dfe@cox.net>
// Modified by: Stefan Csomor
// Licence: wxWindows licence
// Notes: See http://developer.apple.com/documentation/CoreFoundation/Conceptual/CFMemoryMgmt/index.html
/////////////////////////////////////////////////////////////////////////////
-/*! @header wx/mac/corefoundation/cfref.h
+/*! @header wx/osx/core/cfref.h
@abstract wxCFRef template class
@discussion FIXME: Convert doc tags to something less buggy with C++
*/
@param p The raw pointer to assume ownership of. May be NULL.
@discussion Like shared_ptr, it is assumed that the caller has a strong reference to p and intends
to transfer ownership of that reference to this ref holder. If the object comes from
- a Create or Copy method then this is the correct behavior. If the object comes from
+ a Create or Copy method then this is the correct behaviour. If the object comes from
a Get method then you must CFRetain it yourself before passing it to this constructor.
A handy way to do this is to use the non-member wxCFRefFromGet factory funcion.
This method is templated and takes an otherType *p. This prevents implicit conversion
*/
wxCFRef& operator=(const wxCFRef& otherRef)
{
- wxCFRetain(otherRef.m_ptr);
- wxCFRelease(m_ptr);
- m_ptr = otherRef.m_ptr;
+ if (this != &otherRef)
+ {
+ wxCFRetain(otherRef.m_ptr);
+ wxCFRelease(m_ptr);
+ m_ptr = otherRef.m_ptr;
+ }
return *this;
}
wxCFRelease(m_ptr);
m_ptr = p; // Automatic conversion should occur
}
+
+ // Release the pointer, i.e. give up its ownership.
+ refType release()
+ {
+ refType p = m_ptr;
+ m_ptr = NULL;
+ return p;
+ }
+
protected:
/*! @var m_ptr The raw pointer.
*/
}
/*! @function CFRelease
- @abstract Overloads CFRelease so that the user is warned of bad behavior.
+ @abstract Overloads CFRelease so that the user is warned of bad behaviour.
@discussion It is rarely appropriate to retain or release a wxCFRef. If one absolutely
must do it he can explicitly get() the raw pointer
Normally, this function is unimplemented resulting in a linker error if used.
inline void CFRelease(const wxCFRef<T*> & cfref) DEPRECATED_ATTRIBUTE;
/*! @function CFRetain
- @abstract Overloads CFRetain so that the user is warned of bad behavior.
+ @abstract Overloads CFRetain so that the user is warned of bad behaviour.
@discussion It is rarely appropriate to retain or release a wxCFRef. If one absolutely
must do it he can explicitly get() the raw pointer
Normally, this function is unimplemented resulting in a linker error if used.