public void AddReceptor(Receptor.Receptor receptor) { Receptors.Add(receptor); for (int i = 0; i < receptor.Cells.Count; i++) { Cells.Add(receptor.Cells[i]); } }
/// <summary> /// Returns the list of distinct protocols that each receptor instance in the membrane emits. /// </summary> public List <string> GetEmittedProtocols() { List <string> ret = new List <string>(); Receptors.ForEach(r => ret.AddRange(r.Instance.GetEmittedProtocols().Select(p => p.Protocol))); return(ret.Distinct().ToList()); }
/// <summary> /// Returns the list of distinct protocols that each receptor isntance in the membrane can receive. /// </summary> /// <returns></returns> public List <string> GetListeningProtocols() { List <string> ret = new List <string>(); Receptors.ForEach(r => ret.AddRange(r.Instance.GetReceiveProtocols().Select(rp => rp.Protocol))); return(ret.Distinct().ToList()); }
// TODO: Maintain a flat list to avoid this recursion. /// <summary> /// Recurse through membranes to find the membrane containing the desired receptor. /// </summary> public Membrane GetMembraneContaining(IReceptor searchFor) { Membrane ret = null; if (Receptors.Contains((Receptor)searchFor)) { ret = this; } else { foreach (Membrane childMembrane in Membranes) { ret = childMembrane.GetMembraneContaining(searchFor); if (ret != null) { break; } } } return(ret); }
/// <summary> /// Move the receptors in this membrane to the target membrane. /// </summary> /// <param name="targetMembrane"></param> public void MoveReceptorsToMembrane(IMembrane targetMembrane) { Receptors.ForEach(r => MoveReceptorToMembrane(r, targetMembrane)); }
/// <summary> /// Remove this membrane, moving its receptors to the parent. /// </summary> public void Dissolve() { // TODO: To much conversion. MoveReceptorsToMembrane(Receptors.Cast <IReceptor>().ToList(), ParentMembrane); ParentMembrane.Membranes.Remove(this); }
// TODO: Re-implement by providing methods to add/remove instantiated receptors which // would support moving receptors between membranes. This is a brute force approach // for now. /// <summary> /// Recreates the protocol receptor map from scratch. /// </summary> public void ReloadProtocolReceptorMap() { protocolReceptorMap.Clear(); Receptors.ForEach(r => GatherProtocolReceivers(r)); }
/// <summary> /// Reset the receptor system. This allows the current carriers to cleanly terminate /// and then re-initializes the internal collections to an empty state. /// </summary> public void Reset() { Receptors.ForEach(r => r.Instance.Terminate()); Initialize(); }