Re: Encapsulate C struct/toll-free bridging?
Re: Encapsulate C struct/toll-free bridging?
- Subject: Re: Encapsulate C struct/toll-free bridging?
- From: Thomas Lachand-Robert <email@hidden>
- Date: Tue, 9 Mar 2004 16:42:09 +0100
Le 9 mars 04, ` 04:52, David Bainbridge a icrit :
I am passing a C data structure back and forth between Cocoa framework
and carbon CFM code. Is there an elegant way to encapsulate structs
such that I can integrate it better with Objective-C/Cocoa?
<snip>
It sounds like
I am looking for something similar to the toll-free bridging that goes
on between some CF structures and Cocoa objects.. Any suggestions?
Toll-free bridging is basically achieved by using structures like this:
typedef struct { Class isa; ... other members ... } myStruct;
The crucial point is the first member must be a pointer to the class of
the obj-c object (it is named 'isa' in Objective-C). This struct is
identical in contents to
@interface myClass { ... other members ... }
so you can pass one to other by a C casting like (myClass*) aStruct or
(myStruct*) anObject, provided you have properly set the 'isa' member.
You will find more details at (long link):
http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/
index.html?
http://developer.apple.com/documentation/Cocoa/Conceptual/
ObjectiveC/9objc_runtime_reference/chapter_5_section_27.html
Hope this helps,
Thomas Lachand-Robert
********************** email@hidden
<< Et le chemin est long du projet ` la chose. >> Molihre, Tartuffe.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.