mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Objective-C++: Make getIvar() a free function so it can be used without a class instance
This commit is contained in:
parent
ddb59d1361
commit
d6a5156dd5
2 changed files with 11 additions and 11 deletions
|
|
@ -230,7 +230,7 @@ NSRect makeNSRect (const RectangleType& r) noexcept
|
|||
#endif
|
||||
|
||||
template <typename SuperType, typename ReturnType, typename... Params>
|
||||
static ReturnType ObjCMsgSendSuper (id self, SEL sel, Params... params)
|
||||
inline ReturnType ObjCMsgSendSuper (id self, SEL sel, Params... params)
|
||||
{
|
||||
using SuperFn = ReturnType (*) (struct objc_super*, SEL, Params...);
|
||||
const auto fn = reinterpret_cast<SuperFn> (MetaSuperFn<ReturnType>::value);
|
||||
|
|
@ -253,6 +253,14 @@ template <typename NSType>
|
|||
using NSUniquePtr = std::unique_ptr<NSType, NSObjectDeleter>;
|
||||
|
||||
//==============================================================================
|
||||
template <typename Type>
|
||||
inline Type getIvar (id self, const char* name)
|
||||
{
|
||||
void* v = nullptr;
|
||||
object_getInstanceVariable (self, name, &v);
|
||||
return static_cast<Type> (v);
|
||||
}
|
||||
|
||||
template <typename SuperclassType>
|
||||
struct ObjCClass
|
||||
{
|
||||
|
|
@ -323,14 +331,6 @@ struct ObjCClass
|
|||
return ObjCMsgSendSuper<SuperclassType, ReturnType, Params...> (self, sel, params...);
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
static Type getIvar (id self, const char* name)
|
||||
{
|
||||
void* v = nullptr;
|
||||
object_getInstanceVariable (self, name, &v);
|
||||
return static_cast<Type> (v);
|
||||
}
|
||||
|
||||
Class cls;
|
||||
|
||||
private:
|
||||
|
|
@ -402,7 +402,7 @@ NSObject* createNSObjectFromJuceClass (Class* obj)
|
|||
template <typename Class>
|
||||
Class* getJuceClassFromNSObject (NSObject* obj)
|
||||
{
|
||||
return obj != nullptr ? ObjCLifetimeManagedClass<Class>:: template getIvar<Class*> (obj, "cppObject") : nullptr;
|
||||
return obj != nullptr ? getIvar<Class*> (obj, "cppObject") : nullptr;
|
||||
}
|
||||
|
||||
template <typename ReturnT, class Class, typename... Params>
|
||||
|
|
|
|||
|
|
@ -1703,7 +1703,7 @@ struct NSViewComponentPeerWrapper : public Base
|
|||
|
||||
static NSViewComponentPeer* getOwner (id self)
|
||||
{
|
||||
return Base::template getIvar<NSViewComponentPeer*> (self, "owner");
|
||||
return getIvar<NSViewComponentPeer*> (self, "owner");
|
||||
}
|
||||
|
||||
static id getAccessibleChild (id self)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue