0554f54dbfc655dce8ffa4b7e9abf06de0a24a4f
[occt.git] / src / Expr / Expr_UnaryExpression.cxx
1 //static const char* sccsid = "@(#)Expr_UnaryExpression.cxx     3.2 95/01/10"; // Do not delete this line. Used by sccs.
2 // Copyright:   Matra-Datavision 1991
3 // File:        Expr_UnaryExpression.cxx
4 // Created:     Mon Apr 15 14:24:44 1991
5 // Author:      Arnaud BOUZY
6 //              <adn>
7
8 #include <Expr_UnaryExpression.ixx>
9 #include <Expr_NamedUnknown.hxx>
10 #include <Expr_InvalidOperand.hxx>
11 #include <Standard_OutOfRange.hxx>
12
13 void Expr_UnaryExpression::SetOperand (const Handle(Expr_GeneralExpression)& exp)
14 {
15   Handle(Expr_UnaryExpression) me = this;
16   if (exp == me) {
17     Expr_InvalidOperand::Raise();
18   }
19   if (exp->Contains(me)) {
20     Expr_InvalidOperand::Raise();
21   }
22   myOperand = exp;
23 }
24
25 void Expr_UnaryExpression::CreateOperand (const Handle(Expr_GeneralExpression)& exp)
26 {
27   myOperand = exp;
28 }
29
30 Standard_Integer Expr_UnaryExpression::NbSubExpressions () const
31 {
32   return 1;
33 }
34
35 const Handle(Expr_GeneralExpression)& Expr_UnaryExpression::SubExpression (const Standard_Integer I) const
36 {
37   if (I != 1) {
38     Standard_OutOfRange::Raise();
39   }
40   return myOperand;
41 }
42
43 Standard_Boolean Expr_UnaryExpression::ContainsUnknowns () const
44 {
45   if (!myOperand->IsKind(STANDARD_TYPE(Expr_NamedUnknown))) {
46     return myOperand->ContainsUnknowns();
47   }
48   return Standard_True;
49 }
50
51 Standard_Boolean Expr_UnaryExpression::Contains (const Handle(Expr_GeneralExpression)& exp) const
52 {
53   if (myOperand != exp) {
54     return myOperand->Contains(exp);
55   }
56   return Standard_True;
57 }
58
59 void Expr_UnaryExpression::Replace (const Handle(Expr_NamedUnknown)& var, const Handle(Expr_GeneralExpression)& with)
60 {
61   if (myOperand == var) {
62     SetOperand(with);
63   }
64   else {
65     if (myOperand->Contains(var)) {
66       myOperand->Replace(var,with);
67     }
68   }
69 }
70
71
72 Handle(Expr_GeneralExpression) Expr_UnaryExpression::Simplified() const
73 {
74   Handle(Expr_UnaryExpression) cop = Handle(Expr_UnaryExpression)::DownCast(Copy());
75   Handle(Expr_GeneralExpression) op = cop->Operand();
76   cop->SetOperand(op->Simplified());
77   return cop->ShallowSimplified();
78 }
79