aboutsummaryrefslogtreecommitdiff
path: root/include/cru/base/Osx.h
blob: 6c6d5109fb02a136c2a27b80e7448ba410b4d5ef (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
27
28
29
30
31
32
33
34
35
36
37
38
#pragma once

// TODO: Move This file to platform dir.

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

#include "Range.h"
#include "String.h"

#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;
  }
};

// TODO: Remove "Ref" in name.
CFWrapper<CFStringRef> ToCFStringRef(StringView string);
String FromCFStringRef(CFStringRef string);

CFRange ToCFRange(const Range& range);
Range FromCFRange(const CFRange& range);
}  // namespace cru