X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.graph.compiler%2Fsrc%2Forg%2Fsimantics%2Fgraph%2Fcompiler%2Finternal%2Ftemplates%2FGraphTemplate.java;fp=bundles%2Forg.simantics.graph.compiler%2Fsrc%2Forg%2Fsimantics%2Fgraph%2Fcompiler%2Finternal%2Ftemplates%2FGraphTemplate.java;h=abf1a768860d31cdba64004d3feb128f8216f144;hp=0000000000000000000000000000000000000000;hb=969bd23cab98a79ca9101af33334000879fb60c5;hpb=866dba5cd5a3929bbeae85991796acb212338a08 diff --git a/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/templates/GraphTemplate.java b/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/templates/GraphTemplate.java new file mode 100644 index 000000000..abf1a7688 --- /dev/null +++ b/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/templates/GraphTemplate.java @@ -0,0 +1,100 @@ +package org.simantics.graph.compiler.internal.templates; + +import gnu.trove.map.hash.TIntIntHashMap; +import gnu.trove.map.hash.TObjectIntHashMap; + +import java.util.Arrays; +import java.util.Collection; + +import org.simantics.graph.compiler.ExternalFileLoader; +import org.simantics.graph.compiler.internal.store.LocationStore; +import org.simantics.graph.query.IGraph; +import org.simantics.graph.representation.External; +import org.simantics.graph.representation.Identity; +import org.simantics.graph.representation.Root; +import org.simantics.graph.representation.TransferableGraph1; +import org.simantics.graph.representation.Value; +import org.simantics.graph.store.GraphStore; +import org.simantics.graph.store.IdentityStore; +import org.simantics.graph.store.StatementStore; +import org.simantics.graph.store.ValueStore; +import org.simantics.ltk.Location; +import org.simantics.ltk.Problem; + +public class GraphTemplate implements ITemplate { + int[] prototypeResources; + int[] parameterMapping; + int[] statements; + Value[] values; + + public GraphTemplate(GraphStore store, String[] parameters, TransferableGraph1 tg) { + prototypeResources = new int[tg.resourceCount]; + Arrays.fill(prototypeResources, -1); + + this.values = tg.values; + this.statements = tg.statements; + this.parameterMapping = new int[parameters.length]; + TObjectIntHashMap pmap = new TObjectIntHashMap(); + for(int i=0;i problems) { + if(parameters.length != parameterMapping.length) { + Location location = store.getStore(LocationStore.class) + .getLocation(parameters[0]); + problems.add(new Problem(location, "A template applied with wrong number of parameters.")); + return; + } + int[] resources = Arrays.copyOf(prototypeResources, prototypeResources.length); + for(int i=0;i= 0 && map.contains(temp)) + prototypeResources[i] = map.get(temp); + } + } +}