Nui
helpers.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "mac_includes.hpp"
4 
5 namespace Nui::MacOs
6 {
7  template <typename Result, typename Callable, typename... Args>
8  Result invoke(Callable callable, Args... args) noexcept
9  {
10  return reinterpret_cast<Result (*)(Args...)>(callable)(args...);
11  }
12 
13  // Calls objc_msgSend.
14  template <typename Result, typename... Args>
15  Result msg_send(Args... args) noexcept
16  {
17  return invoke<Result>(objc_msgSend, args...);
18  }
19 
20  inline id operator"" _cls(const char* s, std::size_t)
21  {
22  return reinterpret_cast<id>(objc_getClass(s));
23  }
24  inline SEL operator"" _sel(const char* s, std::size_t)
25  {
26  return sel_registerName(s);
27  }
28  inline id operator"" _str(const char* s, std::size_t)
29  {
30  return msg_send<id>("NSString"_cls, "stringWithUTF8String:"_sel, s);
31  }
32 }
Definition: class.hpp:7
Result msg_send(Args... args) noexcept
Definition: helpers.hpp:15
Result invoke(Callable callable, Args... args) noexcept
Definition: helpers.hpp:8