Re: ObjC data structure for C++/ObjC++ objects?
Re: ObjC data structure for C++/ObjC++ objects?
- Subject: Re: ObjC data structure for C++/ObjC++ objects?
- From: "Jonathan Bailey" <email@hidden>
- Date: Sat, 8 Nov 2008 00:12:41 -0500
Hi Michael -
Thanks much for your response. I actually did originally intend to use
an STL map, but I couldn't get it to work. It seemed that when I added
a C++ object to a map declared as an instance variable within my
ObjC++ class's header file, this generated an "EXC_BAD_ACCESS" signal
- and no exception thrown. As a test, I created a temp STL map in the
implementation/.mm file for this class, and added my C++ object to
that map and it seemed to work fine. So I assumed that templated
classes weren't supported as instance variables for an ObjC++ class.
I'll definitely investigate using CFMutableDictionary instead if
indeed STL won't work for instance variables.
Thanks, JB
On Fri, Nov 7, 2008 at 10:29 PM, Michael Ash <email@hidden> wrote:
> On Fri, Nov 7, 2008 at 8:41 PM, Jonathan Bailey <email@hidden> wrote:
>> Hi all -
>>
>> I am trying to find a way to create a dynamically-growable objective C
>> data structure within objective C++ code, such as a
>> NSMutableDictionary, that can store values that are pointers to an
>> objective C++ or straight-up C++ object.
>>
>> NSMutableDictionary seems to only accept pointers to objective C
>> objects, however, and not to arbitrary objects. This seems like a
>> simple thing to do but I am a bit stumped. Does anyone know of a way
>> to do this?
>
> CFMutableDictionary will accept arbitrary pointers, and allows you to
> provide callbacks so that it knows how to work with them.
>
> As an added bonus, CFMutableDictionary is "toll-free bridged" to
> NSMutableDictionary, meaning that you can simply cast the pointer and
> use it. The bridging is not 100% with custom callbacks, as there are
> parts of the NSMutableDictionary API which assume that you are storing
> only Objective-C objects, but for dictionaries which actually are
> storing Objective-C objects it's very useful. This also means that you
> can store it in other Cocoa collections like NSArray, other
> NSDictionaries, etc.
>
> And note that if you're using Objective-C++, there's nothing
> preventing you from using STL collections for this sort of thing, if
> they do what you like.
>
> Mike
> _______________________________________________
>
> 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
>
_______________________________________________
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