1 // Created on: 1991-04-16
2 // Created by: Arnaud BOUZY
3 // Copyright (c) 1991-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <Expr_GeneralExpression.hxx>
19 #include <Expr_InvalidOperand.hxx>
20 #include <Expr_NamedUnknown.hxx>
21 #include <Expr_PolyExpression.hxx>
22 #include <Standard_DimensionMismatch.hxx>
23 #include <Standard_NumericError.hxx>
24 #include <Standard_OutOfRange.hxx>
25 #include <Standard_Type.hxx>
27 IMPLEMENT_STANDARD_RTTIEXT(Expr_PolyExpression,Expr_GeneralExpression)
29 Expr_PolyExpression::Expr_PolyExpression()
33 Standard_Integer Expr_PolyExpression::NbOperands () const
35 return myOperands.Length();
38 void Expr_PolyExpression::SetOperand (const Handle(Expr_GeneralExpression)& exp, const Standard_Integer index)
40 Handle(Expr_PolyExpression) me = this;
42 throw Expr_InvalidOperand();
44 if (exp->Contains(me)) {
45 throw Expr_InvalidOperand();
47 myOperands(index) = exp;
50 void Expr_PolyExpression::AddOperand (const Handle(Expr_GeneralExpression)& exp)
52 myOperands.Append(exp);
55 void Expr_PolyExpression::RemoveOperand (const Standard_Integer index)
57 if (myOperands.Length() <= 2) {
58 throw Standard_DimensionMismatch();
60 myOperands.Remove(index);
63 Standard_Integer Expr_PolyExpression::NbSubExpressions () const
68 const Handle(Expr_GeneralExpression)& Expr_PolyExpression::SubExpression (const Standard_Integer I) const
73 Standard_Boolean Expr_PolyExpression::ContainsUnknowns () const
75 Standard_Boolean found = Standard_False;
76 Standard_Integer nbop = NbOperands();
77 Standard_Integer i = 1;
78 Handle(Expr_GeneralExpression) expop;
80 while ((!found) && (i <= nbop)) {
82 found = expop->IsKind(STANDARD_TYPE(Expr_NamedUnknown));
86 while ((!found) && (i <= nbop)) {
88 found = expop->ContainsUnknowns();
94 Standard_Boolean Expr_PolyExpression::Contains (const Handle(Expr_GeneralExpression)& exp) const
96 Standard_Boolean found = Standard_False;
97 Standard_Integer nbop = NbOperands();
98 Standard_Integer i = 1;
99 Handle(Expr_GeneralExpression) expop;
101 while ((!found) && (i <= nbop)) {
103 found = (expop == exp);
107 while ((!found) && (i <= nbop)) {
109 found = expop->Contains(exp);
115 void Expr_PolyExpression::Replace (const Handle(Expr_NamedUnknown)& var, const Handle(Expr_GeneralExpression)& with)
117 Standard_Integer nbop = NbOperands();
119 Handle(Expr_GeneralExpression) expop;
121 for(i=1;i <= nbop; i++) {
127 if (expop->Contains(var)) {
128 expop->Replace(var,with);
135 Handle(Expr_GeneralExpression) Expr_PolyExpression::Simplified() const
137 Handle(Expr_PolyExpression) cop = Handle(Expr_PolyExpression)::DownCast(Copy());
139 Standard_Integer max = cop->NbOperands();
140 Handle(Expr_GeneralExpression) op;
141 for (i=1; i<= max; i++) {
142 op = cop->Operand(i);
143 cop->SetOperand(op->Simplified(),i);
145 return cop->ShallowSimplified();