8#ifndef SkCFObject_DEFINED
9#define SkCFObject_DEFINED
17#import <CoreFoundation/CoreFoundation.h>
24template <
typename T>
static inline T SkCFSafeRetain(
T obj) {
31template <
typename T>
static inline void SkCFSafeRelease(
T obj) {
37template <
typename T>
class sk_cfp {
39 using element_type =
T;
42 constexpr sk_cfp(std::nullptr_t) {}
48 sk_cfp(
const sk_cfp<T>& that) : fObject(SkCFSafeRetain(that.
get())) {}
55 sk_cfp(sk_cfp<T>&& that) : fObject(that.release()) {}
61 explicit sk_cfp(
T obj) {
69 SkCFSafeRelease(fObject);
73 sk_cfp<T>& operator=(std::nullptr_t) { this->
reset();
return *
this; }
80 sk_cfp<T>& operator=(
const sk_cfp<T>& that) {
82 this->
reset(SkCFSafeRetain(that.get()));
92 sk_cfp<T>& operator=(sk_cfp<T>&& that) {
93 this->
reset(that.release());
97 explicit operator bool()
const {
return this->
get() != nil; }
99 T get()
const {
return fObject; }
109 void reset(
T object = nil) {
113 T oldObject = fObject;
115 SkCFSafeRelease(oldObject);
122 void retain(
T object) {
123 if (fObject !=
object) {
124 this->
reset(SkCFSafeRetain(
object));
133 [[nodiscard]]
T release() {
143template <
typename T>
inline bool operator==(
const sk_cfp<T>&
a,
144 const sk_cfp<T>&
b) {
145 return a.get() ==
b.get();
147template <
typename T>
inline bool operator==(
const sk_cfp<T>&
a,
151template <
typename T>
inline bool operator==(std::nullptr_t,
152 const sk_cfp<T>&
b) {
156template <
typename T>
inline bool operator!=(
const sk_cfp<T>&
a,
157 const sk_cfp<T>&
b) {
158 return a.get() !=
b.get();
160template <
typename T>
inline bool operator!=(
const sk_cfp<T>&
a,
162 return static_cast<bool>(
a);
164template <
typename T>
inline bool operator!=(std::nullptr_t,
165 const sk_cfp<T>&
b) {
166 return static_cast<bool>(
b);
175template <
typename T> sk_cfp<T> sk_ret_cfp(
T obj) {
176 return sk_cfp<T>(SkCFSafeRetain(obj));
SkDEBUGCODE(SK_SPI) SkThreadID SkGetThreadID()
bool operator==(C p1, const scoped_nsprotocol< C > &p2)
bool operator!=(C p1, const scoped_nsprotocol< C > &p2)
constexpr Color operator*(T value, const Color &c)
const myers::Point & get(const myers::Segment &)