aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2009-09-08 17:45:23 +0000
committerGravatar gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2009-09-08 17:45:23 +0000
commit29229aa01d4ef56f614636a7bf0a73403304d994 (patch)
tree1a452deedec4e2b0102d8fa5ed2d9462fd3f5a5d
parentdb82cd9ae80c2428fc2cf93b46c21b6360b37f0b (diff)
[Author: dmaclach]
Adds CGFloat support to NSNumber R=thomasvl DELTA=219 (217 added, 0 deleted, 2 changed)
-rw-r--r--AppKit/GTMUILocalizerAndLayoutTweaker.m4
-rw-r--r--Foundation/GTMNSNumber+64Bit.h38
-rw-r--r--Foundation/GTMNSNumber+64Bit.m98
-rw-r--r--Foundation/GTMNSNumber+64BitTest.m56
-rw-r--r--GTM.xcodeproj/project.pbxproj12
-rw-r--r--GTMiPhone.xcodeproj/project.pbxproj6
-rw-r--r--ReleaseNotes.txt4
-rw-r--r--UnitTesting/GTMNSObject+UnitTesting.m3
8 files changed, 219 insertions, 2 deletions
diff --git a/AppKit/GTMUILocalizerAndLayoutTweaker.m b/AppKit/GTMUILocalizerAndLayoutTweaker.m
index 91c6ffc..cae8a02 100644
--- a/AppKit/GTMUILocalizerAndLayoutTweaker.m
+++ b/AppKit/GTMUILocalizerAndLayoutTweaker.m
@@ -18,6 +18,7 @@
#import "GTMUILocalizerAndLayoutTweaker.h"
#import "GTMUILocalizer.h"
+#import "GTMNSNumber+64Bit.h"
// Helper that will try to do a SizeToFit on any UI items and do the special
// case handling we also need to end up with a usable UI item. It also takes
@@ -160,7 +161,8 @@ static BOOL IsRightAnchored(NSView *view);
// once we know this view's size.
if (IsRightAnchored(subView)) {
[rightAlignedSubViews addObject:subView];
- [rightAlignedSubViewDeltas addObject:[NSNumber numberWithDouble:delta]];
+ NSNumber *nsDelta = [NSNumber gtm_numberWithCGFloat:delta];
+ [rightAlignedSubViewDeltas addObject:nsDelta];
}
}
diff --git a/Foundation/GTMNSNumber+64Bit.h b/Foundation/GTMNSNumber+64Bit.h
new file mode 100644
index 0000000..a5c31e1
--- /dev/null
+++ b/Foundation/GTMNSNumber+64Bit.h
@@ -0,0 +1,38 @@
+//
+// GTMNSNumber+64Bit.h
+//
+// Copyright 2009 Google Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy
+// of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+//
+
+#import <Foundation/Foundation.h>
+#import "GTMDefines.h"
+
+// Adds support for working with NSIntegers,
+// NSUIntegers, CGFloats and NSNumbers (rdar://5812091)
+@interface NSNumber (GTM64BitAdditions)
+
++ (NSNumber *)gtm_numberWithCGFloat:(CGFloat)value;
++ (NSNumber *)gtm_numberWithInteger:(NSInteger)value;
++ (NSNumber *)gtm_numberWithUnsignedInteger:(NSUInteger)value;
+
+- (id)gtm_initWithCGFloat:(CGFloat)value;
+- (id)gtm_initWithInteger:(NSInteger)value;
+- (id)gtm_initWithUnsignedInteger:(NSUInteger)value;
+
+- (CGFloat)gtm_cgFloatValue;
+- (NSInteger)gtm_integerValue;
+- (NSUInteger)gtm_unsignedIntegerValue;
+
+@end
diff --git a/Foundation/GTMNSNumber+64Bit.m b/Foundation/GTMNSNumber+64Bit.m
new file mode 100644
index 0000000..49d5c4d
--- /dev/null
+++ b/Foundation/GTMNSNumber+64Bit.m
@@ -0,0 +1,98 @@
+//
+// GTMNSNumber+64Bit.m
+//
+// Copyright 2009 Google Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy
+// of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+//
+
+#import "GTMNSNumber+64Bit.h"
+
+@implementation NSNumber (GTM64BitAdditions)
++ (NSNumber *)gtm_numberWithCGFloat:(CGFloat)value {
+ return [[[[self class] alloc] gtm_initWithCGFloat:value] autorelease];
+}
+
++ (NSNumber *)gtm_numberWithInteger:(NSInteger)value {
+ return [[[[self class] alloc] gtm_initWithInteger:value] autorelease];
+}
+
++ (NSNumber *)gtm_numberWithUnsignedInteger:(NSUInteger)value {
+ return [[[[self class] alloc] gtm_initWithUnsignedInteger:value] autorelease];
+}
+
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
+
+- (id)gtm_initWithCGFloat:(CGFloat)value {
+ CFNumberRef numberRef = CFNumberCreate(NULL, kCFNumberCGFloatType, &value);
+ return NSMakeCollectable(numberRef);
+}
+
+- (CGFloat)gtm_cgFloatValue {
+ CGFloat value = 0;
+ CFNumberGetValue((CFNumberRef)self, kCFNumberCGFloatType, &value);
+ return value;
+}
+
+- (id)gtm_initWithInteger:(NSInteger)value {
+ return [self initWithInteger:value];
+}
+
+- (NSInteger)gtm_integerValue {
+ return [self integerValue];
+}
+
+- (id)gtm_initWithUnsignedInteger:(NSUInteger)value {
+ return [self initWithUnsignedInteger:value];
+}
+
+- (NSUInteger)gtm_unsignedIntegerValue {
+ return [self unsignedIntegerValue];
+}
+
+#else // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
+
+- (id)gtm_initWithCGFloat:(CGFloat)value {
+#if defined(__LP64__) && __LP64__
+ return [self initWithDouble:value];
+#else
+ return [self initWithFloat:value];
+#endif // defined(__LP64__) && __LP64__
+}
+
+- (CGFloat)gtm_cgFloatValue {
+#if defined(__LP64__) && __LP64__
+ return [self doubleValue];
+#else
+ return [self floatValue];
+#endif // defined(__LP64__) && __LP64__
+}
+
+- (id)gtm_initWithInteger:(NSInteger)value {
+ return [self initWithLong:value];
+}
+
+- (NSInteger)gtm_integerValue {
+ return [self longValue];
+}
+
+- (id)gtm_initWithUnsignedInteger:(NSUInteger)value {
+ return [self initWithUnsignedLong:value];
+}
+
+- (NSUInteger)gtm_unsignedIntegerValue {
+ return [self unsignedLongValue];
+}
+
+#endif // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
+@end
diff --git a/Foundation/GTMNSNumber+64BitTest.m b/Foundation/GTMNSNumber+64BitTest.m
new file mode 100644
index 0000000..5250bc7
--- /dev/null
+++ b/Foundation/GTMNSNumber+64BitTest.m
@@ -0,0 +1,56 @@
+//
+// GTMNSNumber+64BitTest.m
+//
+// Copyright 2009 Google Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy
+// of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+//
+
+#import "GTMSenTestCase.h"
+#import "GTMNSNumber+64Bit.h"
+
+@interface GTMNSNumber_64BitTest : GTMTestCase
+@end
+
+@implementation GTMNSNumber_64BitTest
+- (void)testCGFloat {
+ CGFloat testValue = 0.0;
+ NSNumber *testNum = [NSNumber gtm_numberWithCGFloat:testValue];
+ STAssertEquals(testValue, [testNum gtm_cgFloatValue], nil);
+ testValue = INFINITY;
+ testNum = [NSNumber gtm_numberWithCGFloat:testValue];
+ STAssertEquals(testValue, [testNum gtm_cgFloatValue], nil);
+ testValue = -1.0;
+ testNum = [NSNumber gtm_numberWithCGFloat:testValue];
+ STAssertEquals(testValue, [testNum gtm_cgFloatValue], nil);
+}
+
+- (void)testInteger {
+ NSInteger testValue = 0.0;
+ NSNumber *testNum = [NSNumber gtm_numberWithInteger:testValue];
+ STAssertEquals(testValue, [testNum gtm_integerValue], nil);
+ testValue = -INT_MAX;
+ testNum = [NSNumber gtm_numberWithInteger:testValue];
+ STAssertEquals(testValue, [testNum gtm_integerValue], nil);
+}
+
+- (void)testUnsignedInteger {
+ NSUInteger testValue = 0.0;
+ NSNumber *testNum = [NSNumber gtm_numberWithUnsignedInteger:testValue];
+ STAssertEquals(testValue, [testNum gtm_unsignedIntegerValue], nil);
+ testValue = UINT_MAX;
+ testNum = [NSNumber gtm_numberWithUnsignedInteger:testValue];
+ STAssertEquals(testValue, [testNum gtm_unsignedIntegerValue], nil);
+}
+
+@end
diff --git a/GTM.xcodeproj/project.pbxproj b/GTM.xcodeproj/project.pbxproj
index b19c00d..48dc0f9 100644
--- a/GTM.xcodeproj/project.pbxproj
+++ b/GTM.xcodeproj/project.pbxproj
@@ -91,6 +91,9 @@
8B1B49190E5F8E2100A08972 /* GTMExceptionalInlines.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B1B49170E5F8E2100A08972 /* GTMExceptionalInlines.m */; };
8B1B49260E5F97C800A08972 /* GTMExceptionalInlinesTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B1B491B0E5F904C00A08972 /* GTMExceptionalInlinesTest.m */; };
8B2789960EF855FB00D68C01 /* GTMUnitTestingWindow.10.5.6.tiff in Resources */ = {isa = PBXBuildFile; fileRef = 8B2789950EF855FB00D68C01 /* GTMUnitTestingWindow.10.5.6.tiff */; };
+ 8B307FF81056B773006C4C7A /* GTMNSNumber+64Bit.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B307FF61056B773006C4C7A /* GTMNSNumber+64Bit.m */; };
+ 8B307FF91056B773006C4C7A /* GTMNSNumber+64Bit.h in Headers */ = {isa = PBXBuildFile; fileRef = 8B307FF71056B773006C4C7A /* GTMNSNumber+64Bit.h */; settings = {ATTRIBUTES = (Public, ); }; };
+ 8B3080151056B917006C4C7A /* GTMNSNumber+64BitTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B3080141056B917006C4C7A /* GTMNSNumber+64BitTest.m */; };
8B3344210DBF7A36009FD32C /* GTMNSAppleScript+HandlerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B3344170DBF7A36009FD32C /* GTMNSAppleScript+HandlerTest.m */; };
8B3344230DBF7A36009FD32C /* GTMNSAppleEventDescriptor+HandlerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B33441A0DBF7A36009FD32C /* GTMNSAppleEventDescriptor+HandlerTest.m */; };
8B3344250DBF7A36009FD32C /* GTMNSAppleEventDescriptor+FoundationTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B33441D0DBF7A36009FD32C /* GTMNSAppleEventDescriptor+FoundationTest.m */; };
@@ -488,6 +491,9 @@
8B1B49170E5F8E2100A08972 /* GTMExceptionalInlines.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTMExceptionalInlines.m; sourceTree = "<group>"; };
8B1B491B0E5F904C00A08972 /* GTMExceptionalInlinesTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTMExceptionalInlinesTest.m; sourceTree = "<group>"; };
8B2789950EF855FB00D68C01 /* GTMUnitTestingWindow.10.5.6.tiff */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = GTMUnitTestingWindow.10.5.6.tiff; sourceTree = "<group>"; };
+ 8B307FF61056B773006C4C7A /* GTMNSNumber+64Bit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GTMNSNumber+64Bit.m"; sourceTree = "<group>"; };
+ 8B307FF71056B773006C4C7A /* GTMNSNumber+64Bit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "GTMNSNumber+64Bit.h"; sourceTree = "<group>"; };
+ 8B3080141056B917006C4C7A /* GTMNSNumber+64BitTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GTMNSNumber+64BitTest.m"; sourceTree = "<group>"; };
8B3344170DBF7A36009FD32C /* GTMNSAppleScript+HandlerTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GTMNSAppleScript+HandlerTest.m"; sourceTree = "<group>"; };
8B3344180DBF7A36009FD32C /* GTMNSAppleScript+Handler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GTMNSAppleScript+Handler.m"; sourceTree = "<group>"; };
8B3344190DBF7A36009FD32C /* GTMNSAppleScript+Handler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "GTMNSAppleScript+Handler.h"; sourceTree = "<group>"; };
@@ -1156,6 +1162,9 @@
F413908C0D75F63C00F72B31 /* GTMNSFileManager+Path.h */,
F413908D0D75F63C00F72B31 /* GTMNSFileManager+Path.m */,
F413908E0D75F63C00F72B31 /* GTMNSFileManager+PathTest.m */,
+ 8B307FF71056B773006C4C7A /* GTMNSNumber+64Bit.h */,
+ 8B307FF61056B773006C4C7A /* GTMNSNumber+64Bit.m */,
+ 8B3080141056B917006C4C7A /* GTMNSNumber+64BitTest.m */,
8B6C15910F356E6400E51E5D /* GTMNSObject+KeyValueObserving.h */,
8B6C15920F356E6400E51E5D /* GTMNSObject+KeyValueObserving.m */,
8B6C161B0F3580DA00E51E5D /* GTMNSObject+KeyValueObservingTest.m */,
@@ -1365,6 +1374,7 @@
F43C7A571021FAA300ABF03C /* GTMUILocalizerAndLayoutTweaker.h in Headers */,
7F97DB32104EBCA0004DDDEE /* GTMFadeTruncatingTextFieldCell.h in Headers */,
7FF768E41051B17E00D34F4B /* GTMNSImage+SearchCache.h in Headers */,
+ 8B307FF91056B773006C4C7A /* GTMNSNumber+64Bit.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1836,6 +1846,7 @@
8BF4D2E80FC70751009ABC3F /* GTMGoogleSearchTest.m in Sources */,
0BFAD4CB104D06FE002BEB27 /* GTMNSData+HexTest.m in Sources */,
0BFAD4CC104D06FE002BEB27 /* GTMNSDictionary+CaseInsensitiveTest.m in Sources */,
+ 8B3080151056B917006C4C7A /* GTMNSNumber+64BitTest.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1908,6 +1919,7 @@
0BFAD4C6104D06EF002BEB27 /* GTMNSData+Hex.m in Sources */,
0BFAD4C9104D06EF002BEB27 /* GTMNSDictionary+CaseInsensitive.m in Sources */,
7FF768E51051B17E00D34F4B /* GTMNSImage+SearchCache.m in Sources */,
+ 8B307FF81056B773006C4C7A /* GTMNSNumber+64Bit.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
diff --git a/GTMiPhone.xcodeproj/project.pbxproj b/GTMiPhone.xcodeproj/project.pbxproj
index 1d4d425..6430e40 100644
--- a/GTMiPhone.xcodeproj/project.pbxproj
+++ b/GTMiPhone.xcodeproj/project.pbxproj
@@ -178,6 +178,9 @@
64D0F5DD0FD3E68400506CC7 /* GTMUIImage+Resize_100x100_to_50x50.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "GTMUIImage+Resize_100x100_to_50x50.png"; path = "TestData/GTMUIImage+Resize_100x100_to_50x50.png"; sourceTree = "<group>"; };
67A7820A0E00927400EBF506 /* GTMIPhoneUnitTestDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GTMIPhoneUnitTestDelegate.h; sourceTree = "<group>"; };
67A7820B0E00927400EBF506 /* GTMIPhoneUnitTestDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTMIPhoneUnitTestDelegate.m; sourceTree = "<group>"; };
+ 8B30806F1056BDCE006C4C7A /* GTMNSNumber+64Bit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "GTMNSNumber+64Bit.h"; sourceTree = "<group>"; };
+ 8B3080701056BDCE006C4C7A /* GTMNSNumber+64Bit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GTMNSNumber+64Bit.m"; sourceTree = "<group>"; };
+ 8B3080711056BDCE006C4C7A /* GTMNSNumber+64BitTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GTMNSNumber+64BitTest.m"; sourceTree = "<group>"; };
8B308BCD0DAD0B8400183556 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
8B3AA8F00E032FC7007E31B5 /* GTMNSString+URLArguments.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "GTMNSString+URLArguments.h"; sourceTree = "<group>"; };
8B3AA8F10E032FC7007E31B5 /* GTMNSString+URLArguments.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GTMNSString+URLArguments.m"; sourceTree = "<group>"; };
@@ -449,6 +452,9 @@
8BC047840DAE928A00C2D1CA /* GTMNSFileManager+Path.h */,
8BC047850DAE928A00C2D1CA /* GTMNSFileManager+Path.m */,
8BC047860DAE928A00C2D1CA /* GTMNSFileManager+PathTest.m */,
+ 8B30806F1056BDCE006C4C7A /* GTMNSNumber+64Bit.h */,
+ 8B3080701056BDCE006C4C7A /* GTMNSNumber+64Bit.m */,
+ 8B3080711056BDCE006C4C7A /* GTMNSNumber+64BitTest.m */,
8B6C18710F3769D200E51E5D /* GTMNSObject+KeyValueObserving.h */,
8B6C18720F3769D200E51E5D /* GTMNSObject+KeyValueObserving.m */,
8B6C18730F3769D200E51E5D /* GTMNSObject+KeyValueObservingTest.m */,
diff --git a/ReleaseNotes.txt b/ReleaseNotes.txt
index fb959ba..603808c 100644
--- a/ReleaseNotes.txt
+++ b/ReleaseNotes.txt
@@ -337,6 +337,10 @@ Changes since 1.5.1
- Added GTMNSData+Hex for conversion to and from hex strings.
+- Added GTMNSNumber+64Bit for working with CGFloats, NSIntegers and NSUInters
+ using NSNumber on all supported SDKs.
+
+
Release 1.5.1
Changes since 1.5.0
16-June-2008
diff --git a/UnitTesting/GTMNSObject+UnitTesting.m b/UnitTesting/GTMNSObject+UnitTesting.m
index 55625c8..8529059 100644
--- a/UnitTesting/GTMNSObject+UnitTesting.m
+++ b/UnitTesting/GTMNSObject+UnitTesting.m
@@ -21,6 +21,7 @@
#import "GTMNSObject+UnitTesting.h"
#import "GTMSystemVersion.h"
#import "GTMGarbageCollection.h"
+#import "GTMNSNumber+64Bit.h"
#if GTM_IPHONE_SDK
#import <UIKit/UIKit.h>
@@ -664,7 +665,7 @@ static NSString *gGTMUnitTestSaveToDirectory = nil;
// LZW Compression for TIFF
NSDictionary *tiffDict
= [NSDictionary dictionaryWithObjectsAndKeys:
- [NSNumber numberWithInt:NSTIFFCompressionLZW],
+ [NSNumber gtm_numberWithUnsignedInteger:NSTIFFCompressionLZW],
(const NSString*)kCGImagePropertyTIFFCompression,
nil];
NSDictionary *destProps