blob: edfba2d507df03429a90bf61be28e757544ddc83 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
//static const char* sccsid = "@(#)Expr_PolyExpression.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: Matra-Datavision 1991
// File: Expr_PolyExpression.cxx
// Created: Tue Apr 16 09:55:23 1991
// Author: Arnaud BOUZY
// <adn>
#include <Expr_PolyExpression.ixx>
#include <Expr_NamedUnknown.hxx>
#include <Expr_InvalidOperand.hxx>
#include <Standard_OutOfRange.hxx>
#include <Standard_DimensionMismatch.hxx>
Expr_PolyExpression::Expr_PolyExpression()
{
}
Standard_Integer Expr_PolyExpression::NbOperands () const
{
return myOperands.Length();
}
void Expr_PolyExpression::SetOperand (const Handle(Expr_GeneralExpression)& exp, const Standard_Integer index)
{
Handle(Expr_PolyExpression) me = this;
if (exp == me) {
Expr_InvalidOperand::Raise();
}
if (exp->Contains(me)) {
Expr_InvalidOperand::Raise();
}
myOperands(index) = exp;
}
void Expr_PolyExpression::AddOperand (const Handle(Expr_GeneralExpression)& exp)
{
myOperands.Append(exp);
}
void Expr_PolyExpression::RemoveOperand (const Standard_Integer index)
{
if (myOperands.Length() <= 2) {
Standard_DimensionMismatch::Raise();
}
myOperands.Remove(index);
}
Standard_Integer Expr_PolyExpression::NbSubExpressions () const
{
return NbOperands();
}
const Handle(Expr_GeneralExpression)& Expr_PolyExpression::SubExpression (const Standard_Integer I) const
{
return Operand(I);
}
Standard_Boolean Expr_PolyExpression::ContainsUnknowns () const
{
Standard_Boolean found = Standard_False;
Standard_Integer nbop = NbOperands();
Standard_Integer i = 1;
Handle(Expr_GeneralExpression) expop;
while ((!found) && (i <= nbop)) {
expop = Operand(i);
found = expop->IsKind(STANDARD_TYPE(Expr_NamedUnknown));
i++;
}
i = 1;
while ((!found) && (i <= nbop)) {
expop = Operand(i);
found = expop->ContainsUnknowns();
i++;
}
return found;
}
Standard_Boolean Expr_PolyExpression::Contains (const Handle(Expr_GeneralExpression)& exp) const
{
Standard_Boolean found = Standard_False;
Standard_Integer nbop = NbOperands();
Standard_Integer i = 1;
Handle(Expr_GeneralExpression) expop;
while ((!found) && (i <= nbop)) {
expop = Operand(i);
found = (expop == exp);
i++;
}
i = 1;
while ((!found) && (i <= nbop)) {
expop = Operand(i);
found = expop->Contains(exp);
i++;
}
return found;
}
void Expr_PolyExpression::Replace (const Handle(Expr_NamedUnknown)& var, const Handle(Expr_GeneralExpression)& with)
{
Standard_Integer nbop = NbOperands();
Standard_Integer i;
Handle(Expr_GeneralExpression) expop;
for(i=1;i <= nbop; i++) {
expop = Operand(i);
if (expop == var) {
SetOperand(with,i);
}
else {
if (expop->Contains(var)) {
expop->Replace(var,with);
}
}
}
}
Handle(Expr_GeneralExpression) Expr_PolyExpression::Simplified() const
{
Handle(Expr_PolyExpression) cop = Handle(Expr_PolyExpression)::DownCast(Copy());
Standard_Integer i;
Standard_Integer max = cop->NbOperands();
Handle(Expr_GeneralExpression) op;
for (i=1; i<= max; i++) {
op = cop->Operand(i);
cop->SetOperand(op->Simplified(),i);
}
return cop->ShallowSimplified();
}
|