Foundation: add CFRelease_delete and CFType

Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
Simon Rozman 2024-09-12 16:54:29 +02:00
parent 57d8dbbd97
commit 0ac23b91ce

View File

@ -0,0 +1,41 @@
/*
SPDX-License-Identifier: MIT
Copyright © 2023-2024 Amebis
*/
#pragma once
#include "common.hpp"
#import <Foundation/Foundation.h>
#include <memory>
namespace macstd {
///
/// Deleter for unique_ptr using CFRelease
///
struct CFRelease_delete
{
///
/// Default constructor
///
CFRelease_delete() noexcept {}
///
/// Delete a pointer
///
/// \sa [CFRelease function](https://developer.apple.com/documentation/corefoundation/1521153-cfrelease)
///
template <class _T>
void operator()(_T *_Ptr) const
{
CFRelease(_Ptr);
}
};
///
/// CFType helper
///
/// \sa [CFType](https://developer.apple.com/documentation/corefoundation/cftype)
template <class T>
using CFType = std::unique_ptr<T, CFRelease_delete>;
}