[vtk-developers] Proposed change to vtkCocoaGLView.h (regarding C++ usage)

Sean McBride sean at rogue-research.com
Mon Mar 10 19:03:46 EDT 2008


Hi all,

VTK provides the public class vtkCocoaGLView.  It is a subclass of
Apple's NSView.  NSView is an Objective-C class.  vtkCocoaGLView is a so-
called Objective-C++ class, meaning that it is an Objective-C class but
it has some C++ syntax (needed because it has methods and instance
variables with C++ types).  This is absolutely fine, working, common,
and well-supported.  However...

Apple's Xcode 3 IDE provides some code refactoring features which are
extremely useful, however they only support Objective-C, not C++ and not
even Objective-C++.

Every time I #include vtkCocoaGLView.h I am forced to make my files .mm
instead of .m (Obj-C++ vs Obj-C).  Then I loose refactoring for those
files. :(

I have a fix, and want to see if anyone objects... Basically,
vtkCocoaGLView.h can be summarised as:

--------
class vtkCocoaRenderWindow; // fwd declare

@interface vtkCocoaGLView : NSView
{
	vtkCocoaRenderWindow* ivar;
}

- (vtkCocoaRenderWindow*)method;
@end
--------

Where vtkCocoaRenderWindow is a C++ type.  I'd like to change it to:

--------
#ifdef __cplusplus
	class vtkCocoaRenderWindow; // fwd declare
	typedef vtkCocoaRenderWindow* vtkCocoaRenderWindowRef;
#else
	typedef void* vtkCocoaRenderWindowRef;
#endif

@interface vtkCocoaGLView : NSView
{
	vtkCocoaRenderWindowRef ivar;
}

- (vtkCocoaRenderWindowRef)method;
@end
--------

Now, if vtkCocoaGLView.h is included by a .m file it sees pure Obj-C, if
it is included by a .mm files it sees Obj-C++.

It's not too ugly... :)  Any objections?

Thanks,

-- 
____________________________________________________________
Sean McBride, B. Eng                 sean at rogue-research.com
Rogue Research                        www.rogue-research.com 
Mac Software Developer              Montréal, Québec, Canada




More information about the vtk-developers mailing list