]>
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
8 // Copyright: (c) 2002 David Elliott <dfe@cox.net>
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef __WX_COCOA_OBJC_ASSOCIATE_H__
13 #define __WX_COCOA_OBJC_ASSOCIATE_H__
15 /*-------------------------------------------------------------------------
16 Basic hashmap stuff, used by everything
17 -------------------------------------------------------------------------*/
18 #define WX_DECLARE_OBJC_HASHMAP(ObjcClass) \
19 class wxCocoa##ObjcClass; \
20 WX_DECLARE_HASH_MAP(WX_##ObjcClass,wxCocoa##ObjcClass*,wxPointerHash,wxPointerEqual,wxCocoa##ObjcClass##Hash)
22 #define WX_DECLARE_OBJC_INTERFACE_HASHMAP(ObjcClass) \
24 static inline wxCocoa##ObjcClass* GetFromCocoa(WX_##ObjcClass cocoaObjcClass) \
26 wxCocoa##ObjcClass##Hash::iterator iter = sm_cocoaHash.find(cocoaObjcClass); \
27 if(iter!=sm_cocoaHash.end()) \
29 return iter->second; \
34 static wxCocoa##ObjcClass##Hash sm_cocoaHash;
36 #define WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(ObjcClass) \
37 wxCocoa##ObjcClass##Hash wxCocoa##ObjcClass::sm_cocoaHash;
40 /*-------------------------------------------------------------------------
41 The entire interface, including some boilerplate stuff
42 -------------------------------------------------------------------------*/
43 #define WX_DECLARE_OBJC_INTERFACE(ObjcClass) \
44 WX_DECLARE_OBJC_INTERFACE_HASHMAP(ObjcClass) \
46 inline void Associate##ObjcClass(WX_##ObjcClass cocoaObjcClass) \
49 sm_cocoaHash.insert(wxCocoa##ObjcClass##Hash::value_type(cocoaObjcClass,this)); \
51 inline void Disassociate##ObjcClass(WX_##ObjcClass cocoaObjcClass) \
54 sm_cocoaHash.erase(cocoaObjcClass); \
57 #define WX_IMPLEMENT_OBJC_INTERFACE(ObjcClass) \
58 WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(ObjcClass)
60 /*-------------------------------------------------------------------------
61 Stuff to be used by the wxWidgets class (not the Cocoa interface)
62 -------------------------------------------------------------------------*/
63 #define WX_DECLARE_COCOA_OWNER(ObjcClass,ObjcBase,ObjcRoot) \
65 inline WX_##ObjcClass Get##ObjcClass() { return (WX_##ObjcClass)m_cocoa##ObjcRoot; } \
66 inline const WX_##ObjcClass Get##ObjcClass() const { return (WX_##ObjcClass)m_cocoa##ObjcRoot; } \
68 void Set##ObjcClass(WX_##ObjcClass cocoaObjcClass);
70 #define WX_IMPLEMENT_COCOA_OWNER(wxClass,ObjcClass,ObjcBase,ObjcRoot) \
71 void wxClass::Set##ObjcClass(WX_##ObjcClass cocoaObjcClass) \
73 Disassociate##ObjcClass((WX_##ObjcClass)m_cocoa##ObjcRoot); \
74 Set##ObjcBase(cocoaObjcClass); \
75 Associate##ObjcClass((WX_##ObjcClass)m_cocoa##ObjcRoot); \
78 #endif // __WX_COCOA_OBJC_ASSOCIATE_H__