Re: NSNumber : method to return pointer to represented value

2014-03-17 Thread Mike Kluev
> I require an pointer to the value represented by an NSNumber. > ... > I am using NSNumber instances in collections as keys. i may not fully understand your question, but can you not just use NSValue valueWithPointer as your collection keys? or, if a number at all, the number matching the pointer

Re: NSNumber : method to return pointer to represented value

2014-02-24 Thread jonat...@mugginsoft.com
On 23 Feb 2014, at 13:15, Graham Cox wrote: > > Either that or a custom class would actually require very little effort - > probably less than the typing in this discussion so far anyway! > It actually takes a bit more effort to subclass NSNumber than it does to talk about not doing it! Gr

Re: NSNumber : method to return pointer to represented value

2014-02-23 Thread Uli Kusterer
On 23 Feb 2014, at 14:15, Graham Cox wrote: > On 23 Feb 2014, at 11:08 pm, jonat...@mugginsoft.com wrote: > >>> 1(int) and 1(float) can be represented by the same NSNumber object >>> perfectly legally. >> Is that true? > > I said "can be", not "is". Certainly my observation in the past was that

Re: NSNumber : method to return pointer to represented value

2014-02-23 Thread Ken Thomases
On Feb 22, 2014, at 1:28 PM, jonat...@mugginsoft.com wrote: > On 22 Feb 2014, at 15:32, Ken Thomases wrote: >>> >> >> NSDecimalNumber can represent values that are outside of the range of >> doubles. So, _some_ NSDecimalNumber instances _may_ return "d" for double, >> but others definitely w

Re: NSNumber : method to return pointer to represented value

2014-02-23 Thread Jonathan Hull
On Feb 23, 2014, at 4:08 AM, jonat...@mugginsoft.com wrote: >> 1(int) and 1(float) can be represented by the same NSNumber object perfectly >> legally. > Is that true? Yes. As far as NSNumber is concerned, they are equal. They are also both equal to @(YES) which is initialized with a BOOL. On

Re: NSNumber : method to return pointer to represented value

2014-02-23 Thread Graham Cox
On 23 Feb 2014, at 11:08 pm, jonat...@mugginsoft.com wrote: >> 1(int) and 1(float) can be represented by the same NSNumber object perfectly >> legally. > Is that true? I said "can be", not "is". Certainly my observation in the past was that NSNumber stored, as an int, a float that could be rep

Re: NSNumber : method to return pointer to represented value

2014-02-23 Thread jonat...@mugginsoft.com
On 23 Feb 2014, at 10:05, Graham Cox wrote: > > You might find it happens to work today but it is not contracted to do so > I agree that there is some uncertainty going forward. Part of the issue I think is in the nature of class clusters. We rely on the behaviour of an unspecified collection

Re: NSNumber : method to return pointer to represented value

2014-02-23 Thread dangerwillrobinsondanger
Would an NSNumber subclass be out of the question? Just store that original type in your own retrievable way? ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderat

Re: NSNumber : method to return pointer to represented value

2014-02-23 Thread Graham Cox
On 23 Feb 2014, at 8:30 pm, jonat...@mugginsoft.com wrote: > This dict, when instantiated, will contain 1 key value pair. >NSDictionary *dict = @{ @((int)1): @"val 1", @((float)1): @"val 2" }; > > However, this C# Dictionary unit test object will contain two, >ObjectObjectDictio

Re: NSNumber : method to return pointer to represented value

2014-02-23 Thread Ken Thomases
On Feb 23, 2014, at 3:30 AM, jonat...@mugginsoft.com wrote: > 3. For any given object subclass (of which there may be many) I want > -objCType to be constant. > > I think that NSNumber does all of the above. Ken believes that 3. is in doubt. > If this proves to be the case then I will have to g

Re: NSNumber : method to return pointer to represented value

2014-02-23 Thread Graham Cox
On 23 Feb 2014, at 8:30 pm, jonat...@mugginsoft.com wrote: > Therefore the encoded class of the numeric key is essential. Another solution would be just to use a string, with some encoding scheme of your own device, e.g. append a type code to the constant. Category methods on NSString would a

Re: NSNumber : method to return pointer to represented value

2014-02-23 Thread Graham Cox
On 23 Feb 2014, at 8:30 pm, jonat...@mugginsoft.com wrote: > suppose I think that NSNumber actually is a good fit. > My usage model requires: > > 1. Configure an object with a numeric type: e.g.: @((int)5). > 2. When I query an object subclass with getValue: I want to receive back an > instanc

Re: NSNumber : method to return pointer to represented value

2014-02-23 Thread jonat...@mugginsoft.com
On 23 Feb 2014, at 00:07, Graham Cox wrote: > NSNumber's can be slippery buggers, in my experience. Won’t disagree with that. > > Why are you so determined that you must use NSNumber, rather than your own > class? You haven't adequately explained why that isn't a good solution, as it > certai

Re: NSNumber : method to return pointer to represented value

2014-02-22 Thread Graham Cox
On 22 Feb 2014, at 11:58 pm, jonat...@mugginsoft.com wrote: >> There's no one representation of an NSNumber's content. > I think that this is the foundation of things. > > What there is is a reported representation as given by -objCType. NSNumber's can be slippery buggers, in my experience. W

Re: NSNumber : method to return pointer to represented value

2014-02-22 Thread jonat...@mugginsoft.com
On 22 Feb 2014, at 15:32, Ken Thomases wrote: >> > > NSDecimalNumber can represent values that are outside of the range of > doubles. So, _some_ NSDecimalNumber instances _may_ return "d" for double, > but others definitely won't. > I don’t think so. It is possible that this behaviour could

Re: NSNumber : method to return pointer to represented value

2014-02-22 Thread Gary L. Wade
NSDecimal is a structure with associated C-level functions that could theoretically work with the not-yet-supported floating point decimal types in LLVM that were in later versions of GCC whereas NSDecimalNumber is an Objective C class subclassed from NSNumber that provides NSDecimal encapsulation.

Re: NSNumber : method to return pointer to represented value

2014-02-22 Thread jonat...@mugginsoft.com
On 22 Feb 2014, at 16:55, Jens Alfke wrote: > But there's already a fully functional ObjC<->C# bridge in Mono, isn’t there? > I know that’s what MonoTouch for iOS is based on. Doesn’t it already handle > bridging of NSDictionaries to C# Maps? > The MonoTouch bindings are from C# to Cocoa. So

Re: NSNumber : method to return pointer to represented value

2014-02-22 Thread Ken Thomases
On Feb 22, 2014, at 9:43 AM, Ken Thomases wrote: > On Feb 22, 2014, at 9:33 AM, jonat...@mugginsoft.com wrote: > >> -getValue: populates a pointer to a type matching -objCType. > > But there's no guarantee about what that type is. There's no guarantee that > it's a scalar rather than a structu

Re: NSNumber : method to return pointer to represented value

2014-02-22 Thread Jens Alfke
But there's already a fully functional ObjC<->C# bridge in Mono, isn’t there? I know that’s what MonoTouch for iOS is based on. Doesn’t it already handle bridging of NSDictionaries to C# Maps? —Jens ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.co

Re: NSNumber : method to return pointer to represented value

2014-02-22 Thread Ken Thomases
On Feb 22, 2014, at 9:33 AM, jonat...@mugginsoft.com wrote: > On 22 Feb 2014, at 14:27, Jonathan Hull wrote: > >> I think the main objection everyone has is that they believe (as did I) that >> -getValue: is actually returning the internal representation of the object. > > That is a very perti

Re: NSNumber : method to return pointer to represented value

2014-02-22 Thread jonat...@mugginsoft.com
On 22 Feb 2014, at 14:27, Jonathan Hull wrote: > I think the main objection everyone has is that they believe (as did I) that > -getValue: is actually returning the internal representation of the object. That is a very pertinent point that we haven’t mentioned. -getValue: populates a pointer t

Re: NSNumber : method to return pointer to represented value

2014-02-22 Thread Ken Thomases
On Feb 22, 2014, at 6:58 AM, jonat...@mugginsoft.com wrote: > Now I don’t care know how NSNumber persists its value nor with what type it > was initialised. What I do care about in this case is what -objCType returns. > If I create a NSNumber like so: > > NSNumber *n = @((int)5); > > Then [n ob

Re: NSNumber : method to return pointer to represented value

2014-02-22 Thread jonat...@mugginsoft.com
On 22 Feb 2014, at 08:32, Ken Thomases wrote: > There's no one representation of an NSNumber's content. I think that this is the foundation of things. What there is is a reported representation as given by -objCType. The docs say, as I am sure you know: “ NSNumber objCType Returns a C string

Re: NSNumber : method to return pointer to represented value

2014-02-22 Thread Jonathan Hull
Ken is right about the internal representation of NSNumber not being something you can count on (as it is a class cluster). You should be able to count on the format of the data returned from its methods though (e.g. -integerValue, -floatValue). Out of curiosity, are there any constraints on t

Re: NSNumber : method to return pointer to represented value

2014-02-22 Thread Ken Thomases
On Feb 22, 2014, at 1:44 AM, jonat...@mugginsoft.com wrote: > On 22 Feb 2014, at 00:12, Ken Thomases wrote: > >> On Feb 21, 2014, at 3:17 PM, jonat...@mugginsoft.com wrote: >> >>> So I want to be able to send the same message to any class and get an >>> appropriate void* pointer. >> >> There'

Re: NSNumber : method to return pointer to represented value

2014-02-21 Thread jonat...@mugginsoft.com
On 22 Feb 2014, at 00:12, Ken Thomases wrote: > On Feb 21, 2014, at 3:17 PM, jonat...@mugginsoft.com wrote: > >> So I want to be able to send the same message to any class and get an >> appropriate void* pointer. > > There's no one representation of its content, so there's no way for any > r

Re: NSNumber : method to return pointer to represented value

2014-02-21 Thread Ken Thomases
On Feb 21, 2014, at 3:17 PM, jonat...@mugginsoft.com wrote: > I have an NSNumber containing 5. > The NSNumber instance is a key in a dictionary collection. > In order to obtain the value I need to pass a pointer to a memory location > containing 5 to Mono. > However not all keys in the dictionar

Re: NSNumber : method to return pointer to represented value

2014-02-21 Thread jonat...@mugginsoft.com
On 21 Feb 2014, at 19:07, Fritz Anderson wrote > int five = [@((int)5) intValue]; > SomeMonoCall("here's two more than three: ", &five); The above is basically correct - note that I edited it a bit. A basic point here is that you cannot take the address of an rvalue like so &[@((int)5) intVal

Re: NSNumber : method to return pointer to represented value

2014-02-21 Thread Fritz Anderson
On 21 Feb 2014, at 6:12 AM, jonat...@mugginsoft.com wrote: > I require an pointer to the value represented by an NSNumber. (Assuming “value represented” means @1 -> 1, @HUGE -> HUGE.) > No interior pointer exists as the class is immutable. Immutability isn’t the point. The point is that the cla

NSNumber : method to return pointer to represented value

2014-02-21 Thread jonat...@mugginsoft.com
I require an pointer to the value represented by an NSNumber. No interior pointer exists as the class is immutable. My best attempt, a category that shadows the represented value, is as follows though I am wondering if I have missed a trick somewhere. NSNumber uses tagged pointers and my unit te