]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/cocoa/ObjcAssociate.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/cocoa/ObjcAssociate.h
3 // Purpose: Associates an Objective-C class with a C++ class
4 // Author: David Elliott
7 // Copyright: (c) 2002 David Elliott <dfe@cox.net>
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef __WX_COCOA_OBJC_ASSOCIATE_H__
12 #define __WX_COCOA_OBJC_ASSOCIATE_H__
14 /*-------------------------------------------------------------------------
15 Basic hashmap stuff, used by everything
16 -------------------------------------------------------------------------*/
17 #define WX_DECLARE_OBJC_HASHMAP(ObjcClass) \
18 class wxCocoa##ObjcClass; \
19 WX_DECLARE_HASH_MAP(WX_##ObjcClass,wxCocoa##ObjcClass*,wxPointerHash,wxPointerEqual,wxCocoa##ObjcClass##Hash)
21 #define WX_DECLARE_OBJC_INTERFACE_HASHMAP(ObjcClass) \
23 static inline wxCocoa##ObjcClass* GetFromCocoa(WX_##ObjcClass cocoaObjcClass) \
25 wxCocoa##ObjcClass##Hash::iterator iter = sm_cocoaHash.find(cocoaObjcClass); \
26 if(iter!=sm_cocoaHash.end()) \
28 return iter->second; \
33 static wxCocoa##ObjcClass##Hash sm_cocoaHash;
35 #define WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(ObjcClass) \
36 wxCocoa##ObjcClass##Hash wxCocoa##ObjcClass::sm_cocoaHash;
39 /*-------------------------------------------------------------------------
40 The entire interface, including some boilerplate stuff
41 -------------------------------------------------------------------------*/
42 #define WX_DECLARE_OBJC_INTERFACE(ObjcClass) \
43 WX_DECLARE_OBJC_INTERFACE_HASHMAP(ObjcClass) \
45 inline void Associate##ObjcClass(WX_##ObjcClass cocoaObjcClass) \
48 sm_cocoaHash.insert(wxCocoa##ObjcClass##Hash::value_type(cocoaObjcClass,this)); \
50 inline void Disassociate##ObjcClass(WX_##ObjcClass cocoaObjcClass) \
53 sm_cocoaHash.erase(cocoaObjcClass); \
56 #define WX_IMPLEMENT_OBJC_INTERFACE(ObjcClass) \
57 WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(ObjcClass)
59 /*-------------------------------------------------------------------------
60 Stuff to be used by the wxWidgets class (not the Cocoa interface)
61 -------------------------------------------------------------------------*/
62 #define WX_DECLARE_COCOA_OWNER(ObjcClass,ObjcBase,ObjcRoot) \
64 inline WX_##ObjcClass Get##ObjcClass() { return (WX_##ObjcClass)m_cocoa##ObjcRoot; } \
65 inline const WX_##ObjcClass Get##ObjcClass() const { return (WX_##ObjcClass)m_cocoa##ObjcRoot; } \
67 void Set##ObjcClass(WX_##ObjcClass cocoaObjcClass);
69 #define WX_IMPLEMENT_COCOA_OWNER(wxClass,ObjcClass,ObjcBase,ObjcRoot) \
70 void wxClass::Set##ObjcClass(WX_##ObjcClass cocoaObjcClass) \
72 Disassociate##ObjcClass((WX_##ObjcClass)m_cocoa##ObjcRoot); \
73 Set##ObjcBase(cocoaObjcClass); \
74 Associate##ObjcClass((WX_##ObjcClass)m_cocoa##ObjcRoot); \
77 #endif // __WX_COCOA_OBJC_ASSOCIATE_H__