Nui
Loading...
Searching...
No Matches
nui
src
nui
backend
mac_helpers
class.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include "
mac_includes.hpp
"
4
#include "
type_encodings.hpp
"
5
6
namespace
Nui::MacOs
7
{
8
template
<
typename
T>
9
class
ClassWrapper
10
{
11
public
:
12
static
auto
createInstance
(std::string
const
& name)
13
{
14
auto
cls = objc_getClass(name.c_str());
15
auto
inst = class_createInstance(cls,
sizeof
(T)
/* - sizeof(Class)?*/
);
16
// here or offset by sizeof(Class)?
17
new
(inst) T(cls);
18
return
inst;
19
}
20
21
static
auto
createNsObjectClassPair
(std::string
const
& name)
22
{
23
return
ClassWrapper<T>
{objc_allocateClassPair(
reinterpret_cast<
Class
>
(
"NSObject"
_cls), name.c_str(), 0)};
24
}
25
26
Class
native
() const noexcept
27
{
28
return
m_class;
29
}
30
31
ClassWrapper
(Class cls)
32
: m_class{cls}
33
{}
34
35
void
addProtocol
(std::string
const
& name)
36
{
37
class_addProtocol(m_class, objc_getProtocol(name.c_str()));
38
}
39
40
void
registerClassPair
()
41
{
42
objc_registerClassPair(m_class);
43
}
44
45
template
<
typename
FunctionT>
46
void
addMethod
(std::string
const
& name, FunctionT func)
47
{
48
class_addMethod(
49
m_class, sel_registerName(name.c_str()),
reinterpret_cast<
IMP
>
(func), encodeType<FunctionT>().c_str());
50
}
51
52
private
:
53
Class m_class;
54
};
55
}
Nui::MacOs::ClassWrapper
Definition
class.hpp:10
Nui::MacOs::ClassWrapper::addProtocol
void addProtocol(std::string const &name)
Definition
class.hpp:35
Nui::MacOs::ClassWrapper::createInstance
static auto createInstance(std::string const &name)
Definition
class.hpp:12
Nui::MacOs::ClassWrapper::createNsObjectClassPair
static auto createNsObjectClassPair(std::string const &name)
Definition
class.hpp:21
Nui::MacOs::ClassWrapper::addMethod
void addMethod(std::string const &name, FunctionT func)
Definition
class.hpp:46
Nui::MacOs::ClassWrapper::native
Class native() const noexcept
Definition
class.hpp:26
Nui::MacOs::ClassWrapper::registerClassPair
void registerClassPair()
Definition
class.hpp:40
Nui::MacOs::ClassWrapper::ClassWrapper
ClassWrapper(Class cls)
Definition
class.hpp:31
mac_includes.hpp
Nui::MacOs
Definition
class.hpp:7
type_encodings.hpp
Generated by
1.9.8