]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/cocoa/ObjcAssociate.h
improved const-ness of find/Find functions
[wxWidgets.git] / include / wx / cocoa / ObjcAssociate.h
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/cocoa/ObjcAssociate.h
3// Purpose: Associates an Objective-C class with a C++ class
4// Author: David Elliott
5// Modified by:
6// Created: 2002/12/03
7// RCS-ID: $Id:
8// Copyright: (c) 2002 David Elliott <dfe@cox.net>
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef __WX_COCOA_OBJC_ASSOCIATE_H__
13#define __WX_COCOA_OBJC_ASSOCIATE_H__
14
15/*-------------------------------------------------------------------------
16Basic hashmap stuff, used by everything
17-------------------------------------------------------------------------*/
18#define WX_DECLARE_OBJC_HASHMAP(ObjcClass) \
19class wxCocoa##ObjcClass; \
20WX_DECLARE_HASH_MAP(WX_##ObjcClass,wxCocoa##ObjcClass*,wxPointerHash,wxPointerEqual,wxCocoa##ObjcClass##Hash)
21
22#define WX_DECLARE_OBJC_INTERFACE_HASHMAP(ObjcClass) \
23public: \
24 static inline wxCocoa##ObjcClass* GetFromCocoa(WX_##ObjcClass cocoaObjcClass) \
25 { \
26 wxCocoa##ObjcClass##Hash::iterator iter = sm_cocoaHash.find(cocoaObjcClass); \
27 if(iter!=sm_cocoaHash.end()) \
28 { \
29 return iter->second; \
30 } \
31 return NULL; \
32 } \
33protected: \
34 static wxCocoa##ObjcClass##Hash sm_cocoaHash;
35
36#define WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(ObjcClass) \
37wxCocoa##ObjcClass##Hash wxCocoa##ObjcClass::sm_cocoaHash;
38
39
40/*-------------------------------------------------------------------------
41The entire interface, including some boilerplate stuff
42-------------------------------------------------------------------------*/
43#define WX_DECLARE_OBJC_INTERFACE(ObjcClass) \
44WX_DECLARE_OBJC_INTERFACE_HASHMAP(ObjcClass) \
45public: \
46 inline void Associate##ObjcClass(WX_##ObjcClass cocoaObjcClass) \
47 { \
48 if(cocoaObjcClass) \
49 sm_cocoaHash.insert(wxCocoa##ObjcClass##Hash::value_type(cocoaObjcClass,this)); \
50 } \
51 inline void Disassociate##ObjcClass(WX_##ObjcClass cocoaObjcClass) \
52 { \
53 if(cocoaObjcClass) \
54 sm_cocoaHash.erase(cocoaObjcClass); \
55 }
56
57#define WX_IMPLEMENT_OBJC_INTERFACE(ObjcClass) \
58WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(ObjcClass)
59
60/*-------------------------------------------------------------------------
61Stuff to be used by the wxWindows class (not the Cocoa interface)
62-------------------------------------------------------------------------*/
63#define WX_DECLARE_COCOA_OWNER(ObjcClass,ObjcBase,ObjcRoot) \
64public: \
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; } \
67protected: \
68 void Set##ObjcClass(WX_##ObjcClass cocoaObjcClass);
69
70#define WX_IMPLEMENT_COCOA_OWNER(wxClass,ObjcClass,ObjcBase,ObjcRoot) \
71void wxClass::Set##ObjcClass(WX_##ObjcClass cocoaObjcClass) \
72{ \
73 Disassociate##ObjcClass((WX_##ObjcClass)m_cocoa##ObjcRoot); \
74 Set##ObjcBase(cocoaObjcClass); \
75 Associate##ObjcClass((WX_##ObjcClass)m_cocoa##ObjcRoot); \
76}
77
78#endif // __WX_COCOA_OBJC_ASSOCIATE_H__
79