From 6e99d9f44965386afacaa1b4e23f6b511a519eb8 Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Wed, 22 Jul 2015 12:25:01 -0400 Subject: [PATCH] issue #83: add template var to make Mike Ash-style structs optional --- mogenerator.m | 6 ++++++ templates/machine.h.motemplate | 4 ++++ templates/machine.m.motemplate | 4 ++++ 3 files changed, 14 insertions(+) diff --git a/mogenerator.m b/mogenerator.m index 77808650..73dc8674 100644 --- a/mogenerator.m +++ b/mogenerator.m @@ -944,6 +944,12 @@ - (int)application:(DDCliApplication*)app runWithArguments:(NSArray*)arguments { [templateVar setObject:@YES forKey:@"modules"]; } + // Default to generating Mike Ash-style structures if nothing specific was specified in the command arguments + if ([templateVar objectForKey:@"ash-structures"] == nil) + { + [templateVar setObject:@YES forKey:@"ash-structures"]; + } + gSwift = _swift; if (baseClassForce) { diff --git a/templates/machine.h.motemplate b/templates/machine.h.motemplate index da33f108..60c8d288 100644 --- a/templates/machine.h.motemplate +++ b/templates/machine.h.motemplate @@ -9,6 +9,8 @@ #import "<$additionalHeaderFileName$>" <$endif$> +<$if TemplateVar.ash-structures$> + <$if noninheritedAttributes.@count > 0$> extern const struct <$managedObjectClassName$>Attributes {<$foreach Attribute noninheritedAttributes do$> <$if TemplateVar.arc$>__unsafe_unretained<$endif$> NSString *<$Attribute.name$>;<$endforeach do$> @@ -33,6 +35,8 @@ extern const struct <$managedObjectClassName$>UserInfo {<$foreach UserInfo userI } <$managedObjectClassName$>UserInfo; <$endif$> +<$endif$> + <$foreach Relationship noninheritedRelationships do$>@class <$Relationship.destinationEntity.managedObjectClassName$>; <$endforeach do$> <$foreach Attribute noninheritedAttributes do$> diff --git a/templates/machine.m.motemplate b/templates/machine.m.motemplate index e4fb5c8e..3fec25b3 100644 --- a/templates/machine.m.motemplate +++ b/templates/machine.m.motemplate @@ -3,6 +3,8 @@ #import "_<$managedObjectClassName$>.h" +<$if TemplateVar.ash-structures$> + <$if noninheritedAttributes.@count > 0$> const struct <$managedObjectClassName$>Attributes <$managedObjectClassName$>Attributes = {<$foreach Attribute noninheritedAttributes do$> .<$Attribute.name$> = @"<$Attribute.name$>",<$endforeach do$> @@ -27,6 +29,8 @@ const struct <$managedObjectClassName$>UserInfo <$managedObjectClassName$>UserIn }; <$endif$> +<$endif$> + @implementation <$managedObjectClassName$>ID @end