Skip to content

Commit

Permalink
IMPLEMENT support of custom scalar types (/!\ swift not supported)
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentin ARNAULT committed Jun 20, 2014
1 parent 8d9fe44 commit 43eff6a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
2 changes: 2 additions & 0 deletions mogenerator.h
Original file line number Diff line number Diff line change
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
42 changes: 39 additions & 3 deletions mogenerator.m
Original file line number Diff line number Diff line change
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 @@ -347,13 +359,37 @@ - (BOOL)hasScalarAttributeType {
- (NSString*)scalarAttributeType {
switch ([self attributeType]) {
case NSInteger16AttributeType:
return gSwift ? @"Int16" : @"int16_t";
{
NSString *attributeValueScalarType = [[self userInfo] objectForKey:kAttributeValueScalarTypeKey];

if (attributeValueScalarType) {
return attributeValueScalarType;
} else {
return gSwift ? @"Int16" : @"int16_t";
}
}
break;
case NSInteger32AttributeType:
return gSwift ? @"Int32" : @"int32_t";
{
NSString *attributeValueScalarType = [[self userInfo] objectForKey:kAttributeValueScalarTypeKey];

if (attributeValueScalarType) {
return attributeValueScalarType;
} else {
return gSwift ? @"Int32" : @"int32_t";
}
}
break;
case NSInteger64AttributeType:
return gSwift ? @"Int64" : @"int64_t";
{
NSString *attributeValueScalarType = [[self userInfo] objectForKey:kAttributeValueScalarTypeKey];

if (attributeValueScalarType) {
return attributeValueScalarType;
} else {
return gSwift ? @"Int64" : @"int64_t";
}
}
break;
case NSDoubleAttributeType:
return gSwift ? @"Double" : @"double";
Expand Down
4 changes: 4 additions & 0 deletions templates/machine.h.motemplate
Original file line number Diff line number Diff line change
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

0 comments on commit 43eff6a

Please sign in to comment.