예제 #1
0
        /// <summary>
        /// Function that receives a <see cref="TypeTypeOperator"/> object and returns the
        /// resulting data type of combining the given types with the given operator.
        /// Called by <see cref="QuadrupleManager"/> to get the resulting data type of two operands
        /// and an operator.
        /// </summary>
        /// <param name="tto"></param>
        /// <returns>A <see cref="SemanticCubeUtilities.DataTypes"/> type.</returns>
        public static SemanticCubeUtilities.DataTypes AnalyzeSemantics(TypeTypeOperator tto)
        {
            // handle the negative operator as a special case since it only uses one operand
            if (tto.GetOperator() == SemanticCubeUtilities.Operators.negative)
            {
                if (Cube.TryGetValue(tto, out SemanticCubeUtilities.DataTypes resultType))
                {
                    return(resultType);
                }
                else
                {
                    return(SemanticCubeUtilities.DataTypes.invalidDataType);
                }
            }

            if (tto.GetDataTypeOne().Equals(SemanticCubeUtilities.DataTypes.invalidDataType) ||
                tto.GetDataTypeTwo().Equals(SemanticCubeUtilities.DataTypes.invalidDataType) ||
                tto.GetOperator().Equals(SemanticCubeUtilities.Operators.invalidOperator))
            {
                return(SemanticCubeUtilities.DataTypes.invalidDataType);
            }

            SemanticCubeUtilities.DataTypes type;
            if (Cube.TryGetValue(tto, out type))
            {
                return(type);
            }
            else
            {
                throw new Exception(String.Format("The specified key <{0},{1},{2}> was not found in the Semantic Cube",
                                                  tto.GetDataTypeOne(), tto.GetDataTypeTwo(), tto.GetOperator()));
            }
        }
예제 #2
0
        /// <summary>
        /// Overrides <see cref="object.Equals(object)"/>'s definition. Two <see cref="TypeTypeOperator"/> objects are equal
        /// if the two hold the same <see cref="SemanticCubeUtilities.DataTypes"/> and the same <see cref="SemanticCubeUtilities.Operators"/>.
        /// Called every time two <see cref="TypeTypeOperator"/> objects are compared in the Semantic Cube.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns>
        /// A boolean stating whether two <see cref="TypeTypeOperator"/> objects are equal or not.
        /// </returns>
        public override bool Equals(object obj)
        {
            TypeTypeOperator tto = obj as TypeTypeOperator;

            return((tto.GetDataTypeOne() == DataTypeOne) &&
                   (tto.GetDataTypeTwo() == DataTypeTwo) &&
                   (tto.GetOperator() == Operator));
        }