Salome HOME
Merge from V5_1_3_BR 07/12/2009
[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 #include <cstdio>
29
30 using namespace std;
31
32 //============================================================================
33 /*! Function : SALOMEDSImpl_ScalarVariable
34  *  Purpose  : 
35  */
36 //============================================================================
37 SALOMEDSImpl_ScalarVariable::
38 SALOMEDSImpl_ScalarVariable(SALOMEDSImpl_GenericVariable::VariableTypes type,
39                             const string& theName):
40   SALOMEDSImpl_GenericVariable(type,theName)
41 {}
42
43 //============================================================================
44 /*! Function : ~SALOMEDSImpl_ScalarVariable()
45  *  Purpose  : 
46  */
47 //============================================================================
48 SALOMEDSImpl_ScalarVariable::~SALOMEDSImpl_ScalarVariable(){}
49
50 //============================================================================
51 /*! Function : 
52  *  Purpose  : 
53  */
54 //============================================================================
55 bool SALOMEDSImpl_ScalarVariable::setValue(const double theValue)
56 {
57   
58   if(myValue == theValue) 
59     return false;
60   
61   myValue = theValue;
62   return true;
63 }
64
65 //============================================================================
66 /*! Function : 
67  *  Purpose  : 
68  */
69 //============================================================================
70 bool SALOMEDSImpl_ScalarVariable::setStringValue(const string& theValue)
71 {
72   
73   if(myStrValue == theValue) 
74     return false;
75   
76   myStrValue = theValue;
77   return true;
78 }
79
80 //============================================================================
81 /*! Function : getValue()
82  *  Purpose  : 
83  */
84 //============================================================================
85 double SALOMEDSImpl_ScalarVariable::getValue() const
86 {
87   return myValue;
88 }
89
90 //============================================================================
91 /*! Function : getStringValue()
92  *  Purpose  : 
93  */
94 //============================================================================
95 string SALOMEDSImpl_ScalarVariable::getStringValue() const
96 {
97   return myStrValue;
98 }
99
100 //============================================================================
101 /*! Function : Save()
102  *  Purpose  : 
103  */
104 //============================================================================
105 string SALOMEDSImpl_ScalarVariable::Save() const{
106   char buffer[255];
107   switch(Type())
108     {
109     case SALOMEDSImpl_GenericVariable::REAL_VAR:
110       {
111         sprintf(buffer, "%.64e", myValue);
112         break;
113       }
114     case SALOMEDSImpl_GenericVariable::BOOLEAN_VAR:
115     case SALOMEDSImpl_GenericVariable::INTEGER_VAR:
116       {
117         sprintf(buffer, "%d", (int)myValue);
118         break;
119       }
120     case SALOMEDSImpl_GenericVariable::STRING_VAR:
121       {
122         sprintf(buffer, "\"%s\"", myStrValue.c_str());
123         break;
124       }
125     default:break;
126     }
127   return string(buffer);
128 }
129
130 //============================================================================
131 /*! Function : SaveToScript()
132  *  Purpose  : 
133  */
134 //============================================================================
135 string SALOMEDSImpl_ScalarVariable::SaveToScript() const
136 {
137   char buffer[255];
138   switch(Type())
139     {
140     case SALOMEDSImpl_GenericVariable::REAL_VAR:
141       {
142         sprintf(buffer, "%g", myValue);
143         break;
144       }
145     case SALOMEDSImpl_GenericVariable::INTEGER_VAR:
146       {
147         sprintf(buffer, "%d", (int)myValue);
148         break;
149       }
150     case SALOMEDSImpl_GenericVariable::BOOLEAN_VAR:
151       {
152         if((bool)myValue)
153           sprintf(buffer, "%s", "True");
154         else
155           sprintf(buffer, "%s", "False");
156         break;
157       }
158     case SALOMEDSImpl_GenericVariable::STRING_VAR:
159       {
160         sprintf(buffer, "\"%s\"", myStrValue.c_str());
161         break;
162       }
163     default:break;
164     }
165   return string(buffer);
166 }
167
168 //============================================================================
169 /*! Function : SaveType()
170  *  Purpose  : 
171  */
172 //============================================================================
173 string SALOMEDSImpl_ScalarVariable::SaveType() const{
174   char buffer[255];
175   sprintf(buffer, "%d", (int)Type());
176   return string(buffer);
177 }
178
179 //============================================================================
180 /*! Function : Load()
181  *  Purpose  : 
182  */
183 //============================================================================
184 void SALOMEDSImpl_ScalarVariable::Load(const string& theStrValue)
185 {
186   double aValue = atof(theStrValue.c_str());
187   setValue(aValue);
188 }