src/GuileHandler.h
branchv_0
changeset 12 7977c1bdba1f
parent 11 9603e64324bc
child 13 c9fece435aa2
equal deleted inserted replaced
11:9603e64324bc 12:7977c1bdba1f
   188 		if (currentRelationConfiguration) {
   188 		if (currentRelationConfiguration) {
   189 			evalGuileCode(currentRelationConfiguration->guileAfterRecords);
   189 			evalGuileCode(currentRelationConfiguration->guileAfterRecords);
   190 			for (DefinitionRecipe definition : currentRelationConfiguration->definitions) undefineGuileVariable(definition.name);
   190 			for (DefinitionRecipe definition : currentRelationConfiguration->definitions) undefineGuileVariable(definition.name);
   191 		}
   191 		}
   192 		for (auto attribute : currentReaderMetadata) undefineGuileVariable(attribute.getAttributeName());
   192 		for (auto attribute : currentReaderMetadata) undefineGuileVariable(attribute.getAttributeName());
   193 		currentReaderMetadata = attributes;
       
   194 		// TODO: move to a reusable method (or use same metadata on both reader and writer side?)
       
   195 		// TODO: allow structural changes during transformation
       
   196 		currentWriterMetadata.clear();
       
   197 		for (AttributeMetadata readerMetadata : attributes) {
       
   198 			currentWriterMetadata.push_back({readerMetadata.getAttributeName(), relationalWriter->toTypeId(readerMetadata.getTypeName())});
       
   199 		}
       
   200 
   193 
   201 		currentRelationConfiguration = nullptr;
   194 		currentRelationConfiguration = nullptr;
   202 		for (int i = 0; i < configuration.relationConfigurations.size(); i++) {
   195 		for (int i = 0; i < configuration.relationConfigurations.size(); i++) {
   203 			if (regex_match(name, wregex(configuration.relationConfigurations[i].relation))) {
   196 			if (regex_match(name, wregex(configuration.relationConfigurations[i].relation))) {
   204 				currentRelationConfiguration = &configuration.relationConfigurations[i];
   197 				currentRelationConfiguration = &configuration.relationConfigurations[i];
   205 				for (DefinitionRecipe definition : currentRelationConfiguration->definitions) defineGuileVariable(definition);
   198 				for (DefinitionRecipe definition : currentRelationConfiguration->definitions) defineGuileVariable(definition);
   206 				break; // it there are multiple matches, only the first configuration is used
   199 				break; // it there are multiple matches, only the first configuration is used
   207 			}
   200 			}
   208 		}
   201 		}
   209 
   202 
       
   203 		currentReaderMetadata = attributes;
       
   204 		// TODO: move to a reusable method (or use same metadata on both reader and writer side?)
       
   205 		currentWriterMetadata.clear();
       
   206 		if (currentRelationConfiguration && currentRelationConfiguration->writerMetadata.size()) {
       
   207 			currentWriterMetadata = currentRelationConfiguration->writerMetadata;
       
   208 		} else {
       
   209 			for (AttributeMetadata readerMetadata : attributes) currentWriterMetadata.push_back({readerMetadata.getAttributeName(), relationalWriter->toTypeId(readerMetadata.getTypeName())});
       
   210 		}
       
   211 
   210 		relationalWriter->startRelation(name, currentWriterMetadata, true);
   212 		relationalWriter->startRelation(name, currentWriterMetadata, true);
   211 
   213 
   212 		if (currentRelationConfiguration) {
   214 		if (currentRelationConfiguration) {
   213 			// TODO: better variable name, object, function?
   215 			// TODO: better variable name, object, function?
   214 			defineGuileVariable(L"relpipe-relation-name", &name, typeid (name), TypeId::STRING);
   216 			defineGuileVariable(L"relpipe-relation-name", &name, typeid (name), TypeId::STRING);