-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathObject.h
More file actions
162 lines (125 loc) · 4.54 KB
/
Object.h
File metadata and controls
162 lines (125 loc) · 4.54 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#pragma once
#include <CoreFoundation/CFBase.h>
#include <IOKit/IOKitLib.h>
#include "MemBuffer.h"
NS_BEGIN
//#################################################################################################
class CCFObject final
{
public:
CCFObject(void);
CCFObject(const CCFObject &src);
CCFObject(CCFObject &&src) noexcept;
CCFObject(const CFTypeRef cf, const bool bAutoRelease = true);
~CCFObject(void);
bool IsValid(void) const noexcept;
void Release(void);
CCFObject &Attach(const CFTypeRef cf, const bool bAutoRelease = true);
CFTypeRef Detach(bool *pbAutoRelease = nullptr) noexcept;
operator CFTypeRef(void) const noexcept;
CFTypeRef Get(void) const noexcept;
CFTypeRef &Receive(const bool bAutoRelease = true) noexcept; // A form of 'Get' which allows the underlying CFTypeRef be set
CCFObject &operator=(const CCFObject &src);
CCFObject &operator=(CCFObject &&src) noexcept;
CFTypeID GetType(void) const;
bool GetBoolean(const bool bDefault = false) const;
int64_t GetInteger(const int64_t nDefault = 0) const;
CStr GetString(PCSTR szDefault = nullptr) const;
CMemBuffer GetData(void) const;
size_t GetArrayCount(void) const;
CCFObject GetArrayObject(const size_t nIndex) const;
CCFObject GetDictionaryEx(PCSTR szProperty) const;
bool GetDictionaryBooleanEx(PCSTR szProperty, const bool bDefault = false) const;
int64_t GetDictionaryIntegerEx(PCSTR szProperty, const int64_t nDefault = 0) const;
CStr GetDictionaryStringEx(PCSTR szProperty, PCSTR szDefault = nullptr) const;
CMemBuffer GetDictionaryDataEx(PCSTR szProperty) const;
//#########################################################################
template<typename T>
CCFObject GetDictionary(T&& cfProperty) const
{
CCFObject cf;
if(GetType() == CFDictionaryGetTypeID())
cf.Attach(CFDictionaryGetValue((CFDictionaryRef)m_cf, cfProperty), false);
return cf;
}
//#########################################################################
template<typename T>
bool GetDictionaryBoolean(T&& cfProperty, const bool bDefault = false) const
{
bool b = bDefault;
if(GetType() == CFDictionaryGetTypeID())
{
CCFObject cfValue(CFDictionaryGetValue((CFDictionaryRef)m_cf, cfProperty), false);
b = cfValue.GetBoolean();
}
return b;
}
//#########################################################################
template<typename T>
int64_t GetDictionaryInteger(T&& cfProperty, const int64_t nDefault = 0) const
{
int64_t n = nDefault;
if(GetType() == CFDictionaryGetTypeID())
{
CCFObject cfValue(CFDictionaryGetValue((CFDictionaryRef)m_cf, cfProperty), false);
n = cfValue.GetInteger();
}
return n;
}
//#########################################################################
template<typename T>
CStr GetDictionaryString(T&& cfProperty, PCSTR szDefault = nullptr) const
{
CStr str(szDefault);
if(GetType() == CFDictionaryGetTypeID())
{
CCFObject cfValue(CFDictionaryGetValue((CFDictionaryRef)m_cf, cfProperty), false);
str = cfValue.GetString();
}
return str;
}
//#########################################################################
template<typename T>
CMemBuffer GetDictionaryData(T&& cfProperty) const
{
CMemBuffer buf;
if(GetType() == CFDictionaryGetTypeID())
{
CCFObject cfValue(CFDictionaryGetValue((CFDictionaryRef)m_cf, cfProperty), false);
buf = cfValue.GetData();
}
return buf;
}
//#########################################################################
template<typename T, typename ...ARGS>
static CCFObject CreateWithFormat(T&& cfFormat, const ARGS&... args)
{
return CFStringCreateWithFormat(nullptr, nullptr, cfFormat, args...);
}
private:
CFTypeRef m_cf;
bool m_bAutoRelease;
};
//#################################################################################################
class CIOObject final
{
public:
CIOObject(void);
CIOObject(const CIOObject &src);
CIOObject(CIOObject &&src) noexcept;
CIOObject(const io_object_t io);
~CIOObject(void);
bool IsValid(void) const noexcept;
void Release(void);
CIOObject &Attach(io_object_t io);
io_object_t Detach(void) noexcept;
operator io_object_t(void) const noexcept;
io_object_t Get(void) const noexcept;
io_object_t &Receive(void) noexcept; // A form of 'Get' which allows the underlying io_object_t be set
CIOObject &operator=(const CIOObject &src);
CIOObject &operator=(CIOObject &&src) noexcept;
CStr GetName(void) const;
private:
io_object_t m_io;
};
NS_END