wxWidgets/include/wx/cocoa/ObjcPose.h
David Elliott 462bc04863 It was not acceptable to call the class method from the static initializer
because it caused the load and initialize methods to be called.  Some of the
load and initialize methods used autorelease which would lead to warnings
about memory leaks (true, though very benign).
This version delays all Objective-C calls until InitializePosers().


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21585 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2003-07-02 20:46:34 +00:00

69 lines
1.6 KiB
Objective-C

/////////////////////////////////////////////////////////////////////////////
// Name: wx/cocoa/ObjcPose.h
// Purpose: Macros for initializing poseAs, among other things
// Author: David Elliott
// Modified by:
// Created: 2002/12/03
// RCS-ID: $Id:
// Copyright: (c) 2002 David Elliott <dfe@cox.net>
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#ifndef __WX_COCOA_PRIVATE_POSER_H__
#define __WX_COCOA_PRIVATE_POSER_H__
/*-------------------------------------------------------------------------
Objective-C Poser class initialization
-------------------------------------------------------------------------*/
#ifdef __OBJC__
#import <objc/objc-class.h>
#import <Foundation/NSObjcRuntime.h>
class wxPoseAsInitializer
{
public:
wxPoseAsInitializer()
: m_next(sm_first)
{
sm_first = this;
}
virtual ~wxPoseAsInitializer()
{
sm_first = m_next;
}
static void InitializePosers()
{
while(sm_first)
{
delete sm_first;
}
};
protected:
wxPoseAsInitializer *m_next;
static wxPoseAsInitializer *sm_first;
};
class wxDummyForPoseAsInitializer
{
public:
wxDummyForPoseAsInitializer(void*) {}
};
#define WX_IMPLEMENT_POSER(poser) \
class wxPoseAsInitializerFor##poser: public wxPoseAsInitializer \
{ \
protected: \
virtual ~wxPoseAsInitializerFor##poser() \
{ \
class_poseAs([poser class],[poser superclass]); \
} \
}; \
wxDummyForPoseAsInitializer wxDummyPoseAsInitializerFor##poser(new wxPoseAsInitializerFor##poser)
#else // __OBJC__
#warning "Objective-C++ Only!"
#endif // __OBJC__
#endif // __WX_COCOA_PRIVATE_POSER_H__