Salome HOME
CCAR: remove some memory leaks in non local SALOMEDS
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_AttributeParameter.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  File   : SALOMEDS_AttributeParameter.cxx
23 //  Author : Sergey RUIN
24 //  Module : SALOME
25 //
26 #include "SALOMEDS_AttributeParameter.hxx"
27 #include "SALOMEDS.hxx"
28
29 #include <string>
30
31 using namespace std;
32
33 //=======================================================================
34 /*!
35  * Function : Constructor
36  * Purpose  : Creates a new instance of SALOMEDS_AttributeParameter
37  */
38 //=======================================================================
39 SALOMEDS_AttributeParameter::SALOMEDS_AttributeParameter(SALOMEDSImpl_AttributeParameter* theAttr)
40 :SALOMEDS_GenericAttribute(theAttr)
41 {}
42
43 //=======================================================================
44 /*!
45  * Function : Constructor
46  * Purpose  : Creates a new instance of SALOMEDS_AttributeParameter
47  */
48 //=======================================================================
49 SALOMEDS_AttributeParameter::SALOMEDS_AttributeParameter(SALOMEDS::AttributeParameter_ptr theAttr)
50 :SALOMEDS_GenericAttribute(theAttr)
51 {}
52
53 //=======================================================================
54 /*!
55  * Function : Destructor
56  * Purpose  : Destroys the instance of SALOMEDS_AttributeParameter
57  */
58 //=======================================================================
59 SALOMEDS_AttributeParameter::~SALOMEDS_AttributeParameter()
60 {}
61
62 //=======================================================================
63 /*!
64  * Function : SetInt
65  * Purpose  : Associates a integer value with the ID
66  */
67 //=======================================================================
68 void SALOMEDS_AttributeParameter::SetInt(const string& theID, const int theValue) 
69 {
70   CheckLocked();
71
72   if(_isLocal) {
73     SALOMEDS::Locker lock; 
74     dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->SetInt(theID, theValue);
75   }
76   else
77     SALOMEDS::AttributeParameter::_narrow(_corba_impl)->SetInt(theID.c_str(), theValue);
78 }
79
80 //=======================================================================
81 /*!
82  * Function : GetInt
83  * Purpose  : Returns a int value associated with the given ID
84  */
85 //=======================================================================
86 int SALOMEDS_AttributeParameter::GetInt(const string& theID) 
87 {
88   int aValue;
89   if(_isLocal) {
90     SALOMEDS::Locker lock; 
91     aValue = dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->GetInt(theID);
92   }
93   else
94     aValue = SALOMEDS::AttributeParameter::_narrow(_corba_impl)->GetInt(theID.c_str());
95   return aValue;
96 }
97
98 //=======================================================================
99 /*!
100  * Function : SetReal
101  * Purpose  : Associates a double value with the ID
102  */
103 //=======================================================================
104 void SALOMEDS_AttributeParameter::SetReal(const string& theID, const double& theValue) 
105 {
106   CheckLocked();
107
108   if(_isLocal) {
109     SALOMEDS::Locker lock; 
110     dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->SetReal(theID, theValue);
111   }
112   else
113     SALOMEDS::AttributeParameter::_narrow(_corba_impl)->SetReal(theID.c_str(), theValue);
114 }
115  
116 //=======================================================================
117 /*!
118  * Function : GetReal
119  * Purpose  : Returns a double value associated with the given ID
120  */
121 //=======================================================================
122 double SALOMEDS_AttributeParameter::GetReal(const string& theID) 
123 {
124   double aValue;
125   if(_isLocal) {
126     SALOMEDS::Locker lock; 
127     aValue = dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->GetReal(theID);
128   }
129   else
130     aValue = SALOMEDS::AttributeParameter::_narrow(_corba_impl)->GetReal(theID.c_str());
131   return aValue;
132 }
133
134 //=======================================================================
135 /*!
136  * Function : SetString
137  * Purpose  : Associates a string with the ID
138  */
139 //=======================================================================
140 void SALOMEDS_AttributeParameter::SetString(const string& theID, const string& theValue) 
141 {
142   CheckLocked();
143
144   if(_isLocal) {
145     SALOMEDS::Locker lock; 
146     dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->SetString(theID, theValue);
147   }
148   else
149     SALOMEDS::AttributeParameter::_narrow(_corba_impl)->SetString(theID.c_str(), theValue.c_str());
150 }
151  
152 //=======================================================================
153 /*!
154  * Function : GetString
155  * Purpose  : Returns a string associated with the given ID
156  */
157 //=======================================================================
158 string SALOMEDS_AttributeParameter::GetString(const string& theID) 
159 {
160   string aValue;
161   if(_isLocal) {
162     SALOMEDS::Locker lock; 
163     aValue = dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->GetString(theID);
164   }
165   else
166     aValue = SALOMEDS::AttributeParameter::_narrow(_corba_impl)->GetString(theID.c_str());
167   return aValue;
168 }
169   
170 //=======================================================================
171 /*!
172  * Function : SetBool
173  * Purpose  : Associates a bool value with the ID
174  */
175 //=======================================================================
176 void SALOMEDS_AttributeParameter::SetBool(const string& theID, const bool& theValue) 
177 {
178   CheckLocked();
179
180   if(_isLocal) {
181     SALOMEDS::Locker lock; 
182     dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->SetBool(theID, theValue);
183   }
184   else
185     SALOMEDS::AttributeParameter::_narrow(_corba_impl)->SetBool(theID.c_str(), theValue);
186 }
187
188 //=======================================================================
189 /*!
190  * Function : GetBool
191  * Purpose  : Returns a bool value associated with the ID
192  */
193 //=======================================================================
194 bool SALOMEDS_AttributeParameter::GetBool(const string& theID) 
195 {
196   if(_isLocal) {
197     SALOMEDS::Locker lock; 
198     return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->GetBool(theID);
199   }
200   else
201     return SALOMEDS::AttributeParameter::_narrow(_corba_impl)->GetBool(theID.c_str());
202 }
203   
204 //=======================================================================
205 /*!
206  * Function : SetRealArray
207  * Purpose  : Associates an array of double values with the given ID
208  */
209 //=======================================================================
210 void SALOMEDS_AttributeParameter::SetRealArray(const string& theID, const vector<double>& theArray) 
211 {
212   CheckLocked();
213
214   if(_isLocal) {
215     SALOMEDS::Locker lock; 
216     dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->SetRealArray(theID, theArray);
217   }
218   else {
219     SALOMEDS::DoubleSeq_var aSeq = new SALOMEDS::DoubleSeq;
220     int length = theArray.size();
221     if(length) {
222       aSeq->length(length);
223       for(int i = 0; i<length; i++) aSeq[i] = theArray[i];
224     }
225     SALOMEDS::AttributeParameter::_narrow(_corba_impl)->SetRealArray(theID.c_str(), aSeq);
226   }
227 }
228  
229 //=======================================================================
230 /*!
231  * Function : GetRealArray
232  * Purpose  : Returns an array of double values associated with the ID
233  */
234 //=======================================================================
235 vector<double> SALOMEDS_AttributeParameter::GetRealArray(const string& theID) 
236 {
237   vector<double> v;
238   if(_isLocal) {
239     SALOMEDS::Locker lock; 
240     return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->GetRealArray(theID);
241   }
242   else {
243     SALOMEDS::DoubleSeq_var aSeq = SALOMEDS::AttributeParameter::_narrow(_corba_impl)->GetRealArray(theID.c_str());    
244     int length = aSeq->length();
245     if(length) {
246       v.resize(length);
247       for(int i = 0; i < length; i++) v[i] = aSeq[i];
248     }
249   }
250   return v;
251 }
252
253 //=======================================================================
254 /*!
255  * Function : SetIntArray
256  * Purpose  : Associates an array of int values with the given ID
257  */
258 //=======================================================================
259 void SALOMEDS_AttributeParameter::SetIntArray(const string& theID, const vector<int>& theArray) 
260 {
261   CheckLocked();
262
263   if(_isLocal) {
264     SALOMEDS::Locker lock; 
265     dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->SetIntArray(theID, theArray);
266   }
267   else {
268     SALOMEDS::LongSeq_var aSeq = new SALOMEDS::LongSeq;
269     int length = theArray.size();
270     if(length) {
271       aSeq->length(length);
272       for(int i = 0; i<length; i++) aSeq[i] = theArray[i];
273     }
274     SALOMEDS::AttributeParameter::_narrow(_corba_impl)->SetIntArray(theID.c_str(), aSeq);
275   }
276 }
277  
278 //=======================================================================
279 /*!
280  * Function : GetIntArray
281  * Purpose  : Returns an array of int values associated with the ID
282  */
283 //=======================================================================
284 vector<int> SALOMEDS_AttributeParameter::GetIntArray(const string& theID) 
285 {
286   vector<int> v;
287   if(_isLocal) {
288     SALOMEDS::Locker lock; 
289     return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->GetIntArray(theID);
290   }
291   else {
292     SALOMEDS::LongSeq_var aSeq = SALOMEDS::AttributeParameter::_narrow(_corba_impl)->GetIntArray(theID.c_str());    
293     int length = aSeq->length();
294     if(length) {
295       v.resize(length);
296       for(int i = 0; i < length; i++) v[i] = aSeq[i];
297     }
298   }
299   return v;
300 }
301
302 //=======================================================================
303 /*!
304  * Function : SetStrArray
305  * Purpose  : Associates an array of string values with the given ID
306  */
307 //=======================================================================
308 void SALOMEDS_AttributeParameter::SetStrArray(const string& theID, const vector<string>& theArray) 
309 {
310   CheckLocked();
311
312   if(_isLocal) {
313     SALOMEDS::Locker lock; 
314     dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->SetStrArray(theID, theArray);
315   }
316   else {
317     SALOMEDS::StringSeq_var aSeq = new SALOMEDS::StringSeq;
318     int length = theArray.size();
319     if(length) {
320       aSeq->length(length);
321       for(int i = 0; i<length; i++) aSeq[i] = CORBA::string_dup(theArray[i].c_str());
322     }
323     SALOMEDS::AttributeParameter::_narrow(_corba_impl)->SetStrArray(theID.c_str(), aSeq);
324   }
325 }
326  
327 //=======================================================================
328 /*!
329  * Function : GetStrArray
330  * Purpose  : Returns an array of string values associated with the ID
331  */
332 //=======================================================================
333 vector<string> SALOMEDS_AttributeParameter::GetStrArray(const string& theID) 
334 {
335   vector<string> v;
336   if(_isLocal) {
337     SALOMEDS::Locker lock; 
338     return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->GetStrArray(theID);
339   }
340   else {
341     SALOMEDS::StringSeq_var aSeq = SALOMEDS::AttributeParameter::_narrow(_corba_impl)->GetStrArray(theID.c_str());    
342     int length = aSeq->length();
343     if(length) {
344       v.resize(length);
345       for(int i = 0; i < length; i++) v[i] = string(aSeq[i].in());
346     }
347   }
348   return v;
349 }
350
351
352 //=======================================================================
353 /*!
354  * Function : IsSet
355  * Purpose  : Returns true if for the ID of given type was assigned \n
356  *            a value in the attribute
357  */
358 //======================================================================= 
359 bool SALOMEDS_AttributeParameter::IsSet(const string& theID, const int theType) 
360 {
361   if(_isLocal) {
362     SALOMEDS::Locker lock; 
363     return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->IsSet(theID, (Parameter_Types)theType);
364   }
365   else 
366     return SALOMEDS::AttributeParameter::_narrow(_corba_impl)->IsSet(theID.c_str(), theType);
367 }
368
369 //=======================================================================
370 /*!
371  * Function : RemoveID
372  * Purpose  : Removes a parameter with given ID
373  */
374 //======================================================================= 
375 bool SALOMEDS_AttributeParameter::RemoveID(const string& theID, const int theType) 
376 {
377   CheckLocked();
378
379   if(_isLocal) {
380     SALOMEDS::Locker lock; 
381     return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->RemoveID(theID, (Parameter_Types)theType);
382   }
383   else
384     return SALOMEDS::AttributeParameter::_narrow(_corba_impl)->RemoveID(theID.c_str(), theType);
385 }
386
387 //=======================================================================
388 /*!
389  * Function : GetFather
390  * Purpose  : Returns a father attribute for this attribute
391  */
392 //=======================================================================
393 _PTR(AttributeParameter) SALOMEDS_AttributeParameter::GetFather() 
394 {
395   SALOMEDSClient_AttributeParameter* AP = NULL;
396   if(_isLocal) {
397     SALOMEDS::Locker lock; 
398     SALOMEDSImpl_AttributeParameter* AP_impl = dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->GetFather();
399     if(!AP_impl) return _PTR(AttributeParameter)(AP);
400     AP = new SALOMEDS_AttributeParameter(AP_impl);
401   }
402   else {
403     SALOMEDS::AttributeParameter_var AP_impl = SALOMEDS::AttributeParameter::_narrow(_corba_impl)->GetFather();
404     if(CORBA::is_nil(AP_impl)) return _PTR(AttributeParameter)(AP);
405     AP = new SALOMEDS_AttributeParameter(AP_impl);
406   }
407   
408   return _PTR(AttributeParameter)(AP);
409 }
410
411 //=======================================================================
412 /*!
413  * Function : HasFather
414  * Purpose  : Returns True if the attribute has a father attribute
415  */
416 //======================================================================= 
417 bool SALOMEDS_AttributeParameter::HasFather() 
418 {
419   if(_isLocal) {
420     SALOMEDS::Locker lock; 
421     return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->HasFather();
422   }
423   else 
424     return SALOMEDS::AttributeParameter::_narrow(_corba_impl)->HasFather();
425 }
426
427 //=======================================================================
428 /*!
429  * Function : IsRoot
430  * Purpose  : Returns True is the attribute is highest in an hierachy
431  */
432 //=======================================================================
433 bool SALOMEDS_AttributeParameter::IsRoot()
434 {
435   if(_isLocal) {
436     SALOMEDS::Locker lock; 
437     return dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->IsRoot();
438   }
439   else 
440     return SALOMEDS::AttributeParameter::_narrow(_corba_impl)->IsRoot();
441 }
442
443 //=======================================================================
444 /*!
445  * Function : Clear
446  * Purpose  : Clears the content of the attribute
447  */
448 //======================================================================= 
449 void SALOMEDS_AttributeParameter::Clear() 
450 {
451   if(_isLocal) {
452     SALOMEDS::Locker lock; 
453     dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl)->Clear();
454   }
455   else 
456     SALOMEDS::AttributeParameter::_narrow(_corba_impl)->Clear();
457 }
458
459 //=======================================================================
460 /*!
461  * Function : GetIDs
462  * Purpose  : Returns an array of all ID's of the given type
463  */
464 //=======================================================================
465 vector<string> SALOMEDS_AttributeParameter::GetIDs(const int theType)
466 {
467   vector<string> v;
468   if(_isLocal) {
469     SALOMEDS::Locker lock; 
470     SALOMEDSImpl_AttributeParameter* AP_impl = dynamic_cast<SALOMEDSImpl_AttributeParameter*>(_local_impl);
471     return AP_impl->GetIDs((Parameter_Types)theType);
472   }
473   else {
474     SALOMEDS::AttributeParameter_var AP_impl = SALOMEDS::AttributeParameter::_narrow(_corba_impl);
475     SALOMEDS::StringSeq_var CorbaSeq = AP_impl->GetIDs(theType);
476     int length = CorbaSeq->length();
477     if(length) {
478       v.resize(length);
479       for(int i = 0; i <length; i++) v[i] = string(CorbaSeq[i].in());
480     }
481   }
482
483   return v;
484 }