Skip to content
Browse files

Merge pull request #86 from robrix/master

[NEW] Better return value types: `int16_t`/`int32_t`/`int64_t` instead of `short`/`long`/`long long` and `id` instead of `NSObject*`. closes #2, #85 (Rob Rix)
  • Loading branch information...
2 parents 64733a4 + 3f8512b commit c82f11aaa638a5a1866279079a4d6846d18eff07 @rentzsch committed Jan 6, 2012
Showing with 98 additions and 16 deletions.
  1. +4 −0 mogenerator.h
  2. +78 −0 mogenerator.m
  3. +9 −9 templates/machine.h.motemplate
  4. +7 −7 templates/machine.m.motemplate
View
4 mogenerator.h
@@ -30,8 +30,12 @@
@interface NSAttributeDescription (scalarAttributeType)
- (BOOL)hasScalarAttributeType;
- (NSString*)scalarAttributeType;
+- (NSString*)scalarAttributeTypeName;
+- (NSString*)scalarAccessorMethodName;
+- (NSString*)scalarFactoryMethodName;
- (BOOL)hasDefinedAttributeType;
- (NSString*)objectAttributeType;
+- (NSString*)attributeTypeName;
- (BOOL)hasTransformableAttributeType;
@end
View
78 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;
}
@@ -259,6 +331,12 @@ - (NSString*)objectAttributeType {
return [self attributeValueClassName];
}
}
+- (NSString*)attributeTypeName {
+ return
+ [[self userInfo] objectForKey:@"attributeValueTypeName"]
+ ?: [self scalarAttributeTypeName]
+ ?: [[self objectAttributeType] stringByAppendingString:@"*"];
+}
- (BOOL)hasTransformableAttributeType {
return ([self attributeType] == NSTransformableAttributeType);
View
18 templates/machine.h.motemplate
@@ -32,14 +32,14 @@ extern const struct <$managedObjectClassName$>FetchedProperties {<$foreach Fetch
<$foreach Attribute noninheritedAttributes do$>
<$if Attribute.hasDefinedAttributeType$>
<$if TemplateVar.arc$>
-@property (nonatomic, strong) <$Attribute.objectAttributeType$> *<$Attribute.name$>;
+@property (nonatomic, strong) <$Attribute.attributeTypeName$> <$Attribute.name$>;
<$else$>
-@property (nonatomic, retain) <$Attribute.objectAttributeType$> *<$Attribute.name$>;
+@property (nonatomic, retain) <$Attribute.attributeTypeName$> <$Attribute.name$>;
<$endif$>
<$if Attribute.hasScalarAttributeType$>
-@property <$Attribute.scalarAttributeType$> <$Attribute.name$>Value;
-- (<$Attribute.scalarAttributeType$>)<$Attribute.name$>Value;
-- (void)set<$Attribute.name.initialCapitalString$>Value:(<$Attribute.scalarAttributeType$>)value_;
+@property <$Attribute.attributeTypeName$> <$Attribute.name$>Value;
+- (<$Attribute.attributeTypeName$>)<$Attribute.name$>Value;
+- (void)set<$Attribute.name.initialCapitalString$>Value:(<$Attribute.attributeTypeName$>)value_;
<$endif$>
//- (BOOL)validate<$Attribute.name.initialCapitalString$>:(id*)value_ error:(NSError**)error_;
<$endif$>
@@ -87,11 +87,11 @@ extern const struct <$managedObjectClassName$>FetchedProperties {<$foreach Fetch
@interface _<$managedObjectClassName$> (CoreDataGeneratedPrimitiveAccessors)
<$foreach Attribute noninheritedAttributes do$>
<$if Attribute.hasDefinedAttributeType$>
-- (<$Attribute.objectAttributeType$>*)primitive<$Attribute.name.initialCapitalString$>;
-- (void)setPrimitive<$Attribute.name.initialCapitalString$>:(<$Attribute.objectAttributeType$>*)value;
+- (<$Attribute.attributeTypeName$>)primitive<$Attribute.name.initialCapitalString$>;
+- (void)setPrimitive<$Attribute.name.initialCapitalString$>:(<$Attribute.attributeTypeName$>)value;
<$if Attribute.hasScalarAttributeType$>
-- (<$Attribute.scalarAttributeType$>)primitive<$Attribute.name.initialCapitalString$>Value;
-- (void)setPrimitive<$Attribute.name.initialCapitalString$>Value:(<$Attribute.scalarAttributeType$>)value_;
+- (<$Attribute.attributeTypeName$>)primitive<$Attribute.name.initialCapitalString$>Value;
+- (void)setPrimitive<$Attribute.name.initialCapitalString$>Value:(<$Attribute.attributeTypeName$>)value_;
<$endif$>
<$endif$>
<$endforeach do$>
View
14 templates/machine.m.motemplate
@@ -56,22 +56,22 @@ const struct <$managedObjectClassName$>FetchedProperties <$managedObjectClassNam
<$if Attribute.hasScalarAttributeType$>
-- (<$Attribute.scalarAttributeType$>)<$Attribute.name$>Value {
+- (<$Attribute.attributeTypeName$>)<$Attribute.name$>Value {
NSNumber *result = [self <$Attribute.name$>];
- return [result <$Attribute.scalarAttributeType.camelCaseString$>Value];
+ return [result <$Attribute.scalarAccessorMethodName$>];
}
-- (void)set<$Attribute.name.initialCapitalString$>Value:(<$Attribute.scalarAttributeType$>)value_ {
- [self set<$Attribute.name.initialCapitalString$>:[NSNumber numberWith<$Attribute.scalarAttributeType.camelCaseString.initialCapitalString$>:value_]];
+- (void)set<$Attribute.name.initialCapitalString$>Value:(<$Attribute.attributeTypeName$>)value_ {
+ [self set<$Attribute.name.initialCapitalString$>:[NSNumber <$Attribute.scalarFactoryMethodName$>value_]];
}
-- (<$Attribute.scalarAttributeType$>)primitive<$Attribute.name.initialCapitalString$>Value {
+- (<$Attribute.attributeTypeName$>)primitive<$Attribute.name.initialCapitalString$>Value {
NSNumber *result = [self primitive<$Attribute.name.initialCapitalString$>];
- return [result <$Attribute.scalarAttributeType.camelCaseString$>Value];
+ return [result <$Attribute.scalarAccessorMethodName$>];
}
- (void)setPrimitive<$Attribute.name.initialCapitalString$>Value:(<$Attribute.scalarAttributeType$>)value_ {
- [self setPrimitive<$Attribute.name.initialCapitalString$>:[NSNumber numberWith<$Attribute.scalarAttributeType.camelCaseString.initialCapitalString$>:value_]];
+ [self setPrimitive<$Attribute.name.initialCapitalString$>:[NSNumber <$Attribute.scalarFactoryMethodName$>value_]];
}
<$endif$>
<$endif$>

0 comments on commit c82f11a

Please sign in to comment.
Something went wrong with that request. Please try again.