aboutsummaryrefslogtreecommitdiff
path: root/include/cru/base/Osx.h
blob: e42a4fe534fce75eefef8f6c0a92613ffb06c3e4 (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 <CoreFoundation/CoreFoundation.h>
#include <string>
#include <string_view>

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

CFWrapper<CFStringRef> ToCFString(std::string_view string);
std::string FromCFStringRef(CFStringRef string);

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