Salome HOME
Remove warnings
[modules/kernel.git] / src / SALOMEDSImpl / SALOMEDSImpl_ScalarVariable.cxx
1 // Copyright (C) 2008  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 //  File   : SALOMEDSImpl_ScalarVariable.cxx
21 //  Author : Roman NIKOLAEV, Open CASCADE S.A.S.
22 //  Module : SALOME
23
24 #include "SALOMEDSImpl_ScalarVariable.hxx"
25 #include "SALOMEDSImpl_GenericVariable.hxx"
26 #include <iostream>
27 #include <cstdlib>
28
29 using namespace std;
30
31 //============================================================================
32 /*! Function : SALOMEDSImpl_ScalarVariable
33  *  Purpose  : 
34  */
35 //============================================================================
36 SALOMEDSImpl_ScalarVariable::
37 SALOMEDSImpl_ScalarVariable(SALOMEDSImpl_GenericVariable::VariableTypes type,
38                             const string& theName):
39   SALOMEDSImpl_GenericVariable(type,theName)
40 {}
41
42 //============================================================================
43 /*! Function : ~SALOMEDSImpl_ScalarVariable()
44  *  Purpose  : 
45  */
46 //============================================================================
47 SALOMEDSImpl_ScalarVariable::~SALOMEDSImpl_ScalarVariable(){}
48
49 //============================================================================
50 /*! Function : 
51  *  Purpose  : 
52  */
53 //============================================================================
54 bool SALOMEDSImpl_ScalarVariable::setValue(const double theValue)
55 {
56   
57   if(myValue == theValue) 
58     return false;
59   
60   myValue = theValue;
61   return true;
62 }
63
64 //============================================================================
65 /*! Function : getValue()
66  *  Purpose  : 
67  */
68 //============================================================================
69 double SALOMEDSImpl_ScalarVariable::getValue() const
70 {
71   return myValue;
72 }
73
74 //============================================================================
75 /*! Function : Save()
76  *  Purpose  : 
77  */
78 //============================================================================
79 string SALOMEDSImpl_ScalarVariable::Save() const{
80   char buffer[255];
81   switch(Type())
82     {
83     case SALOMEDSImpl_GenericVariable::REAL_VAR:
84       {
85         sprintf(buffer, "%.64e", myValue);
86         break;
87       }
88     case SALOMEDSImpl_GenericVariable::BOOLEAN_VAR:
89     case SALOMEDSImpl_GenericVariable::INTEGER_VAR:
90       {
91         sprintf(buffer, "%d", (int)myValue);
92         break;
93       }
94     default:break;
95     }
96   return string(buffer);
97 }
98
99 //============================================================================
100 /*! Function : SaveToScript()
101  *  Purpose  : 
102  */
103 //============================================================================
104 string SALOMEDSImpl_ScalarVariable::SaveToScript() const
105 {
106   char buffer[255];
107   switch(Type())
108     {
109     case SALOMEDSImpl_GenericVariable::REAL_VAR:
110       {
111         sprintf(buffer, "%g", myValue);
112         break;
113       }
114     case SALOMEDSImpl_GenericVariable::INTEGER_VAR:
115       {
116         sprintf(buffer, "%d", (int)myValue);
117         break;
118       }
119     case SALOMEDSImpl_GenericVariable::BOOLEAN_VAR:
120       {
121         if((bool)myValue)
122           sprintf(buffer, "%s", "True");
123         else
124           sprintf(buffer, "%s", "False");
125         break;
126       }
127     default:break;
128     }
129   return string(buffer);
130 }
131
132 //============================================================================
133 /*! Function : SaveType()
134  *  Purpose  : 
135  */
136 //============================================================================
137 string SALOMEDSImpl_ScalarVariable::SaveType() const{
138   char buffer[255];
139   sprintf(buffer, "%d", (int)Type());
140   return string(buffer);
141 }
142
143 //============================================================================
144 /*! Function : Load()
145  *  Purpose  : 
146  */
147 //============================================================================
148 void SALOMEDSImpl_ScalarVariable::Load(const string& theStrValue)
149 {
150   double aValue = atof(theStrValue.c_str());
151   setValue(aValue);
152 }