Foundation: add CFRelease_delete and CFType
Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
parent
57d8dbbd97
commit
0ac23b91ce
41
include/MacStd/Foundation.hpp
Normal file
41
include/MacStd/Foundation.hpp
Normal 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>;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user