예제 #1
0
        /// <summary>
        /// Removes a port from some ring of ports of some capsule.
        /// </summary>
        /// <param name="port">the port</param>
        /// <param name="ring">the ring</param>
        private static void DisassociatePort(Port <TContent, TPort> port, LinkRingX <TContent, TPort> ring)
        {
            int position;

            port.Links.ExtractNode(port.Links.Size).GetContainerX(out position);
            ring.DeleteNode(position);
        }
예제 #2
0
 public override void InitFrom(Capsule <TContent, TPort> cap)
 {
     base.InitFrom(cap);
     SubCapsRing           = cap.SubCapsRing;
     SubCapsRing.Container = this;
     InPorts            = cap.InPorts;
     InPorts.Container  = this;
     OutPorts           = cap.OutPorts;
     OutPorts.Container = this;
 }
예제 #3
0
        /// <summary>
        /// Finds the capsule of some level, that some port (I or O) points to.
        /// </summary>
        /// <param name="ring">The list of ports.</param>
        /// <param name="portNum">The port number.</param>
        /// <param name="capLevel">The level of the capsule to find.</param>
        /// <returns>A reference to the pointed capsule.</returns>
        public Capsule <TContent, TPort> GetPointedCapsule(LinkRingX <TContent, TPort> ring, int portNum, int capLevel)
        {
            if (portNum > ring.Size)
            {
                return(null);
            }
            var port = GetPort(ring, portNum).Points;

            if (port == null || capLevel > port.Links.Size)
            {
                return(null);
            }
            return(port.Links.GetNode(capLevel).GetContainerX());
        }
예제 #4
0
        /// <summary>
        /// Weaves a port throuth some ring of ports of some capsule.
        /// </summary>
        /// <param name="port">the port</param>
        /// <param name="level">the capsule's level</param>
        /// <param name="ring">the ring</param>
        /// <param name="cap">the capsule which contains the ring</param>
        private static void AssociatePort(Port <TContent, TPort> port, int level, ref LinkRingX <TContent, TPort> ring, Capsule <TContent, TPort> cap)
        {
            if (ring == null)
            {
                ring = new LinkRingX <TContent, TPort>(cap);
            }
            else
            {
                ring.AddNodeToEnd(new Link <TContent, TPort>());
            }
            Link <TContent, TPort> ringLink = ring.GetNode(ring.Size);

            port.Links.InsertNode(ringLink, level);
        }
예제 #5
0
        /// <summary>
        /// Add a port at the final position in the ring of input or output ports
        /// (Only the content should be allowed to use this function).
        /// </summary>
        /// <param name="ring">The ring of ports.</param>
        /// <param name="data">The data going through the port.</param>
        public void AddLastPort(ref LinkRingX <TContent, TPort> ring, TPort data = null)
        {
            var port = new Port <TContent, TPort>(data);
            Link <TContent, TPort> node = port.Links.GetNode(0);

            if (ring == null)
            {
                ring = new LinkRingX <TContent, TPort>(this, node);
            }
            else
            {
                ring.AddNodeToEnd(node);
            }
        }
예제 #6
0
        /// <summary>
        /// Replaces some subcapsule with another capsule (presumes that the number of input and output ports
        /// of each capsule is the same accordingly. The correspondance of ports is given by the array parameter).
        /// </summary>
        /// <param name="oldCapNum">The position of the capsule which is replaced.</param>
        /// <param name="newCap">The new capsule.</param>
        /// <param name="cor">The correspondance of port numbers.</param>
        public void ReplaceCapsule(int oldCapNum, Capsule <TContent, TPort> newCap, int[] cor)
        {
            Capsule <TContent, TPort> cap = SubCapsRing.GetNode(oldCapNum);

            // Glue the new port structure into place.
            LinkRingX <TContent, TPort> ring1 = cap.InPorts,
                                        ring2 = newCap.InPorts;

            /*
             * for (int j = 0; j <= 1; j++)
             * {
             *  for (int i = 1; i <= ring1.Size; i++)
             *  {
             *      IVLink link1 = ring1.GetNode(i);
             *      IVLink link2 = link1.Down;
             *      link1.Down = null;
             *      link2.Up = null;
             *      do link1 = link1.Up;
             *      while (link1.GetType() != typeof(Port<Link<TContent, TData>, TData>));
             *      link1.Down.Up = null;
             *      link1.Down = null;
             *      IVLink link3 = ring2.GetNode(cor[i]);
             *      IVLink link4 = link3;
             *      while (link3.Up != null) link3 = link3.Up;
             *      link1.Down = link3;
             *      link3.Up = link1;
             *      link4.Down = link2;
             *      link2.Up = link4;
             *  }
             *  ring1 = cap.OutPorts;
             *  ring2 = newCap.OutPorts;
             * }
             */
            // Discart the old capsule structure.
            if (!cap.Empty())
            {
                cap.SubCapsRing.Container = null;
            }
            cap.SubCapsRing = newCap.SubCapsRing;
            if (!newCap.Empty())
            {
                newCap.SubCapsRing.Container = cap;
            }
            cap.Data = newCap.Data;
        }
예제 #7
0
 private static void CapPorts(LinkRingX <TContent, TPort> capRing, Capsule <TContent, TPort> capCont, ref LinkRingX <TContent, TPort> associateRing, LinkRingX <TContent, TPort> disassociateRing, CapPort capAction)
 {
     if (capRing == null)
     {
         return;
     }
     for (int j = 1; j <= capRing.Size; j++)
     {
         int level;
         Port <TContent, TPort> maxCapPort, capPort = GetPort(capRing, j, out level);
         if ((maxCapPort = capPort.Points) == null)
         {
             continue;
         }
         Capsule <TContent, TPort> maxCap = maxCapPort.Links.GetNode(maxCapPort.Links.Size).GetContainerX();
         capAction(maxCap, capCont, maxCapPort, level, capPort, ref associateRing, disassociateRing);
     }
 }
예제 #8
0
        /// <summary>
        /// Produces a deep-copy of the capsule without the external ports.
        /// </summary>
        /// <returns>A copy of the capsule.</returns>
        public Capsule <TContent, TPort> DeepClone()
        {
            Capsule <TContent, TPort> clone = base.Clone();
            int i;

            // Create the input and output ports collections of the clone as of equal length to the prototypes.
            if (InPorts != null && InPorts.Size != 0)
            {
                clone.InPorts = new LinkRingX <TContent, TPort>(clone);
                for (i = 2; i <= InPorts.Size; i++)
                {
                    clone.InPorts.AddNodeToEnd(new Link <TContent, TPort>());
                }
            }
            if (OutPorts != null && OutPorts.Size != 0)
            {
                clone.OutPorts = new LinkRingX <TContent, TPort>(clone);
                for (i = 2; i <= OutPorts.Size; i++)
                {
                    clone.OutPorts.AddNodeToEnd(new Link <TContent, TPort>());
                }
            }
            // Copy the inner structure of the capsule if any.
            if (Empty())
            {
                return(clone);
            }

            // Clone the head of the ring of subcapsules.
            clone.SubCapsRing = new ExtendedDataRing <Capsule <TContent, TPort>, HeadCapsule <TContent, TPort>, TContent, Capsule <TContent, TPort> >(clone, SubCapsRing.GetNode(1).DeepClone());

            // Clone the rest of the subcapsules.
            for (i = 2; i <= SubCapsRing.Size; i++)
            {
                clone.SubCapsRing.InsertNode(SubCapsRing.GetNode(i).DeepClone(), i);
            }

            // Copy the connections between the subcapsules,
            for (i = 1; i <= SubCapsRing.Size; i++)
            {
                // for each subcapsule,
                Capsule <TContent, TPort> cap1 = SubCapsRing.GetNode(i),
                                          cap2 = clone.SubCapsRing.GetNode(i);

                // for the input & output ports of it respectively,
                LinkRingX <TContent, TPort> ring1 = cap1.InPorts,
                                            ring2 = cap2.InPorts,
                                            ring3 = clone.InPorts;

                /*
                 * for (int m = 0; m <= 1; m++)
                 * {
                 *  // for each port,
                 *  for (int j = 1; j <= ring1.Size; j++)
                 *  {
                 *      IVLink link1 = ring1.GetNode(j),
                 *             link4 = link1;
                 *      do link1 = link1.Up;
                 *      while (link1.GetType() != typeof(Port<Link<TContent, TData>, TData>));
                 *      var port1 = (Port<Link<TContent, TData>, TData>)link1;
                 *
                 *      // if the port points to another port,
                 *      if (port1.Points == null) continue;
                 *      port1 = port1.Points;
                 *      IVLink link2 = port1.Up;
                 *      int l;
                 *      Capsule<TContent, TData> cap3 = ((Link<TContent, TData>)link2).GetContainer(out l);
                 *      link1 = ring2.GetNode(j);
                 *
                 *      // check whether the capsule, that the port points to, belongs to the subcapsules
                 *      // of the containing capsule, that has called 'clone' last at the recursion hierarchy,
                 *      IVLink link5;
                 *      int k;
                 *      if (cap3.GetContainer() != this)
                 *      {
                 *          // if not, add this port to the external ports of the containing capsule,
                 *          link4 = link4.Down;
                 *          ((Link<TContent, TData>)link4).GetContainer(out k);
                 *          link5 = ring3.GetNode(k);
                 *          link5.Up = link1;
                 *          link1.Down = link5;
                 *      }
                 *      else
                 *      {
                 *          // else create a new port for each of the two subcapsules and link them,
                 *          cap3.GetContainer(out k);
                 *          cap3 = clone.SubCapsRing.GetNode(k);
                 *          link5 = cap3.OutPorts.GetNode(l);
                 *
                 *          // check if this pair of ports has been fixed allready.
                 *          if (link5.Down != null) continue;
                 *          var port2 = new Port<Link<TContent, TData>, TData>(port1.Data);
                 *          link5.Down = port2;
                 *          while (link5.Up != null) link5 = link5.Up;
                 *          link5.Up = port2;
                 *          port2.Down = link5;
                 *          var port3 = new Port<Link<TContent, TData>, TData>(port1.Data);
                 *          link1.Down = port3;
                 *          while (link1.Up != null) link1 = link1.Up;
                 *          link1.Up = port3;
                 *          port3.Down = link1;
                 *          port2.Points = port3;
                 *      }
                 *  }
                 *  ring1 = cap1.OutPorts;
                 *  ring2 = cap2.OutPorts;
                 *  ring3 = clone.OutPorts;
                 * }*/
            }
            return(clone);
        }
예제 #9
0
 private static void UnCupPort(Capsule <TContent, TPort> maxCap, Capsule <TContent, TPort> capCont, Port <TContent, TPort> maxCapPort, int level, Port <TContent, TPort> capPort, ref LinkRingX <TContent, TPort> associateRing, LinkRingX <TContent, TPort> disassociateRing)
 {
     if (maxCap.GetContainer() == capCont)
     {
         AssociatePort(maxCapPort, level + 1, ref associateRing, capCont);
     }
     else
     {
         DisassociatePort(capPort, disassociateRing);
     }
 }
예제 #10
0
 private static void UnCapPorts(LinkRingX <TContent, TPort> capRing, Capsule <TContent, TPort> capCont, ref LinkRingX <TContent, TPort> associateRing, LinkRingX <TContent, TPort> disassociateRing)
 {
     CapPorts(capRing, capCont, ref associateRing, disassociateRing, UnCapPortDel);
 }
예제 #11
0
 /// <summary>
 /// Get the port at position <param name="portNum"></param> of input or output ring.
 /// </summary>
 /// <param name="ring">the ring of ports</param>
 /// <param name="portNum">he port position inside the ring of ports</param>
 /// <returns>the port</returns>
 private static Port <TContent, TPort> GetPort(LinkRingX <TContent, TPort> ring, int portNum)
 {
     return(ring.GetNode(portNum).GetContainerY());
 }