Skip to content

Commit

Permalink
Adds scalar int*_t support.
Browse files Browse the repository at this point in the history
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:.
  • Loading branch information
robrix committed Jan 7, 2012
1 parent 01e5043 commit fd2b556
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
3 changes: 3 additions & 0 deletions mogenerator.h
Expand Up @@ -30,6 +30,9 @@
@interface NSAttributeDescription (scalarAttributeType)
- (BOOL)hasScalarAttributeType;
- (NSString*)scalarAttributeType;
- (NSString*)scalarAttributeTypeName;
- (NSString*)scalarAccessorMethodName;
- (NSString*)scalarFactoryMethodName;
- (BOOL)hasDefinedAttributeType;
- (NSString*)objectAttributeType;
- (NSString*)attributeTypeName;
Expand Down
72 changes: 72 additions & 0 deletions mogenerator.m
Expand Up @@ -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;
}
Expand Down

0 comments on commit fd2b556

Please sign in to comment.