-
Notifications
You must be signed in to change notification settings - Fork 11
/
utils.h
48 lines (35 loc) · 1.01 KB
/
utils.h
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
#pragma once
#include <Carbon/Carbon.h>
#include <CoreFoundation/CoreFoundation.h>
#include <string>
std::string stringFromCFString(CFStringRef cfStr);
void printInputSourceProperty(TISInputSourceRef inputSource, CFStringRef property);
class CFStringWrap {
public:
CFStringWrap(const std::string& str) {
_cfStr = CFStringCreateWithBytes(NULL, (const UInt8*)str.c_str(), str.length(), kCFStringEncodingUTF8, FALSE);
}
CFStringRef cfString() const { return _cfStr; }
~CFStringWrap() {
CFRelease(_cfStr);
_cfStr = NULL;
}
private:
CFStringRef _cfStr;
};
class CFDictionaryWrap {
public:
CFDictionaryWrap() {
_cfDict = CFDictionaryCreateMutable(NULL, 0, NULL, NULL);
}
CFMutableDictionaryRef cfDict() const { return _cfDict; }
void set(CFStringRef key, CFTypeRef val) {
CFDictionarySetValue(_cfDict, key, val);
}
~CFDictionaryWrap() {
CFRelease(_cfDict);
_cfDict = NULL;
}
private:
CFMutableDictionaryRef _cfDict;
};