/// <summary>
 /// Accepts operation
 /// </summary>
 /// <param name="types">Types of variables</param>
 /// <returns>Object operation</returns>
 public IObjectOperation Accept(object[] types)
 {
     foreach (object o in types)
     {
         if (o is ArrayReturnType)
         {
             return(accept(types));
         }
     }
     return(detector.Accept(types));
 }
Пример #2
0
 /// <summary>
 /// Processes multi operation
 /// </summary>
 /// <param name="formula">Formula</param>
 /// <param name="creator">Formula creator</param>
 /// <returns>True if operation exists and false otherwise</returns>
 protected bool processMultiOperation(MathFormula formula, IFormulaObjectCreator creator)
 {
     for (int n = 0; n < creator.MultiOperationCount; n++)
     {
         IMultiOperationDetector detector = creator.GetMultiOperationDetector(n);
         int j = 0;
         int m = 0;
         int i = 0;
         //int opened = 0;
         int k = 0;
         List <ObjectFormulaTree> list = null;
         for (; i < formula.Count; i++)
         {
             MathSymbol symbol = formula[i];
             if (creator.IsBra(symbol))
             {
                 ++m;
                 continue;
             }
             if (creator.IsKet(symbol))
             {
                 --m;
                 continue;
             }
             if (m != 0)
             {
                 continue;
             }
             if (!detector.Detect(k, symbol))
             {
                 continue;
             }
             if (list == null)
             {
                 list = new List <ObjectFormulaTree>();
             }
             MathFormula f = new MathFormula(formula, j, i - 1);
             list.Add(CreateTree(f, creator));
             ++k;
             j = i + 1;
             if (k == detector.Count)
             {
                 f = new MathFormula(formula, j, formula.Count - 1);
                 list.Add(CreateTree(f, creator));
                 object[] types = new object[list.Count];
                 int      nOp   = 0;
                 foreach (ObjectFormulaTree tree in list)
                 {
                     types[nOp] = tree.ReturnType;
                     ++nOp;
                 }
                 IObjectOperation op = detector.Accept(types);
                 if (op != null)
                 {
                     operation = op;
                     children  = list;
                     y         = new object[list.Count];
                     return(true);
                 }
             }
         }
     }
     return(false);
 }