diff options
Diffstat (limited to 'platform/darwin/src/CFHandle.hpp')
-rw-r--r-- | platform/darwin/src/CFHandle.hpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/platform/darwin/src/CFHandle.hpp b/platform/darwin/src/CFHandle.hpp new file mode 100644 index 0000000000..b87b8c696f --- /dev/null +++ b/platform/darwin/src/CFHandle.hpp @@ -0,0 +1,27 @@ + +namespace { + +template <typename T, typename S, void (*Releaser)(S)> +struct CFHandle { + CFHandle(T t_): t(t_) {} + ~CFHandle() { Releaser(t); } + T operator*() { return t; } + operator bool() { return t; } +private: + T t; +}; + +using CGImageHandle = CFHandle<CGImageRef, CGImageRef, CGImageRelease>; +using CFDataHandle = CFHandle<CFDataRef, CFTypeRef, CFRelease>; +using CGImageSourceHandle = CFHandle<CGImageSourceRef, CFTypeRef, CFRelease>; +using CGDataProviderHandle = CFHandle<CGDataProviderRef, CGDataProviderRef, CGDataProviderRelease>; +using CGColorSpaceHandle = CFHandle<CGColorSpaceRef, CGColorSpaceRef, CGColorSpaceRelease>; +using CGContextHandle = CFHandle<CGContextRef, CGContextRef, CGContextRelease>; + +using CFStringRefHandle = CFHandle<CFStringRef, CFTypeRef, CFRelease>; +using CFAttributedStringRefHandle = CFHandle<CFAttributedStringRef, CFTypeRef, CFRelease>; +using CFDictionaryRefHandle = CFHandle<CFDictionaryRef, CFTypeRef, CFRelease>; + + +} // namespace + |