Example #1
0
        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);
        }
Example #2
0
        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);
        }
Example #3
0
 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));
 }
Example #4
0
        public ISlot Remove(Delegate listener)
        {
            ISlot slot = this.slots.Find(listener);

            if (slot == null)
            {
                return(null);
            }

            this.slots = this.slots.FilterNot(listener);
            return(slot);
        }
Example #5
0
        public void Dispatch(params object[] args)
        {
            SlotList slotsToProcess = this.slots;

            if (slotsToProcess.nonEmpty)
            {
                while (slotsToProcess.nonEmpty)
                {
                    slotsToProcess.Head.Excute(args);
                    slotsToProcess = slotsToProcess.tail;
                }
            }
        }
Example #6
0
        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);
        }
Example #7
0
 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;
     }
 }
Example #8
0
        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);
        }
Example #9
0
 public void RemoveAll()
 {
     this.slots = SlotList.NIL;
 }