]> SALOME platform Git repositories - modules/yacs.git/blob - src/SALOMEDSImpl/SALOMEDSImpl_ScalarVariable.cxx
Salome HOME
merge from branch BR_V5_DEV
[modules/yacs.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 using namespace std;
28
29 //============================================================================
30 /*! Function : SALOMEDSImpl_ScalarVariable
31  *  Purpose  : 
32  */
33 //============================================================================
34 SALOMEDSImpl_ScalarVariable::
35 SALOMEDSImpl_ScalarVariable(SALOMEDSImpl_GenericVariable::VariableTypes type,
36                             const string& theName):
37   SALOMEDSImpl_GenericVariable(type,theName)
38 {}
39
40 //============================================================================
41 /*! Function : ~SALOMEDSImpl_ScalarVariable()
42  *  Purpose  : 
43  */
44 //============================================================================
45 SALOMEDSImpl_ScalarVariable::~SALOMEDSImpl_ScalarVariable(){}
46
47 //============================================================================
48 /*! Function : 
49  *  Purpose  : 
50  */
51 //============================================================================
52 bool SALOMEDSImpl_ScalarVariable::setValue(const double theValue)
53 {
54   
55   if(myValue == theValue) 
56     return false;
57   
58   myValue = theValue;
59   return true;
60 }
61
62 //============================================================================
63 /*! Function : getValue()
64  *  Purpose  : 
65  */
66 //============================================================================
67 double SALOMEDSImpl_ScalarVariable::getValue() const
68 {
69   return myValue;
70 }
71
72 //============================================================================
73 /*! Function : Save()
74  *  Purpose  : 
75  */
76 //============================================================================
77 string SALOMEDSImpl_ScalarVariable::Save() const{
78   char buffer[255];
79   switch(Type())
80     {
81     case SALOMEDSImpl_GenericVariable::REAL_VAR:
82       {
83         sprintf(buffer, "%.64e", myValue);
84         break;
85       }
86     case SALOMEDSImpl_GenericVariable::BOOLEAN_VAR:
87     case SALOMEDSImpl_GenericVariable::INTEGER_VAR:
88       {
89         sprintf(buffer, "%d", (int)myValue);
90         break;
91       }
92     default:break;
93     }
94   return string(buffer);
95 }
96
97 //============================================================================
98 /*! Function : SaveToScript()
99  *  Purpose  : 
100  */
101 //============================================================================
102 string SALOMEDSImpl_ScalarVariable::SaveToScript() const
103 {
104   char buffer[255];
105   switch(Type())
106     {
107     case SALOMEDSImpl_GenericVariable::REAL_VAR:
108       {
109         sprintf(buffer, "%g", myValue);
110         break;
111       }
112     case SALOMEDSImpl_GenericVariable::INTEGER_VAR:
113       {
114         sprintf(buffer, "%d", (int)myValue);
115         break;
116       }
117     case SALOMEDSImpl_GenericVariable::BOOLEAN_VAR:
118       {
119         if((bool)myValue)
120           sprintf(buffer, "%s", "True");
121         else
122           sprintf(buffer, "%s", "False");
123         break;
124       }
125     default:break;
126     }
127   return string(buffer);
128 }
129
130 //============================================================================
131 /*! Function : SaveType()
132  *  Purpose  : 
133  */
134 //============================================================================
135 string SALOMEDSImpl_ScalarVariable::SaveType() const{
136   char buffer[255];
137   sprintf(buffer, "%d", (int)Type());
138   return string(buffer);
139 }
140
141 //============================================================================
142 /*! Function : Load()
143  *  Purpose  : 
144  */
145 //============================================================================
146 void SALOMEDSImpl_ScalarVariable::Load(const string& theStrValue)
147 {
148   double aValue = atof(theStrValue.c_str());
149   setValue(aValue);
150 }