comparison foosdk/sdk/pfc/CFObject.h @ 1:20d02a178406 default tip

*: check in everything else yay
author Paper <paper@tflc.us>
date Mon, 05 Jan 2026 02:15:46 -0500
parents
children
comparison
equal deleted inserted replaced
0:e9bb126753e7 1:20d02a178406
1 #pragma once
2
3 #include <CoreFoundation/CoreFoundation.h>
4
5 namespace pfc {
6 template<typename type_t = CFTypeRef>
7 class CFObject {
8 public:
9 typedef CFObject<type_t> self_t;
10 type_t p = NULL;
11
12 ~CFObject() {
13 if ( p ) CFRelease(p);
14 }
15
16 void Retain(type_t arg) {
17 if ( p ) CFRelease(p);
18 p = arg;
19 if ( p ) CFRetain(p);
20 }
21
22 void Attach(type_t arg) {
23 if ( p ) CFRelease(p);
24 p = arg;
25 }
26
27 void operator=( self_t const & arg ) {
28 if ( p ) CFRelease(p);
29 p = arg.p;
30 if ( p ) CFRetain(p);
31 }
32 CFObject() {}
33 CFObject( self_t const & arg ) {
34 p = arg.p;
35 if ( p ) CFRetain(p);
36 }
37
38 CFObject(self_t && arg ) {
39 p = arg.p; arg.p = NULL;
40 }
41 void operator=(self_t && arg) {
42 if ( p ) CFRelease(p);
43 p = arg.p; arg.p = NULL;
44 }
45
46 operator bool() const { return p != NULL; }
47 operator type_t() const { return p;}
48
49
50 void reset() {
51 if ( p ) CFRelease(p);
52 p = NULL;
53 }
54
55 void operator=(nullptr_t) {
56 reset();
57 }
58 };
59 }