X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.interop.scl%2Fsrc%2Forg%2Fsimantics%2Finterop%2Fscl%2FFunctionRegistry.java;fp=org.simantics.interop.scl%2Fsrc%2Forg%2Fsimantics%2Finterop%2Fscl%2FFunctionRegistry.java;h=003a50ad8488a1fbcf237deb401acdeb7d4fa5fe;hb=14d4d6b020af5777afe37ec990c8fb8661f0bd14;hp=0000000000000000000000000000000000000000;hpb=c276677539e2b4111a072a2e6f6c4e8aa3e65b30;p=simantics%2Finterop.git diff --git a/org.simantics.interop.scl/src/org/simantics/interop/scl/FunctionRegistry.java b/org.simantics.interop.scl/src/org/simantics/interop/scl/FunctionRegistry.java new file mode 100644 index 0000000..003a50a --- /dev/null +++ b/org.simantics.interop.scl/src/org/simantics/interop/scl/FunctionRegistry.java @@ -0,0 +1,82 @@ +package org.simantics.interop.scl; + +import java.util.HashMap; +import java.util.Map; + +import org.simantics.scl.runtime.function.Function; +import org.simantics.utils.datastructures.MapList; + +@SuppressWarnings({"rawtypes","unchecked"}) +public class FunctionRegistry { + + + static Map> map = new HashMap>(); + + public static void register(Object key, String name, Function f) { + MapList fmap = map.get(key); + if (fmap == null) { + fmap = new MapList<>(); + map.put(key, fmap); + } + fmap.add(name, f); + } + + public static void call0 (Object key, String name) { + MapList fmap = map.get(key); + if (fmap == null) + return; + for (Function f : fmap.getValues(name)) { + f.apply(null); + } + } + + + public static void call1 (Object key, String name, Object o1) { + MapList fmap = map.get(key); + if (fmap == null) + return; + for (Function f : fmap.getValues(name)) { + f.apply(o1); + } + } + + public static void call2 (Object key, String name, Object o1, Object o2) { + MapList fmap = map.get(key); + if (fmap == null) + return; + for (Function f : fmap.getValues(name)) { + f.apply(o1,o2); + } + } + + public static void call3 (Object key, String name, Object o1, Object o2, Object o3) { + MapList fmap = map.get(key); + if (fmap == null) + return; + for (Function f : fmap.getValues(name)) { + f.apply(o1,o2,o3); + } + } + + public static void call4 (Object key, String name, Object o1, Object o2, Object o3, Object o4) { + MapList fmap = map.get(key); + if (fmap == null) + return; + for (Function f : fmap.getValues(name)) { + f.apply(o1,o2,o3,o4); + } + } + + public static void clear(Object key) { + map.remove(key); + } + + public static void clear(Object key, String name) { + MapList fmap = map.get(key); + if (fmap == null) + return; + fmap.remove(name); + } + + +}