Using Bindings with C++ objects
Using Bindings with C++ objects
- Subject: Using Bindings with C++ objects
- From: Rick Mann <email@hidden>
- Date: Sat, 22 Dec 2007 14:53:55 -0800
I have an existing Carbon app that I'm trying to port to Cocoa. I
don't want to rewrite everything as an Obj-C object, so I'm looking
for ways to wrap Cocoa around my C++.
In one situation, I have a C++ object that represents a Satellite, and
another that is a SatelliteProxy. In the app, there is a master list
of Satellite objects, and a SatelliteProxy for each satellite in each
view that's displaying satellites. The proxy object overrides some of
the attributes of the graphical representation of a Satellite. For
example, in one view, the International Space Station (ISS) may have a
red ground track, and in another view, a green ground track. In this
instance, there are two ISS SatelliteProxy objects that each refer to
the single, global (app-wide) ISS Satellite object.
The user can select SatelliteProxy objects (one or many) in a view,
then use an inspector to adjust their attributes.For example, if an
attribute is "Show footprint" (the footprint is the area of the Earth
that has line-of-site to the satellite at a given instant), and two
satellites are selected, one with the footprint enabled, the other
not, the checkbox in the inspector would show a dash. Similarly, if
both satellites had the footprint enabled, the box would show as
checked (standard multi-object inspector behavior).
I'd like to use bindings to facilitate this (as I understand it, this
is something they're good for). However, they won't work directly on C+
+ objects. I was thinking I could subclass NSArrayController and
override the valueForKey: methods to manually inspect the key path and
hard-code queries to the SatelliteProxy objects. One of my concerns
with this approach is that the NSArrayController's container for the
collection of SatelliteProxy objects may not be able to contain C++
objects.
I'd like to get feedback on this approach. Is it viable? It's okay if
there's extra effort coding up the key-to-C++ mapping. That's still
less work than rewriting my classes as Obj-C.
An alternative is to create a wrapper Obj-C object, one for each
SatelliteProxy object. I do something similar for the view code I
wrote in the Carbon app.
Suggestions?
TIA,
Rick
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden