add --define for global variables (can be overridden by relation's ones) v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Tue, 05 Feb 2019 12:14:58 +0100
branchv_0
changeset 13 c9fece435aa2
parent 12 7977c1bdba1f
child 14 82bd0f57a889
add --define for global variables (can be overridden by relation's ones)
src/CLIParser.h
src/Configuration.h
src/GuileHandler.h
--- a/src/CLIParser.h	Tue Feb 05 00:06:44 2019 +0100
+++ b/src/CLIParser.h	Tue Feb 05 12:14:58 2019 +0100
@@ -97,7 +97,8 @@
 					definition.name = readNext(arguments, i);
 					definition.type = readNext(arguments, i);
 					definition.value = readNext(arguments, i);
-					currentRelation.definitions.push_back(definition);
+					if (currentRelation.relation.size()) currentRelation.definitions.push_back(definition);
+					else c.definitions.push_back(definition);
 				} else throw relpipe::cli::RelpipeCLIException(L"Unsupported CLI option: " + option, relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);
 
 			}
--- a/src/Configuration.h	Tue Feb 05 00:06:44 2019 +0100
+++ b/src/Configuration.h	Tue Feb 05 12:14:58 2019 +0100
@@ -56,6 +56,7 @@
 	/**
 	 * Variable definitions for this relation.
 	 * Can be used as a safe way for passing parameters from the outside environment.
+	 * See also Configuration::definitions (can be overridden by relation's definitions)
 	 */
 	std::vector<DefinitionRecipe> definitions;
 	/**
@@ -67,8 +68,13 @@
 class Configuration {
 public:
 	vector<RelationConfiguration> relationConfigurations;
+	/**
+	 * Global definitions for all relations.
+	 * Can be used as a safe way for passing parameters from the outside environment.
+	 * See also RelationConfiguration::definitions
+	 */
+	std::vector<DefinitionRecipe> definitions;
 
-	// TODO: --define – global definitions (for all relations)?
 	// TODO: --relation … --drop – will execute --for-each, but no output will be generated for this relation
 	// TODO: --create t2 3 a integer b boolean '…guile…' – allow creating new relations? Or allow calling startRelation() and attribute() from Guile?
 
--- a/src/GuileHandler.h	Tue Feb 05 00:06:44 2019 +0100
+++ b/src/GuileHandler.h	Tue Feb 05 12:14:58 2019 +0100
@@ -190,6 +190,8 @@
 			for (DefinitionRecipe definition : currentRelationConfiguration->definitions) undefineGuileVariable(definition.name);
 		}
 		for (auto attribute : currentReaderMetadata) undefineGuileVariable(attribute.getAttributeName());
+		
+		for (DefinitionRecipe definition : configuration.definitions) defineGuileVariable(definition);
 
 		currentRelationConfiguration = nullptr;
 		for (int i = 0; i < configuration.relationConfigurations.size(); i++) {