/cfref_ptr

shared_ptr for CoreFoundation types (CFTypeRef)

Primary LanguageC++MIT LicenseMIT

cfref_ptr

RAII for CFTypeRef.

build status

Build Status

example

#include <CoreFoundation/CoreFoundation.h>
#include "cfref_ptr.hpp"

// c++ -std=c++14 -framework CoreFoundation example.cpp -o example

int main() {
    cfref_ptr<CFStringRef> str = CFStringCreateWithCString(kCFAllocatorDefault,
                                                           "test",
                                                           kCFStringEncodingUTF8);
    CFShow(str.get());

    cfref_ptr<CFStringRef> copy = str;

    // `str` is still valid here, because the copy operator behaves like `std::shared_ptr`
    CFShow(str.get());
    CFShow(copy.get());

    // We need not to call CFRelease for `str` and `copy` here.
}

license

MIT