• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: ObjC data structure for C++/ObjC++ objects?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ObjC data structure for C++/ObjC++ objects?


  • Subject: Re: ObjC data structure for C++/ObjC++ objects?
  • From: Andrew Merenbach <email@hidden>
  • Date: Fri, 7 Nov 2008 21:33:31 -0800

Greetings, Jonathan,

If you can afford to target 10.5+ only, you can use an NSMapTable, which is a mutable type of collection "modeled after NSDictionary" but "can contain arbitrary pointers (its contents are not constrained to being objects)"; it can also "hold weak references to its keys and/or values." It's probably a little more friendly than using CFMutableDictionary. Hope this helps!

Cheers,
	Andrew

On Nov 7, 2008, at 9:12 PM, Jonathan Bailey wrote:

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

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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

  • Follow-Ups:
    • Re: ObjC data structure for C++/ObjC++ objects?
      • From: "Jonathan Bailey" <email@hidden>
References: 
 >ObjC data structure for C++/ObjC++ objects? (From: "Jonathan Bailey" <email@hidden>)
 >Re: ObjC data structure for C++/ObjC++ objects? (From: "Michael Ash" <email@hidden>)
 >Re: ObjC data structure for C++/ObjC++ objects? (From: "Jonathan Bailey" <email@hidden>)

  • Prev by Date: Xcode 3.1 (iphone SDK version) breaks my Core Data app
  • Next by Date: Re: Notification when window is closing?
  • Previous by thread: Re: ObjC data structure for C++/ObjC++ objects?
  • Next by thread: Re: ObjC data structure for C++/ObjC++ objects?
  • Index(es):
    • Date
    • Thread