Last active
December 26, 2015 17:59
-
-
Save phausler/7190603 to your computer and use it in GitHub Desktop.
CFType registration SublimeText snippet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<snippet> | |
<content><![CDATA[ | |
#include "CFBase.h" | |
#include "CFRuntime.h" | |
#include "${1:name}.h" | |
struct __${1:name} { | |
CFRuntimeBase _base; | |
}; | |
static void __${1:name}Deallocate(CFTypeRef cf) { | |
struct __${1:name} *item = (struct __${1:name} *)cf; | |
} | |
static CFTypeID __k${1:name}TypeID = _kCFRuntimeNotATypeID; | |
static const CFRuntimeClass __${1:name}Class = { | |
_kCFRuntimeScannedObject, | |
"${1:name}", | |
NULL, // init | |
NULL, // copy | |
__${1:name}Deallocate, | |
NULL, | |
NULL, | |
NULL, | |
NULL | |
}; | |
static void __${1:name}Initialize(void) { | |
__k${1:name}TypeID = _CFRuntimeRegisterClass(&__${1:name}Class); | |
} | |
CFTypeID ${1:name}GetTypeID(void) { | |
if (__k${1:name}TypeID == _kCFRuntimeNotATypeID) { | |
__${1:name}Initialize(); | |
} | |
return __k${1:name}TypeID; | |
} | |
static struct __${1:name} *_${1:name}Create(CFAllocatorRef allocator) { | |
CFIndex size = sizeof(struct __${1:name}) - sizeof(CFRuntimeBase); | |
return (struct __${1:name} *)_CFRuntimeCreateInstance(allocator, ${1:name}GetTypeID(), size, NULL); | |
} | |
]]></content> | |
<tabTrigger>cfobject</tabTrigger> | |
</snippet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment