aboutsummaryrefslogtreecommitdiff
path: root/include/cru/base/Osx.h
blob: 711da9a3ef3ccea40db9fbca6b20657f01f512f8 (plain)
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
#pragma once

#ifndef CRU_PLATFORM_OSX
#error "This header can only be included on OSX."
#endif

#include <CoreFoundation/CoreFoundation.h>

namespace cru {
template <typename CFClassRef>
class CFWrapper {
 public:
  CFClassRef ref;

  explicit CFWrapper(CFClassRef ref) { this->ref = ref; }
  ~CFWrapper() {
    if (this->ref) CFRelease(this->ref);
  }

  CFClassRef* release() {
    auto ref = this->ref;
    this->ref = nullptr;
    return ref;
  }
};
}  // namespace cru