ソースを参照

Add stuff based on the idea of a way to compile resource files into code.
Unknown if this will be at tooling time or at runtime...

Sam Jaffe 6 年 前
コミット
904f6bacb5

+ 16 - 0
include/resource_factory/prototype_compiler.hpp

@@ -0,0 +1,16 @@
+//
+//  prototype_compiler.hpp
+//  resource_factory
+//
+//  Created by Sam Jaffe on 11/11/18.
+//  Copyright © 2018 Sam Jaffe. All rights reserved.
+//
+
+#pragma once
+
+namespace objects { namespace prototype {
+  template <typename Base, typename... Args>
+  class compiler {
+    
+  };
+}}

+ 8 - 0
resource_factory.xcodeproj/project.pbxproj

@@ -7,7 +7,9 @@
 	objects = {
 
 /* Begin PBXBuildFile section */
+		CD27237E2198743900AB079D /* prototype_compiler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD27237C2198743900AB079D /* prototype_compiler.cpp */; };
 		CDB23F63230B69A300AC1138 /* libresource_factory.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = CD35DCDD1D612CCD00BE3686 /* libresource_factory.dylib */; };
+		CDB23F6A230B69B900AC1138 /* prototype_compiler_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDB23F69230B69B900AC1138 /* prototype_compiler_test.cpp */; };
 		CDB23F7B230B69D400AC1138 /* GoogleMock.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CDB23F73230B69C800AC1138 /* GoogleMock.framework */; };
 /* End PBXBuildFile section */
 
@@ -50,10 +52,12 @@
 /* End PBXContainerItemProxy section */
 
 /* Begin PBXFileReference section */
+		CD27237C2198743900AB079D /* prototype_compiler.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = prototype_compiler.cpp; sourceTree = "<group>"; };
 		CD35DCDD1D612CCD00BE3686 /* libresource_factory.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = libresource_factory.dylib; sourceTree = BUILT_PRODUCTS_DIR; };
 		CDAA16FE21A3A5ED007BBA11 /* resource_factory */ = {isa = PBXFileReference; lastKnownFileType = folder; name = resource_factory; path = include/resource_factory; sourceTree = "<group>"; };
 		CDB23F5E230B69A300AC1138 /* resource_factory-test.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "resource_factory-test.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
 		CDB23F62230B69A300AC1138 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
+		CDB23F69230B69B900AC1138 /* prototype_compiler_test.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = prototype_compiler_test.cpp; sourceTree = "<group>"; };
 		CDB23F6B230B69C800AC1138 /* GoogleMock.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = GoogleMock.xcodeproj; path = "../../../gmock-xcode-master/GoogleMock.xcodeproj"; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
@@ -102,6 +106,7 @@
 		CDAA16FF21A3A5FE007BBA11 /* test */ = {
 			isa = PBXGroup;
 			children = (
+				CDB23F69230B69B900AC1138 /* prototype_compiler_test.cpp */,
 			);
 			path = test;
 			sourceTree = "<group>";
@@ -109,6 +114,7 @@
 		CDAA170021A3A5FE007BBA11 /* src */ = {
 			isa = PBXGroup;
 			children = (
+				CD27237C2198743900AB079D /* prototype_compiler.cpp */,
 			);
 			path = src;
 			sourceTree = "<group>";
@@ -276,6 +282,7 @@
 			isa = PBXSourcesBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
+				CD27237E2198743900AB079D /* prototype_compiler.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -283,6 +290,7 @@
 			isa = PBXSourcesBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
+				CDB23F6A230B69B900AC1138 /* prototype_compiler_test.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

+ 49 - 0
src/prototype_compiler.cpp

@@ -0,0 +1,49 @@
+//
+//  prototype_compiler.cpp
+//  resource_factory
+//
+//  Created by Sam Jaffe on 11/11/18.
+//  Copyright © 2018 Sam Jaffe. All rights reserved.
+//
+
+#include "resource_factory/prototype_compiler.hpp"
+#include "resource_factory/prototype_factory.hpp"
+
+#define CONCAT_IMPL(A, B) A##B
+#define CONCAT(A, B) CONCAT_IMPL(A, B)
+#define BIND(factory, name, ...) bool CONCAT(dummy, __LINE__) = factory::bind(name, __VA_ARGS__)
+
+namespace objects { namespace prototype {
+  typedef factory<int> my_factory;
+  BIND(my_factory, "one", [](){ return 1; });
+  INSTANTIATE_PROTOTYPE_FACTORY(int);
+} }
+
+/**
+ * File object.protobinding
+ * function={json.path.to.object}
+ *
+ * Usage:
+ * objects::prototype::compile<Monster, ...>("resources/monster.protobinding",
+ *                                           "resources/orc.proto");
+ *
+ * e.g.
+ * $ cat resources/monster.protobinding
+ * name={name}
+ * classification={classification}
+ * minHeight={height.minimum}
+ *
+ * $ cat resources/orc.proto
+ * {
+ *   "name": "Orc",
+ *   "classification": "Goblinoid",
+ *   "height": { "minimum": 180, "maximum": 240 }
+ * }
+ *
+ * Output:
+ * Monster create_orc(...) {
+ *   static MonsterPrototype proto = MonsterPrototype()
+ *   .name("Orc").classification("Goblinoid").minHeight(180);
+ *   return proto(...);
+ * }
+ */

+ 12 - 0
test/prototype_compiler_test.cpp

@@ -0,0 +1,12 @@
+//
+//  prototype_compiler_test.cpp
+//  resource_factory-test
+//
+//  Created by Sam Jaffe on 8/19/19.
+//  Copyright © 2019 Sam Jaffe. All rights reserved.
+//
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include "resource_factory/prototype_factory.hpp"