0032806: Coding - get rid of unused headers [Contap to Extrema]
[occt.git] / src / Expr / Expr_LogOf10.cxx
1 // Created on: 1991-05-27
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_Division.hxx>
20 #include <Expr_GeneralExpression.hxx>
21 #include <Expr_LogOf10.hxx>
22 #include <Expr_NamedUnknown.hxx>
23 #include <Expr_Operators.hxx>
24 #include <Expr_Product.hxx>
25 #include <Standard_Type.hxx>
26 #include <TCollection_AsciiString.hxx>
27
28 IMPLEMENT_STANDARD_RTTIEXT(Expr_LogOf10,Expr_UnaryExpression)
29
30 Expr_LogOf10::Expr_LogOf10(const Handle(Expr_GeneralExpression)& exp)
31 {
32   CreateOperand(exp);
33 }
34
35 Handle(Expr_GeneralExpression) Expr_LogOf10::ShallowSimplified () const
36 {
37   Handle(Expr_GeneralExpression) myexp = Operand();
38   if (myexp->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
39     Handle(Expr_NumericValue) myNVexp = Handle(Expr_NumericValue)::DownCast(myexp);
40     return new Expr_NumericValue(Log10(myNVexp->GetValue()));
41   }
42   Handle(Expr_LogOf10) me = this;
43   return me;
44 }
45
46 Handle(Expr_GeneralExpression) Expr_LogOf10::Copy () const
47 {
48   return new Expr_LogOf10(Expr::CopyShare(Operand()));
49 }
50
51 Standard_Boolean Expr_LogOf10::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
52 {
53   if (Other->IsKind(STANDARD_TYPE(Expr_LogOf10))) {
54     Handle(Expr_GeneralExpression) myexp = Operand();
55     return myexp->IsIdentical(Other->SubExpression(1));
56   }
57   return Standard_False;
58 }
59
60 Standard_Boolean Expr_LogOf10::IsLinear () const
61 {
62   return !ContainsUnknowns();
63 }
64
65 Handle(Expr_GeneralExpression) Expr_LogOf10::Derivative (const Handle(Expr_NamedUnknown)& X) const
66 {
67   if (!Contains(X)) {
68     return new Expr_NumericValue(0.0);
69   }
70   Handle(Expr_GeneralExpression) myexp = Operand();
71   Handle(Expr_GeneralExpression) myder = myexp->Derivative(X);
72   Standard_Real vlog = Log(10.0);
73   Handle(Expr_NumericValue) vallog = new Expr_NumericValue(vlog);
74   Handle(Expr_Product) theprod = Expr::CopyShare(myexp) * vallog;
75   Handle(Expr_Division) thediv = myder / theprod->ShallowSimplified();
76   return thediv->ShallowSimplified();
77 }
78
79 Standard_Real Expr_LogOf10::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const
80 {
81   return ::Log10(Operand()->Evaluate(vars,vals));
82 }
83
84 TCollection_AsciiString Expr_LogOf10::String() const
85 {
86   TCollection_AsciiString str("log(");
87   str += Operand()->String();
88   str += ")";
89   return str;
90 }