0026936: Drawbacks of inlining in new type system in OCCT 7.0 -- automatic
[occt.git] / src / Expr / Expr_NamedFunction.cxx
1 // Created on: 1991-06-26
2 // Created by: Arnaud BOUZY
3 // Copyright (c) 1991-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <Expr.hxx>
19 #include <Expr_FunctionDerivative.hxx>
20 #include <Expr_GeneralExpression.hxx>
21 #include <Expr_GeneralFunction.hxx>
22 #include <Expr_NamedConstant.hxx>
23 #include <Expr_NamedFunction.hxx>
24 #include <Expr_NamedUnknown.hxx>
25 #include <Expr_NotEvaluable.hxx>
26 #include <Expr_NumericValue.hxx>
27 #include <Standard_DimensionMismatch.hxx>
28 #include <Standard_NumericError.hxx>
29 #include <Standard_OutOfRange.hxx>
30 #include <Standard_Type.hxx>
31 #include <TCollection_AsciiString.hxx>
32
33 IMPLEMENT_STANDARD_RTTIEXT(Expr_NamedFunction,Expr_GeneralFunction)
34
35 Expr_NamedFunction::Expr_NamedFunction (const TCollection_AsciiString& name, const Handle(Expr_GeneralExpression)& exp, const Expr_Array1OfNamedUnknown& vars) : 
36                                  myVariables(vars.Lower(),vars.Upper())
37 {
38   myVariables=vars;
39   myName = name;
40   myExp = exp;
41 }
42
43 void Expr_NamedFunction::SetName(const TCollection_AsciiString& newname)
44 {
45   myName = newname;
46 }
47
48 TCollection_AsciiString Expr_NamedFunction::GetName () const
49 {
50   return myName;
51 }
52
53 Standard_Integer Expr_NamedFunction::NbOfVariables () const
54 {
55   return myVariables.Length();
56 }
57
58 Handle(Expr_NamedUnknown) Expr_NamedFunction::Variable (const Standard_Integer index) const
59 {
60   return myVariables(index);
61 }
62
63 Standard_Real Expr_NamedFunction::Evaluate (const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& values) const
64 {
65   if (vars.Length() != values.Length()) {
66     Standard_OutOfRange::Raise();
67   }
68   return myExp->Evaluate(vars,values);
69 }
70
71
72 Handle(Expr_GeneralFunction) Expr_NamedFunction::Copy () const
73 {
74   return new Expr_NamedFunction(myName,Expr::CopyShare(Expression()),myVariables);
75 }
76
77 Handle(Expr_GeneralFunction) Expr_NamedFunction::Derivative(const Handle(Expr_NamedUnknown)& var) const
78 {
79   Handle(Expr_NamedFunction) me = this;
80   return new Expr_FunctionDerivative(me,var,1);
81 }
82
83 Handle(Expr_GeneralFunction) Expr_NamedFunction::Derivative(const Handle(Expr_NamedUnknown)& var, const Standard_Integer deg) const
84 {
85   Handle(Expr_NamedFunction) me = this;
86   return new Expr_FunctionDerivative(me,var,deg);
87 }
88
89 Standard_Boolean Expr_NamedFunction::IsIdentical (const Handle(Expr_GeneralFunction)& func) const
90 {
91   if (!func->IsKind(STANDARD_TYPE(Expr_NamedFunction))) {
92     return Standard_False;
93   }
94   if (myName != Handle(Expr_NamedFunction)::DownCast(func)->GetName()) {       
95     return Standard_False;
96   }
97   Standard_Integer nbvars = NbOfVariables();
98   if (nbvars != func->NbOfVariables()) {
99     return Standard_False;
100   }
101   Handle(Expr_NamedUnknown) thisvar;
102   for (Standard_Integer i =1; i<=nbvars; i++) {
103     thisvar = Variable(i);
104     if (!thisvar->IsIdentical(func->Variable(i))) {
105       return Standard_False;
106     }
107   }
108   if (!Expression()->IsIdentical(Handle(Expr_NamedFunction)::DownCast(func)->Expression())) {
109     return Standard_False;
110   }
111   return Standard_True;
112 }
113
114 Standard_Boolean Expr_NamedFunction::IsLinearOnVariable(const Standard_Integer) const
115 {
116   // bad implementation, should be improved
117   return myExp->IsLinear();
118 }
119
120 TCollection_AsciiString Expr_NamedFunction::GetStringName() const
121 {
122   return myName;
123 }
124
125 Handle(Expr_GeneralExpression) Expr_NamedFunction::Expression() const
126 {
127   return myExp;
128 }
129
130 void Expr_NamedFunction::SetExpression(const Handle(Expr_GeneralExpression)& anexp)
131 {
132   myExp = anexp;
133 }