Salome HOME
Removed includes and libraries of OCC
[modules/kernel.git] / src / SALOMEDSImpl / SALOMEDSImpl_AttributeSequenceOfReal.cxx
1 // Copyright (C) 2005  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_AttributeSequenceOfReal.cxx
21 //  Author : Sergey RUIN
22 //  Module : SALOME
23
24 #include "SALOMEDSImpl_AttributeSequenceOfReal.hxx"
25
26 using namespace std;
27
28 //=======================================================================
29 //function : GetID
30 //purpose  : 
31 //=======================================================================
32
33 const std::string& SALOMEDSImpl_AttributeSequenceOfReal::GetID () 
34 {
35   static std::string SALOMEDSImpl_AttributeSequenceOfRealID ("12837183-8F52-11d6-A8A3-0001021E8C7F");
36   return SALOMEDSImpl_AttributeSequenceOfRealID;
37 }
38
39
40
41 //=======================================================================
42 //function : Set
43 //purpose  : 
44 //=======================================================================
45
46 SALOMEDSImpl_AttributeSequenceOfReal* SALOMEDSImpl_AttributeSequenceOfReal::Set (const DF_Label& L) 
47 {
48   SALOMEDSImpl_AttributeSequenceOfReal* A = NULL;
49   if (!(A=(SALOMEDSImpl_AttributeSequenceOfReal*)L.FindAttribute(SALOMEDSImpl_AttributeSequenceOfReal::GetID()))) {
50     A = new  SALOMEDSImpl_AttributeSequenceOfReal(); 
51     L.AddAttribute(A);
52   }
53   return A;
54 }
55
56
57 //=======================================================================
58 //function : constructor
59 //purpose  : 
60 //=======================================================================
61 SALOMEDSImpl_AttributeSequenceOfReal::SALOMEDSImpl_AttributeSequenceOfReal()
62 :SALOMEDSImpl_GenericAttribute("AttributeSequenceOfReal")
63 {
64   myValue.clear();
65 }
66
67 //=======================================================================
68 //function : ID
69 //purpose  : 
70 //=======================================================================
71
72 const std::string& SALOMEDSImpl_AttributeSequenceOfReal::ID () const { return GetID(); }
73
74
75 //=======================================================================
76 //function : NewEmpty
77 //purpose  : 
78 //=======================================================================
79
80 DF_Attribute* SALOMEDSImpl_AttributeSequenceOfReal::NewEmpty () const
81 {  
82   return new SALOMEDSImpl_AttributeSequenceOfReal(); 
83 }
84
85 //=======================================================================
86 //function : Restore
87 //purpose  : 
88 //=======================================================================
89
90 void SALOMEDSImpl_AttributeSequenceOfReal::Restore(DF_Attribute* with) 
91 {
92   SALOMEDSImpl_AttributeSequenceOfReal* anSeq = dynamic_cast<SALOMEDSImpl_AttributeSequenceOfReal*>(with);
93   myValue.clear();
94   for(int i = 0, len = anSeq->Length(); i<len; i++)
95     myValue.push_back(anSeq->myValue[i]);    
96   return;
97 }
98
99 //=======================================================================
100 //function : Paste
101 //purpose  : 
102 //=======================================================================
103
104 void SALOMEDSImpl_AttributeSequenceOfReal::Paste (DF_Attribute* into)
105 {
106     dynamic_cast<SALOMEDSImpl_AttributeSequenceOfReal*>(into)->Assign(myValue);
107 }
108
109 void SALOMEDSImpl_AttributeSequenceOfReal::Assign(const vector<double>& other) 
110 {
111   CheckLocked();  
112   Backup();
113   myValue = other;
114
115   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
116 }
117
118 void SALOMEDSImpl_AttributeSequenceOfReal::ChangeValue(const int Index,const double& Value) 
119 {
120   CheckLocked();  
121   Backup();
122
123   if(Index <= 0 || Index > myValue.size()) throw DFexception("Out of range");
124
125   myValue[Index-1] = Value;
126   
127   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
128 }
129
130 void SALOMEDSImpl_AttributeSequenceOfReal::Add(const double& Value) 
131 {
132   CheckLocked();  
133   Backup();
134   myValue.push_back(Value);
135   
136   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
137 }
138
139 void SALOMEDSImpl_AttributeSequenceOfReal::Remove(const int Index) 
140 {
141   CheckLocked();  
142   Backup();
143
144   if(Index <= 0 || Index > myValue.size()) throw DFexception("Out of range");
145
146   typedef vector<double>::iterator VI;
147   int i = 1;    
148   for(VI p = myValue.begin(); p!=myValue.end(); p++, i++) {
149     if(i == Index) {
150       myValue.erase(p);
151       break;
152     }     
153   }
154
155   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved   
156 }
157
158 int SALOMEDSImpl_AttributeSequenceOfReal::Length() 
159 {
160   return myValue.size();
161 }
162
163 double SALOMEDSImpl_AttributeSequenceOfReal::Value(const int Index) 
164 {
165   if(Index <= 0 || Index > myValue.size()) throw DFexception("Out of range");
166   return myValue[Index-1];
167 }
168
169
170 string SALOMEDSImpl_AttributeSequenceOfReal::Save()
171 {
172   int aLength = Length();
173   char* aResult = new char[aLength * 127];
174   aResult[0] = 0;
175   int aPosition = 0;
176   for (int i = 1; i <= aLength; i++) {
177     sprintf(aResult + aPosition , "%.64e ", Value(i));
178     aPosition += strlen(aResult + aPosition);
179   }
180   string ret(aResult);
181   delete aResult;
182                           
183   return ret;
184 }
185                             
186 void SALOMEDSImpl_AttributeSequenceOfReal::Load(const string& value)
187 {
188                               
189   char* aCopy = (char*)value.c_str();
190   char* adr = strtok(aCopy, " ");
191   char *err = NULL; 
192   while (adr) {
193     double r =  strtod(adr, &err); 
194     Add(r);
195     adr = strtok(NULL, " ");
196   }
197 }