public static void View <K, V>(this IViewableMap <K, V> me, Lifetime lifetime, Action <Lifetime, K, V> handler) { var lifetimes = new Dictionary <KeyValuePair <K, V>, LifetimeDefinition>(); me.AdviseAddRemove(lifetime, (kind, key, value) => { var entry = JetKeyValuePair.Of(key, value); switch (kind) { case AddRemove.Add: var def = Lifetime.Define(lifetime); lifetimes.Add(entry, def); handler(def.Lifetime, entry.Key, entry.Value); break; case AddRemove.Remove: def = lifetimes[entry]; lifetimes.Remove(entry); def.Terminate(); break; default: throw new ArgumentOutOfRangeException($"Illegal enum value: {kind}"); } }); }
public static void AddOrReplaceLifetimed <K, V>(this IViewableMap <K, V> me, Lifetime lifetime, K k, Func <Lifetime, V> vfun) { var def = lifetime.CreateNested(); me[k] = vfun(def.Lifetime); me.Change.Advise(def.Lifetime, _event => { if (_event.Key.Equals(k)) { def.Terminate(); } }); }
public static void FlowInto <K, V>(this IViewableMap <K, V> me, Lifetime lifetime, IDictionary <K, V> storage) { me.Advise(lifetime, e => { switch (e.Kind) { case AddUpdateRemove.Add: case AddUpdateRemove.Update: storage[e.Key] = e.NewValue; break; case AddUpdateRemove.Remove: storage.Remove(e.Key); break; default: throw new ArgumentOutOfRangeException($"Unexpected kind: {e.Kind}"); } }); }
public static void AdviseAddRemove <K, V>(this IViewableMap <K, V> me, Lifetime lifetime, Action <AddRemove, K, V> handler) { me.Advise(lifetime, e => { switch (e.Kind) { case AddUpdateRemove.Add: handler(AddRemove.Add, e.Key, e.NewValue); break; case AddUpdateRemove.Update: handler(AddRemove.Remove, e.Key, e.OldValue); handler(AddRemove.Add, e.Key, e.NewValue); break; case AddUpdateRemove.Remove: handler(AddRemove.Remove, e.Key, e.OldValue); break; default: throw new ArgumentOutOfRangeException("" + e.Kind); } }); }
public static void View <K, V>(this IViewableMap <K, V> me, Lifetime lifetime, Action <Lifetime, KeyValuePair <K, V> > handler) { View(me, lifetime, (lf, k, v) => handler(lf, JetKeyValuePair.Of(k, v))); }
public RdPerClientIdMap(Func <bool, V> valueFactory) { myValueFactory = valueFactory; myMap = new ViewableMap <ClientId, V>(); }
public RdPerContextMap(RdContext <K> context, Func <bool, V> valueFactory) { myValueFactory = valueFactory; Context = context; myMap = new ViewableMap <K, V>(); }