示例#1
0
        /// <summary>
        /// Internal initialization method.
        /// </summary>
        private void Init(SMOperatorType operatorType, ISMState[] inclStates, SMOperator[] inclOperators)
        {
            this.operatorType = operatorType;

            int numOfOperands = 0;

            this.includedStates = new RCSet <ISMState>();
            if (null != inclStates)
            {
                foreach (ISMState state in inclStates)
                {
                    if (!this.includedStates.Add(state))
                    {
                        throw new SMException("Duplicated operands!");
                    }
                }
                numOfOperands += this.includedStates.Count;
            }
            this.includedOperators = new RCSet <SMOperator>();
            if (null != inclOperators)
            {
                foreach (SMOperator op in inclOperators)
                {
                    if (!this.includedOperators.Add(op))
                    {
                        throw new SMException("Duplicated operands!");
                    }
                }
                numOfOperands += this.includedOperators.Count;
            }

            if (this.operatorType == SMOperatorType.NOT)
            {
                if (numOfOperands != 1)
                {
                    throw new SMException("A logical NOT operator must have exactly 1 operand!");
                }
            }
            else
            {
                if (numOfOperands < 1)
                {
                    throw new SMException("A logical AND or OR operator must have at least 1 operand!");
                }
            }
        }
示例#2
0
 /// <summary>
 /// Constructs an operator with the given included operators.
 /// </summary>
 public SMOperator(SMOperatorType operatorType, SMOperator[] includedOperators)
 {
     Init(operatorType, null, includedOperators);
 }
示例#3
0
 /// <summary>
 /// Constructs an operator with the given included states.
 /// </summary>
 public SMOperator(SMOperatorType operatorType, ISMState[] includedStates)
 {
     Init(operatorType, includedStates, null);
 }
示例#4
0
 /// <summary>
 /// Constructs an operator with the given included states and other operators.
 /// </summary>
 public SMOperator(SMOperatorType operatorType, ISMState[] includedStates, SMOperator[] includedOperators)
 {
     Init(operatorType, includedStates, includedOperators);
 }