Exemple #1
0
        private static bool IsValid(GateType gateType, int inputCount)
        {
            Tracer.Assert(GateSet.IsValid(gateType));
            switch (gateType)
            {
            case GateType.Nop:
            case GateType.Clock:
                return(inputCount == 0);

            case GateType.Not:
                return(inputCount == 1);

            case GateType.Or:
            case GateType.And:
            case GateType.Xor:
                return(1 < inputCount && inputCount <= LogicCircuit.Gate.MaxInputCount);

            case GateType.Led:
                return(inputCount == 1 || inputCount == 8);

            case GateType.TriState1:
            case GateType.TriState2:
                return(inputCount == 2);

            case GateType.Odd:
            case GateType.Even:
            case GateType.Probe:
                Tracer.Fail();
                return(false);

            default:
                return(false);
            }
        }
Exemple #2
0
 private static Guid GateGuid(GateType gateType, int inputCount, bool invertedOutput)
 {
     Tracer.Assert(gateType != GateType.Nop && GateSet.IsValid(gateType, inputCount) && (!invertedOutput || GateSet.HasOutput(gateType)));
     return(new Guid(0, 0, 0, 0, 0, 0, 0, 0,
                     (byte)(int)gateType,
                     (byte)inputCount,
                     (byte)(invertedOutput ? 1 : 0)
                     ));
 }
Exemple #3
0
        public Gate Gate(Guid gateId)
        {
            Gate gate = this.FindByGateId(gateId);

            if (gate != null)
            {
                return(gate);
            }
            byte[]   id             = gateId.ToByteArray();
            GateType gateType       = (GateType)(int)id[13];
            int      inputCount     = (int)id[14];
            bool     invertedOutput = (id[15] == 0) ? false : true;

            if (GateSet.IsValid(gateType) && GateSet.IsValid(gateType, inputCount) && (!invertedOutput || GateSet.HasOutput(gateType)) && GateSet.GateGuid(gateType, inputCount, invertedOutput) == gateId)
            {
                return(this.Create(gateType, inputCount, invertedOutput));
            }
            return(null);
        }
Exemple #4
0
        public Gate Gate(GateType gateType, int inputCount, bool invertedOutput)
        {
            if (!GateSet.IsValid(gateType))
            {
                throw new ArgumentOutOfRangeException("gateType");
            }
            if (!GateSet.IsValid(gateType, inputCount))
            {
                throw new ArgumentOutOfRangeException("inputCount");
            }
            if (invertedOutput && !GateSet.HasOutput(gateType))
            {
                throw new ArgumentOutOfRangeException("invertedOutput");
            }
            Gate gate = this.FindByGateId(GateSet.GateGuid(gateType, inputCount, invertedOutput));

            if (gate == null)
            {
                return(this.Create(gateType, inputCount, invertedOutput));
            }
            return(gate);
        }
Exemple #5
0
 private static bool HasOutput(GateType gateType)
 {
     Tracer.Assert(GateSet.IsValid(gateType));
     return(gateType != GateType.Nop && gateType != GateType.Led);
 }