-
Notifications
You must be signed in to change notification settings - Fork 2
/
NSObjectCPPProxy.hpp
68 lines (55 loc) · 1.35 KB
/
NSObjectCPPProxy.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//
// RealGPUSpectrogramBridge.hpp
// audio_test
//
// Created by Alex on 25.04.2020.
// Copyright © 2020 Alex. All rights reserved.
//
#ifndef object_hpp
#define object_hpp
#include <stdio.h>
#include <CoreFoundation/CoreFoundation.h>
class NSObjectCPPProxy
{
public:
const void* GetPtr() const { return ptr; }
inline operator bool() const { return ptr != nullptr; }
protected:
NSObjectCPPProxy(): ptr(nullptr){}
NSObjectCPPProxy(const void* ptr): ptr(ptr) {
if (ptr)
CFRetain(ptr);
}
NSObjectCPPProxy(const NSObjectCPPProxy& rhs): ptr(rhs.ptr) {
if (ptr)
CFRetain(ptr);
}
NSObjectCPPProxy(NSObjectCPPProxy&& rhs): ptr(rhs.ptr){
rhs.ptr = nullptr;
}
virtual ~NSObjectCPPProxy() {
if (ptr)
CFRelease(ptr);
}
NSObjectCPPProxy& operator=(const NSObjectCPPProxy& rhs) {
if (rhs.ptr == ptr)
return *this;
if (rhs.ptr)
CFRetain(rhs.ptr);
if (ptr)
CFRelease(ptr);
ptr = rhs.ptr;
return *this;
}
NSObjectCPPProxy& operator=(NSObjectCPPProxy&& rhs) {
if (rhs.ptr == ptr)
return *this;
if (ptr)
CFRelease(ptr);
ptr = rhs.ptr;
rhs.ptr = nullptr;
return *this;
}
const void* ptr = nullptr;
};
#endif