Exemplo n.º 1
0
        /// <summary>
        /// Accepts operation
        /// </summary>
        /// <param name="type">Argument type</param>
        /// <returns>The operation</returns>
        public IObjectOperation Accept(object type)
        {
            IObjectOperation ownOp = acceptor.Accept(type);

            if (ownOp != null)
            {
                return(ownOp);
            }
            if (type is ArrayReturnType)
            {
                ArrayReturnType a = type as ArrayReturnType;
                if (a.IsObjectType)
                {
                    op = acceptor.Accept(a) as IMultiVariableOperation;
                    if (op == null)
                    {
                        return(null);
                    }
                    types = new object[] { type };
                    ArrayOperation.CreateAllArrays(op, types, out y, out yy, out rank, out ranks);
                    returnType = new ArrayReturnType(op.ReturnType, rank, true);
                    return(this);
                }
            }
            return(null);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Calculates result of this operation
 /// </summary>
 public object this[object[] x]
 {
     get
     {
         ArrayOperation.PerformOperation(operation, returnValue as object[], x, yy,
                                         rank.Length, ranks, rank, yt);
         return(returnValue);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Accept operation
        /// </summary>
        /// <param name="types">Types of operands</param>
        /// <returns>Operation</returns>
        public IObjectOperation Accept(object[] types)
        {
            this.types = types;
            if (acceptor is IMultiVariableOperation)
            {
                IMultiVariableOperation ma    = acceptor as IMultiVariableOperation;
                IObjectOperation        ownOp = ma.Accept(types);
                if (ownOp != null)
                {
                    return(ownOp);
                }
            }
            if (types == null)
            {
                return(acceptor.Accept(null));
            }
            object[] t       = new object[types.Length];
            bool     isArray = false;

            for (int i = 0; i < t.Length; i++)
            {
                t[i] = ArrayReturnType.GetBaseType(types[i]);
                if (types[i] is ArrayReturnType)
                {
                    isArray = true;
                }
            }
            IObjectOperation opr = operation.Accept(t);

            if (opr == null)
            {
                return(null);
            }
            if (!isArray)
            {
                return(opr);
            }
            ArrayOperation.CreateAllArrays(opr, types, out y, out yy, out rank, out ranks);
            returnType  = new ArrayReturnType(opr.ReturnType, rank, true);
            returnValue = y;
            if (types != null)
            {
                if (types.Length > 0)
                {
                    yt = new object[types.Length];
                }
            }
            return(this);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Sets unary table on tree
 /// </summary>
 /// <param name="tree">Tree to set unary</param>
 /// <param name="unary">Unary table</param>
 public static void SetUnary(ObjectFormulaTree tree, Dictionary <int, IUnary> unary)
 {
     if (tree.Operation is ElementaryUnaryOperation)
     {
         ElementaryUnaryOperation op = tree.Operation as ElementaryUnaryOperation;
         op.Unary = unary;
     }
     else if (tree.Operation is ArrayOperation)
     {
         ArrayOperation ao = tree.Operation as ArrayOperation;
         if (ao.SingleOperation is ElementaryUnaryOperation)
         {
             ElementaryUnaryOperation eo = ao.SingleOperation as ElementaryUnaryOperation;
             eo.Unary = unary;
         }
     }
     for (int i = 0; i < tree.Count; i++)
     {
         SetUnary(tree[i], unary);
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Gets unary table of tree
        /// </summary>
        /// <param name="tree">The tree</param>
        /// <param name="table">The table</param>
        public static void GetUnaryTable(ObjectFormulaTree tree, Dictionary <int, IUnary> table)
        {
            if (tree.Operation is ElementaryUnaryOperation)
            {
                ElementaryUnaryOperation op = tree.Operation as ElementaryUnaryOperation;
                table[op.index] = op.unary;
            }
            if (tree.Operation is ArrayOperation)
            {
                ArrayOperation   op = tree.Operation as ArrayOperation;
                IObjectOperation so = op.SingleOperation;
                if (so is ElementaryUnaryOperation)
                {
                    ElementaryUnaryOperation sop = so as ElementaryUnaryOperation;
                    table[sop.index] = sop.unary;
                }
            }

            for (int i = 0; i < tree.Count; i++)
            {
                GetUnaryTable(tree[i], table);
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Gets unary indexes of tree
 /// </summary>
 /// <param name="tree">The tree</param>
 /// <param name="list">List of indexes</param>
 public static void GetUnaryIndexes(ObjectFormulaTree tree, List <int> list)
 {
     try
     {
         if (tree.Operation is ElementaryUnaryOperation)
         {
             ElementaryUnaryOperation op = tree.Operation as ElementaryUnaryOperation;
             int indx = op.index;
             if (!list.Contains(indx))
             {
                 list.Add(indx);
             }
         }
         if (tree.Operation is ArrayOperation)
         {
             ArrayOperation   op = tree.Operation as ArrayOperation;
             IObjectOperation so = op.SingleOperation;
             if (so is ElementaryUnaryOperation)
             {
                 ElementaryUnaryOperation sop = so as ElementaryUnaryOperation;
                 int ind = sop.index;
                 if (!list.Contains(ind))
                 {
                     list.Add(ind);
                 }
             }
         }
         for (int i = 0; i < tree.Count; i++)
         {
             GetUnaryIndexes(tree[i], list);
         }
     }
     catch (Exception)
     {
     }
 }