41 #if !defined(__CACFObject_h__)
42 #define __CACFObject_h__
48 #if !defined(__COREAUDIO_USE_FLAT_INCLUDES__)
49 #include <CoreAudio/CoreAudioTypes.h>
50 #include <CoreFoundation/CoreFoundation.h>
52 #include <CoreAudioTypes.h>
53 #include <CoreFoundation.h>
60 template <
class CFObjectType>
66 CACFObject() : mCFObject(NULL), mWillRelease(true) {}
67 CACFObject(CFObjectType inCFObject,
bool inWillRelease =
true) : mCFObject(inCFObject), mWillRelease(inWillRelease) {}
68 ~CACFObject() { Release(); }
69 CACFObject(
const CACFObject& inObject) : mCFObject(inObject.mCFObject), mWillRelease(inObject.mWillRelease) { Retain(); }
70 CACFObject& operator=(
const CACFObject& inObject) { Release(); mCFObject = inObject.mCFObject; mWillRelease = inObject.mWillRelease; Retain();
return *
this; }
71 CACFObject& operator=(CFObjectType inCFObject) { Release(); mCFObject = inCFObject; mWillRelease =
true;
return *
this; }
74 void Retain() {
if(mWillRelease && (mCFObject != NULL)) { CFRetain(mCFObject); } }
75 void Release() {
if(mWillRelease && (mCFObject != NULL)) { CFRelease(mCFObject); mCFObject = NULL; } }
77 CFObjectType mCFObject;
82 void AllowRelease() { mWillRelease =
true; }
83 void DontAllowRelease() { mWillRelease =
false; }
84 bool IsValid()
const {
return mCFObject != NULL; }
85 CFTypeID GetTypeID()
const {
return CFGetTypeID(mCFObject); }
86 bool IsEqual(CFObjectType inCFObject)
const {
return CFEqual(inCFObject, mCFObject) != 0; }
90 CFObjectType GetCFObject()
const {
return mCFObject; }
91 CFObjectType CopyCFObject()
const {
if(mCFObject != NULL) { CFRetain(mCFObject); }
return mCFObject; }
95 typedef CACFObject<CFBundleRef> CACFBundle;
96 typedef CACFObject<CFTypeRef> CACFType;
97 typedef CACFObject<CFUUIDRef> CACFUUID;
98 typedef CACFObject<CFURLRef> CACFURL;