//************************************************************************************** // Filename: CFObjDel.h // Part of Contextual Menu Workshop by Abracode Inc. // http://free.abracode.com/cmworkshop/ // Copyright © 2002-2003 Abracode, Inc. All rights reserved. // // Description: // //************************************************************************************** // Revision History: // Friday, January 25, 2002 - Original //************************************************************************************** #pragma once class CFObjDel { public: CFObjDel() { mRef = NULL; } CFObjDel(CFTypeRef inRef) { mRef = inRef; } virtual ~CFObjDel() { Dispose(); } //renamed to avoid confusion CFTypeRef Detach() { CFTypeRef outRef = mRef; mRef = NULL; return outRef; } void Dispose() { if(mRef != NULL) { ::CFRelease(mRef); mRef = NULL; } } void Adopt(CFTypeRef inRef) { if(mRef == inRef) return; Dispose(); mRef = inRef; } //adopt with retaining void Retain(CFTypeRef inRef) { if(mRef != inRef) { Dispose(); } mRef = inRef; if(mRef != NULL) ::CFRetain(mRef); } protected: CFTypeRef mRef; private: CFObjDel(const CFObjDel&); CFObjDel& operator=(const CFObjDel&); };