Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IMPLEMENT support of custom scalar types (/!\ swift not supported) #207

Merged
merged 2 commits into from Aug 7, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions mogenerator.h
Expand Up @@ -22,8 +22,10 @@
- (BOOL)hasCustomClass;
- (BOOL)hasSuperentity;
- (BOOL)hasCustomSuperentity;
- (BOOL)hasAdditionalHeaderFile;
- (NSString*)customSuperentity;
- (NSString*)forcedCustomBaseClass;
- (NSString*)additionalHeaderFileName;
- (void)_processPredicate:(NSPredicate*)predicate_ bindings:(NSMutableArray*)bindings_;
- (NSArray*)prettyFetchRequests;
@end
Expand Down
60 changes: 39 additions & 21 deletions mogenerator.m
Expand Up @@ -12,6 +12,9 @@
NSString *gCustomBaseClassForced;
BOOL gSwift;

static NSString *const kAttributeValueScalarTypeKey = @"attributeValueScalarType";
static NSString *const kAdditionalHeaderFileNameKey = @"additionalHeaderFileName";

@interface NSEntityDescription (fetchedPropertiesAdditions)
- (NSDictionary*)fetchedPropertiesByName;
@end
Expand Down Expand Up @@ -130,6 +133,10 @@ - (BOOL)hasCustomSuperentity {
}
}

- (BOOL)hasAdditionalHeaderFile {
return [[[self userInfo] allKeys] containsObject:kAdditionalHeaderFileNameKey];
}

- (NSString*)customSuperentity {
NSString *forcedBaseClass = [self forcedCustomBaseClass];
if (!forcedBaseClass) {
Expand Down Expand Up @@ -159,6 +166,11 @@ - (NSArray*)noninheritedAttributes {
return [[[self attributesByName] allValues] sortedArrayUsingDescriptors:sortDescriptors];
}
}

- (NSString*)additionalHeaderFileName {
return [[self userInfo] objectForKey:kAdditionalHeaderFileNameKey];
}

/** @TypeInfo NSAttributeDescription */
- (NSArray*)noninheritedAttributesSansType {
NSArray *attributeDescriptions = [self noninheritedAttributes];
Expand Down Expand Up @@ -345,27 +357,33 @@ - (BOOL)hasScalarAttributeType {
}
}
- (NSString*)scalarAttributeType {
switch ([self attributeType]) {
case NSInteger16AttributeType:
return gSwift ? @"Int16" : @"int16_t";
break;
case NSInteger32AttributeType:
return gSwift ? @"Int32" : @"int32_t";
break;
case NSInteger64AttributeType:
return gSwift ? @"Int64" : @"int64_t";
break;
case NSDoubleAttributeType:
return gSwift ? @"Double" : @"double";
break;
case NSFloatAttributeType:
return gSwift ? @"Float" : @"float";
break;
case NSBooleanAttributeType:
return gSwift ? @"Bool" : @"BOOL";
break;
default:
return nil;
NSString *attributeValueScalarType = [[self userInfo] objectForKey:kAttributeValueScalarTypeKey];

if (attributeValueScalarType) {
return attributeValueScalarType;
} else {
switch ([self attributeType]) {
case NSInteger16AttributeType:
return gSwift ? @"Int16" : @"int16_t";
break;
case NSInteger32AttributeType:
return gSwift ? @"Int32" : @"int32_t";
break;
case NSInteger64AttributeType:
return gSwift ? @"Int64" : @"int64_t";
break;
case NSDoubleAttributeType:
return gSwift ? @"Double" : @"double";
break;
case NSFloatAttributeType:
return gSwift ? @"Float" : @"float";
break;
case NSBooleanAttributeType:
return gSwift ? @"Bool" : @"BOOL";
break;
default:
return nil;
}
}
}
- (NSString*)scalarAccessorMethodName {
Expand Down
4 changes: 4 additions & 0 deletions templates/machine.h.motemplate
Expand Up @@ -5,6 +5,10 @@
<$if hasCustomSuperentity$><$if hasSuperentity$>#import "<$customSuperentity$>.h"
<$else$><$if hasCustomBaseCaseImport$>#import <$baseClassImport$><$else$>#import "<$customSuperentity$>.h"<$endif$><$endif$><$endif$>

<$if hasAdditionalHeaderFile$>
#import "<$additionalHeaderFileName$>"
<$endif$>

<$if noninheritedAttributes.@count > 0$>
extern const struct <$managedObjectClassName$>Attributes {<$foreach Attribute noninheritedAttributes do$>
<$if TemplateVar.arc$>__unsafe_unretained<$endif$> NSString *<$Attribute.name$>;<$endforeach do$>
Expand Down