protected ExtendedFormulaCreator(IVariableDetector detector) : base(detector, false) { opDetectors = new IOperationDetector[] { new OneVariableFunctionDetector(detector), new ExtendedOperationDetector(detector, this) //, /*!!! new Func.FuncDetector(detector) */ }; ElementaryBinaryDetector plus = new ElementaryBinaryDetector('+'); plus.Add(StringConcatOperation.Object); /// Has higher priority than other '+'-type operators, causes a bug plus.Add(StringObjectConcatOperation.Object); LikeOperation like = new LikeOperation(); like.Add(LikeObjectOperation.Object); detectors = new IBinaryDetector[] { new LogicalDetector('\u2217'), new LogicalDetector('\u2216'), new LogicalDetector('\u8835'), LogicalEqualityDetector.Object, new BitDetector('|'), new BitDetector('&'), new BitDetector('^'), new BitDetector('\u2266'), new BitDetector('\u2267'), ComparationDetector.Object, like, RealMatrixBinary.Singleton, RealVectorBinary.Singleton, plus, new ElementaryBinaryDetector('-'), RealMatrixMultiplication.Singleton, new ElementaryBinaryDetector('*'), new ElementaryDivisionDetector('/'), new ElementaryDivisionDetector('﹪'), Vector3DProduct.Object, WhereDetector.Singleton, OrderByDetector.Singleton, AverageDetector.Singleton }; }
void IFormulaObjectCreator.Add(IBinaryDetector binaryDetector) { List <IBinaryDetector> b = detectors.ToList(); b.Add(binaryDetector); detectors = b.ToArray(); }
void IFormulaObjectCreator.Add(IBinaryDetector binaryDetector) { binary.Add(binaryDetector); }
/// <summary> /// Adds binary detector /// </summary> /// <param name="detector">Detector to add</param> public void AddBinaryDetector(IBinaryDetector detector) { binary.Add(detector); }
/// <summary> /// Constructor /// </summary> /// <param name="detector">Prototype detector</param> public BinaryArrayOperationDetector(IBinaryDetector detector) { this.detector = detector; }
/// <summary> /// Processes binary operation /// </summary> /// <param name="formula">Input formula</param> /// <param name="creator">Creator of tree</param> protected bool processBinary(MathFormula formula, IFormulaObjectCreator creator) { Dictionary <int, ObjectFormulaTree[]> dic = new Dictionary <int, ObjectFormulaTree[]>(); for (int i = 0; i < creator.BinaryCount; i++) { IBinaryDetector detector = creator.GetBinaryDetector(i); ObjectFormulaTree tA = null; ObjectFormulaTree tB = null; if (detector.AssociationDirection == BinaryAssociationDirection.LeftRight) { int m = 0; for (int j = 0; j < formula.Count - 1; j++) { MathSymbol symbol = formula[j]; if (creator.IsBra(symbol)) { ++m; continue; } if (creator.IsKet(symbol)) { --m; continue; } if (m < 0) { //FormulaEditorPerformer.ThrowErrorException(FormulaTree.ERRORS[1]); } if (j == 0 | m != 0) { continue; } IBinaryAcceptor acceptor = detector.Detect(symbol); if (acceptor == null) { continue; } if (dic.ContainsKey(j)) { tA = dic[j][0]; tB = dic[j][1]; } else { tA = CreateTree(new MathFormula(formula, 0, j - 1), creator); tB = CreateTree(new MathFormula(formula, j + 1, formula.Count - 1), creator); if ((tA == null) | (tB == null)) { continue; } dic[j] = new ObjectFormulaTree[] { tA, tB }; } if (acceptor is IChildTreeCreator) { IChildTreeCreator cc = acceptor as IChildTreeCreator; ObjectFormulaTree t = cc[new ObjectFormulaTree[] { tA, tB }]; if (t != null) { Copy(t); y = new object[children.Count]; return(true); } } operation = acceptor.Accept(tA.ReturnType, tB.ReturnType); if (operation != null) { goto start; } } } else { int m = 0; for (int j = formula.Count - 1; j > 0; j--) { MathSymbol symbol = formula[j]; if (creator.IsKet(symbol)) { ++m; continue; } if (creator.IsBra(symbol)) { --m; continue; } if (m < 0) { //!!! FormulaEditorPerformer.ThrowErrorException(FormulaTree.ERRORS[1]); } if (m != 0) { continue; } IBinaryAcceptor acceptor = detector.Detect(symbol); if (acceptor == null) { continue; } if (dic.ContainsKey(j)) { tA = dic[j][0]; tB = dic[j][1]; } else { tA = CreateTree(new MathFormula(formula, 0, j - 1), creator); tB = CreateTree(new MathFormula(formula, j + 1, formula.Count - 1), creator); if ((tA == null) | (tB == null)) { continue; } dic[j] = new ObjectFormulaTree[] { tA, tB }; } if (acceptor is IChildTreeCreator) { IChildTreeCreator cc = acceptor as IChildTreeCreator; ObjectFormulaTree t = cc[new ObjectFormulaTree[] { tA, tB }]; if (t != null) { Copy(t); y = new object[children.Count]; return(true); } } operation = acceptor.Accept(tA.ReturnType, tB.ReturnType); if (operation != null) { goto start; } } } start: if (operation != null) { children.Add(tA); children.Add(tB); y = new object[2]; return(true); } } return(false); }
/// <summary> /// Adds detector /// </summary> /// <param name="detector">Detector for adding</param> static public void Add(this IBinaryDetector detector) { binary.Add(detector); }