From fd2b5560769cdaa73f08febc35dcad356e8c7634 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Fri, 6 Jan 2012 21:40:05 -0500 Subject: [PATCH] Adds scalar int*_t support. This is done by adding -scalarAttributeTypeName, -scalarAccessorMethodName, and -scalarFactoryMethodName to NSAttributeDescription. -scalarAttributeTypeName returns the same thing as -scalarAttributeType, except that where that uses short, int, and long long, the new method uses int16_t, int32_t, and int64_t. To allow simple boxing and unboxing with NSNumber, -scalarAccessorMethodName and -scalarFactoryMethodName return the appropriate values for the scalar type, e.g. boolValue, longLongValue, and numberWithShort:. --- mogenerator.h | 3 +++ mogenerator.m | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/mogenerator.h b/mogenerator.h index 2daf85ba..885607b2 100644 --- a/mogenerator.h +++ b/mogenerator.h @@ -30,6 +30,9 @@ @interface NSAttributeDescription (scalarAttributeType) - (BOOL)hasScalarAttributeType; - (NSString*)scalarAttributeType; +- (NSString*)scalarAttributeTypeName; +- (NSString*)scalarAccessorMethodName; +- (NSString*)scalarFactoryMethodName; - (BOOL)hasDefinedAttributeType; - (NSString*)objectAttributeType; - (NSString*)attributeTypeName; diff --git a/mogenerator.m b/mogenerator.m index 2ee2bf9f..b8c10f69 100644 --- a/mogenerator.m +++ b/mogenerator.m @@ -248,6 +248,78 @@ - (NSString*)scalarAttributeType { return nil; } } +- (NSString*)scalarAttributeTypeName { + switch ([self attributeType]) { + case NSInteger16AttributeType: + return @"int16_t"; + break; + case NSInteger32AttributeType: + return @"int32_t"; + break; + case NSInteger64AttributeType: + return @"int64_t"; + break; + case NSDoubleAttributeType: + return @"double"; + break; + case NSFloatAttributeType: + return @"float"; + break; + case NSBooleanAttributeType: + return @"BOOL"; + break; + default: + return nil; + } +} +- (NSString*)scalarAccessorMethodName { + switch ([self attributeType]) { + case NSInteger16AttributeType: + return @"shortValue"; + break; + case NSInteger32AttributeType: + return @"intValue"; + break; + case NSInteger64AttributeType: + return @"longLongValue"; + break; + case NSDoubleAttributeType: + return @"doubleValue"; + break; + case NSFloatAttributeType: + return @"floatValue"; + break; + case NSBooleanAttributeType: + return @"boolValue"; + break; + default: + return nil; + } +} +- (NSString*)scalarFactoryMethodName { + switch ([self attributeType]) { + case NSInteger16AttributeType: + return @"numberWithShortValue:"; + break; + case NSInteger32AttributeType: + return @"numberWithIntValue:"; + break; + case NSInteger64AttributeType: + return @"numberWithLongLongValue:"; + break; + case NSDoubleAttributeType: + return @"numberWithDoubleValue:"; + break; + case NSFloatAttributeType: + return @"numberWithFloatValue:"; + break; + case NSBooleanAttributeType: + return @"numberWithBoolValue:"; + break; + default: + return nil; + } +} - (BOOL)hasDefinedAttributeType { return [self attributeType] != NSUndefinedAttributeType; }