public SlotList FilterNot(Delegate listener) { if (!this.nonEmpty || listener == null) { return(this); } if (listener == Head.Listener) { return(this.tail); } SlotList wholeClone = new SlotList(this.Head); SlotList subClone = wholeClone; SlotList current = this.tail; while (current.nonEmpty) { if (current.Head.Listener == listener) { subClone.tail = current.tail; return(wholeClone); } subClone = subClone.tail = new SlotList(current.Head); current = current.tail; } return(this); }
public SlotList Append(ISlot slot) { if (slot == null) { return(this); } if (!nonEmpty) { return(new SlotList(slot)); } if (this.tail == NIL) { return(new SlotList(slot).Prepend(this.Head)); } SlotList wholeClone = new SlotList(this.Head); SlotList subClone = wholeClone; SlotList current = this.tail; while (current.nonEmpty) { subClone = subClone.tail = new SlotList(current.Head); current = current.tail; } subClone.tail = new SlotList(slot); return(wholeClone); }
protected ISlot RegisterListener(Delegate listener, bool once = false) { if (this.RegisterPossible(listener, once)) { ISlot newSlot = new Slot(listener, this, once); slots = slots.Prepend(newSlot); return(newSlot); } return(this.slots.Find(listener)); }
public ISlot Remove(Delegate listener) { ISlot slot = this.slots.Find(listener); if (slot == null) { return(null); } this.slots = this.slots.FilterNot(listener); return(slot); }
public void Dispatch(params object[] args) { SlotList slotsToProcess = this.slots; if (slotsToProcess.nonEmpty) { while (slotsToProcess.nonEmpty) { slotsToProcess.Head.Excute(args); slotsToProcess = slotsToProcess.tail; } } }
public bool Contains(Delegate listener) { if (!this.nonEmpty) { return(false); } SlotList p = this; while (p.nonEmpty) { if (p.Head.Listener == listener) { return(true); } } return(false); }
public SlotList(ISlot head, SlotList tail = null) { if (head == null && tail == null) { nonEmpty = false; } else if (head == null) { throw new Exception("param head cannot be null"); } else { this.Head = head; this.tail = tail == null ? NIL : tail; this.nonEmpty = true; } }
public ISlot Find(Delegate listener) { if (!nonEmpty) { return(null); } SlotList p = this; while (p.nonEmpty) { if (p.Head.Listener == listener) { return(p.Head); } p = p.tail; } return(null); }
public void RemoveAll() { this.slots = SlotList.NIL; }