0026377: Passing Handle objects as arguments to functions as non-const reference...
[occt.git] / src / Expr / Expr_NumericValue.cxx
1 // Created on: 1991-03-06
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_GeneralExpression.hxx>
19 #include <Expr_NamedUnknown.hxx>
20 #include <Expr_NumericValue.hxx>
21 #include <Standard_OutOfRange.hxx>
22 #include <Standard_Type.hxx>
23 #include <TCollection_AsciiString.hxx>
24
25 #include <stdio.h>
26 IMPLEMENT_STANDARD_RTTIEXT(Expr_NumericValue,Expr_GeneralExpression)
27
28 Expr_NumericValue::Expr_NumericValue(const Standard_Real val)
29 {
30   myValue = val;
31 }
32
33 Standard_Real Expr_NumericValue::GetValue() const
34 {
35   return myValue;
36 }
37
38 void Expr_NumericValue::SetValue(const Standard_Real val)
39 {
40   myValue = val;
41 }
42
43 Standard_Integer Expr_NumericValue::NbSubExpressions() const
44 {
45   return 0;
46 }
47
48 const Handle(Expr_GeneralExpression)& Expr_NumericValue::SubExpression(const Standard_Integer) const
49 {
50   Standard_OutOfRange::Raise();
51   Handle(Expr_GeneralExpression)* bid=NULL;
52   return *bid;
53 }
54
55 Handle(Expr_GeneralExpression) Expr_NumericValue::Simplified() const
56 {
57   return Copy();
58 }
59
60 Handle(Expr_GeneralExpression) Expr_NumericValue::Copy() const
61 {
62   return new Expr_NumericValue(myValue);
63 }
64
65 Standard_Boolean Expr_NumericValue::ContainsUnknowns () const
66 {
67   return Standard_False;
68 }
69
70 Standard_Boolean Expr_NumericValue::Contains (const Handle(Expr_GeneralExpression)& ) const
71 {
72   return Standard_False;
73 }
74
75 Standard_Boolean Expr_NumericValue::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
76 {
77   if (!Other->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
78     return Standard_False;
79   }
80   Handle(Expr_NumericValue) NVOther = Handle(Expr_NumericValue)::DownCast(Other);
81   return (myValue == NVOther->GetValue());
82 }
83
84 Standard_Boolean Expr_NumericValue::IsLinear () const
85 {
86   return Standard_True;
87 }
88
89 Handle(Expr_GeneralExpression) Expr_NumericValue::Derivative (const Handle(Expr_NamedUnknown)& ) const
90 {
91   return new Expr_NumericValue(0.0);
92 }
93
94 Handle(Expr_GeneralExpression) Expr_NumericValue::NDerivative (const Handle(Expr_NamedUnknown)& , const Standard_Integer) const
95 {
96   return new Expr_NumericValue(0.0);
97 }
98
99 void Expr_NumericValue::Replace (const Handle(Expr_NamedUnknown)& , const Handle(Expr_GeneralExpression)& )
100 {
101 }
102
103 Handle(Expr_GeneralExpression) Expr_NumericValue::ShallowSimplified () const
104 {
105   Handle(Expr_NumericValue) me = this;
106   return me;
107 }
108
109 Standard_Real Expr_NumericValue::Evaluate(const Expr_Array1OfNamedUnknown&, const TColStd_Array1OfReal&) const
110 {
111   return myValue;
112 }
113
114 TCollection_AsciiString Expr_NumericValue::String() const
115 {
116   char val[100];
117   Sprintf(val,"%g",myValue);
118   return TCollection_AsciiString(val);
119 }