Salome HOME
CCAR: remove some memory leaks in non local SALOMEDS
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_AttributeTableOfString.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_AttributeTableOfString.cxx
23 //  Author : Sergey RUIN
24 //  Module : SALOME
25 //
26 #include "SALOMEDS_AttributeTableOfString.hxx"
27 #include "SALOMEDS.hxx"
28
29 #include <string>
30
31 using namespace std;
32  
33 SALOMEDS_AttributeTableOfString::SALOMEDS_AttributeTableOfString
34                   (SALOMEDSImpl_AttributeTableOfString* theAttr)
35 :SALOMEDS_GenericAttribute(theAttr)
36 {}
37
38 SALOMEDS_AttributeTableOfString::SALOMEDS_AttributeTableOfString
39                   (SALOMEDS::AttributeTableOfString_ptr theAttr)
40 :SALOMEDS_GenericAttribute(theAttr)
41 {}
42
43 SALOMEDS_AttributeTableOfString::~SALOMEDS_AttributeTableOfString()
44 {}
45
46
47 void SALOMEDS_AttributeTableOfString::SetTitle(const std::string& theTitle)
48 {
49   if (_isLocal) {
50     CheckLocked();
51     SALOMEDS::Locker lock;
52     dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl)->SetTitle(theTitle);
53   }
54   else SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->SetTitle(theTitle.c_str());
55 }
56
57 std::string SALOMEDS_AttributeTableOfString::GetTitle()
58 {
59   std::string aStr;
60   if (_isLocal) {
61     SALOMEDS::Locker lock;
62     aStr = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl)->GetTitle();
63   }
64   else aStr = SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->GetTitle();
65   return aStr;
66 }
67
68 void SALOMEDS_AttributeTableOfString::SetRowTitle(int theIndex, const std::string& theTitle)
69 {
70   if (_isLocal) {
71     CheckLocked();
72     SALOMEDS::Locker lock;
73     dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl)->SetRowTitle(theIndex, theTitle);
74   }
75   else SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->SetRowTitle(theIndex, theTitle.c_str());
76 }
77
78 void SALOMEDS_AttributeTableOfString::SetRowTitles(const std::vector<std::string>& theTitles)
79 {
80   int aLength = theTitles.size(), i;
81   if (_isLocal) {
82     CheckLocked();
83     SALOMEDS::Locker lock;
84     dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl)->SetRowTitles(theTitles);
85   }
86   else {
87     SALOMEDS::StringSeq_var aSeq = new SALOMEDS::StringSeq();
88     aSeq->length(aLength);
89     for (i = 0; i < aLength; i++) aSeq[i] = (char*)theTitles[i].c_str();
90     SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->SetRowTitles(aSeq);
91   }
92 }
93
94 std::vector<std::string> SALOMEDS_AttributeTableOfString::GetRowTitles()
95 {
96   std::vector<std::string> aVector;
97   int aLength, i;
98   if (_isLocal) {
99     SALOMEDS::Locker lock;
100     aVector = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl)->GetRowTitles();
101   }
102   else {
103     SALOMEDS::StringSeq_var aSeq = SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->GetRowTitles();
104     aLength = aSeq->length();
105     for (i = 0; i < aLength; i++) aVector.push_back((char*)aSeq[i].in());
106   }
107   return aVector;
108 }
109
110 void SALOMEDS_AttributeTableOfString::SetColumnTitle(int theIndex, const std::string& theTitle)
111 {
112   if (_isLocal) {
113     CheckLocked();
114     SALOMEDS::Locker lock;
115     dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl)->SetColumnTitle(theIndex, theTitle);
116   }
117   else SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->SetColumnTitle(theIndex, theTitle.c_str());
118 }
119
120 void SALOMEDS_AttributeTableOfString::SetColumnTitles(const std::vector<std::string>& theTitles)
121 {
122   int aLength = theTitles.size(), i;
123   if (_isLocal) {
124     CheckLocked();
125     SALOMEDS::Locker lock;
126     dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl)->SetColumnTitles(theTitles);
127   }
128   else {
129     SALOMEDS::StringSeq_var aSeq = new SALOMEDS::StringSeq();
130     aSeq->length(aLength);
131     for (i = 0; i < aLength; i++) aSeq[i] = (char*)theTitles[i].c_str();
132     SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->SetColumnTitles(aSeq);
133   }
134 }
135
136 std::vector<std::string> SALOMEDS_AttributeTableOfString::GetColumnTitles()
137 {
138   std::vector<std::string> aVector;
139   int aLength, i;
140   if (_isLocal) {
141     SALOMEDS::Locker lock;
142     aVector = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl)->GetColumnTitles();
143   }
144   else {
145     SALOMEDS::StringSeq_var aSeq = SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->GetColumnTitles();
146     aLength = aSeq->length();
147     for (i = 0; i < aLength; i++) aVector.push_back((char*)aSeq[i].in());
148   }
149   return aVector;
150 }
151
152 void SALOMEDS_AttributeTableOfString::SetRowUnit(int theIndex, const std::string& theUnit)
153 {
154   if (_isLocal) {
155     CheckLocked();
156     SALOMEDS::Locker lock;
157     dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl)->SetRowUnit(theIndex, theUnit);
158   }
159   else SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->SetRowUnit(theIndex, theUnit.c_str());
160 }
161
162 void SALOMEDS_AttributeTableOfString::SetRowUnits(const std::vector<std::string>& theUnits)
163 {
164   int aLength = theUnits.size(), i;
165   if (_isLocal) {
166     CheckLocked();
167     SALOMEDS::Locker lock;
168     dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl)->SetRowUnits(theUnits);
169   }
170   else {
171     SALOMEDS::StringSeq_var aSeq = new SALOMEDS::StringSeq();
172     aSeq->length(aLength);
173     for (i = 0; i < aLength; i++) aSeq[i] = (char*)theUnits[i].c_str();
174     SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->SetRowUnits(aSeq);
175   }
176 }
177
178 std::vector<std::string> SALOMEDS_AttributeTableOfString::GetRowUnits()
179 {
180   std::vector<std::string> aVector;
181   int aLength, i;
182   if (_isLocal) {
183     SALOMEDS::Locker lock;
184     aVector = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl)->GetRowUnits();
185   }
186   else {
187     SALOMEDS::StringSeq_var aSeq = SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->GetRowUnits();
188     aLength = aSeq->length();
189     for (i = 0; i < aLength; i++) aVector.push_back((char*)aSeq[i].in());
190   }
191   return aVector;
192 }
193
194 int SALOMEDS_AttributeTableOfString::GetNbRows()
195 {
196   int aNb;
197   if (_isLocal) {
198     SALOMEDS::Locker lock;
199     aNb = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl)->GetNbRows();
200   }
201   else aNb = SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->GetNbRows();
202   return aNb;
203 }
204
205 int SALOMEDS_AttributeTableOfString::GetNbColumns()
206 {  
207   int aNb;
208   if (_isLocal) {
209     SALOMEDS::Locker lock;
210     aNb = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl)->GetNbColumns();
211   }
212   else aNb = SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->GetNbColumns();
213   return aNb;
214 }
215
216 void SALOMEDS_AttributeTableOfString::AddRow(const std::vector<std::string>& theData)
217 {
218   int aLength = theData.size(), i;
219   if (_isLocal) {
220     CheckLocked();
221     SALOMEDS::Locker lock;
222     SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl);
223     try {
224       aTable->SetRowData(aTable->GetNbRows() + 1, theData);
225     }   
226     catch(...) {
227       throw SALOMEDS::AttributeTableOfString::IncorrectArgumentLength();
228     }
229   }
230   else {
231     SALOMEDS::StringSeq_var aSeq = new SALOMEDS::StringSeq();
232     aSeq->length(aLength);
233     for (i = 0; i < aLength; i++) aSeq[i] = (char*)theData[i].c_str();
234     SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->AddRow(aSeq);
235   }
236 }
237
238 void SALOMEDS_AttributeTableOfString::SetRow(int theRow, const std::vector<std::string>& theData)
239 {
240   int aLength = theData.size(), i;
241   if (_isLocal) {
242     CheckLocked();
243     SALOMEDS::Locker lock;
244     SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl);
245     try {
246       aTable->SetRowData(theRow, theData);
247     }   
248     catch(...) {
249       throw SALOMEDS::AttributeTableOfString::IncorrectArgumentLength();
250     }
251   }
252   else {
253     SALOMEDS::StringSeq_var aSeq = new SALOMEDS::StringSeq();
254     aSeq->length(aLength);
255     for (i = 0; i < aLength; i++) aSeq[i] = (char*)theData[i].c_str();
256     SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->SetRow(theRow, aSeq);
257   }
258 }
259
260 std::vector<std::string> SALOMEDS_AttributeTableOfString::GetRow(int theRow)
261 {
262   std::vector<std::string> aVector;
263   int aLength, i;
264   if (_isLocal) {
265     SALOMEDS::Locker lock;
266     aVector = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl)->GetRowData(theRow);
267   }
268   else {
269     SALOMEDS::StringSeq_var aRow = SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->GetRow(theRow);
270     aLength = aRow->length();
271     for (i = 0; i < aLength; i++) aVector.push_back((char*)aRow[i].in());
272   }
273
274   return aVector;
275 }
276
277 void SALOMEDS_AttributeTableOfString::AddColumn(const std::vector<std::string>& theData)
278 {
279   int aLength = theData.size(), i;
280   if (_isLocal) {
281     CheckLocked();
282     SALOMEDS::Locker lock;
283     SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl);
284     try {
285       aTable->SetColumnData(aTable->GetNbColumns() + 1, theData);
286     }   
287     catch(...) {
288       throw SALOMEDS::AttributeTableOfString::IncorrectArgumentLength();
289     }
290   }
291   else {
292     SALOMEDS::StringSeq_var aColumn = new SALOMEDS::StringSeq();
293     aColumn->length(aLength);
294     for (i = 0; i < aLength; i++) aColumn[i] = (char*)theData[i].c_str();
295     SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->AddColumn(aColumn);
296   }
297 }
298
299 void SALOMEDS_AttributeTableOfString::SetColumn(int theColumn, const std::vector<std::string>& theData)
300 {
301   int aLength = theData.size(), i;
302   if (_isLocal) {
303     CheckLocked();
304     SALOMEDS::Locker lock;
305     SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl);
306     try {
307       aTable->SetColumnData(theColumn, theData);
308     }   
309     catch(...) {
310       throw SALOMEDS::AttributeTableOfString::IncorrectArgumentLength();
311     }
312   }
313   else {
314     SALOMEDS::StringSeq_var aColumn = new SALOMEDS::StringSeq();
315     aColumn->length(aLength);
316     for (i = 0; i < aLength; i++) aColumn[i] = (char*)theData[i].c_str();
317     SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->SetColumn(theColumn, aColumn);
318   }
319 }
320
321 std::vector<std::string> SALOMEDS_AttributeTableOfString::GetColumn(int theColumn)
322 {
323   std::vector<std::string> aVector;
324   int aLength, i;
325   if (_isLocal) {
326     SALOMEDS::Locker lock;
327     aVector = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl)->GetColumnData(theColumn);
328   }
329   else {
330     SALOMEDS::StringSeq_var aColumn =
331       SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->GetColumn(theColumn);
332     aLength = aColumn->length();  
333     for (i = 0; i < aLength; i++) aVector.push_back(aColumn[i].in());
334   }
335   return aVector;
336 }
337
338 void SALOMEDS_AttributeTableOfString::PutValue(const std::string& theValue, int theRow, int theColumn)
339 {
340   if (_isLocal) {
341     CheckLocked();
342     SALOMEDS::Locker lock;
343     try {
344       dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl)->PutValue(theValue, theRow, theColumn);
345     }   
346     catch(...) {
347       throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
348     }
349   }
350   else {
351     SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->PutValue(theValue.c_str(), theRow, theColumn);
352   }
353 }
354
355 bool SALOMEDS_AttributeTableOfString::HasValue(int theRow, int theColumn)
356 {
357   bool ret;
358   if (_isLocal) {
359     SALOMEDS::Locker lock;
360     ret = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl)->HasValue(theRow, theColumn);
361   }
362   else ret = SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->HasValue(theRow, theColumn);
363   return ret;
364 }
365
366 std::string SALOMEDS_AttributeTableOfString::GetValue(int theRow, int theColumn)
367 {
368   std::string aValue;
369   if (_isLocal) {
370     SALOMEDS::Locker lock;
371     try {
372       aValue = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl)->GetValue(theRow, theColumn);
373     }   
374     catch(...) {
375       throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
376     }
377   }
378   else {
379     aValue = SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->GetValue(theRow, theColumn);
380   }
381   return aValue;
382 }
383
384 std::vector<int> SALOMEDS_AttributeTableOfString::GetRowSetIndices(int theRow)
385 {
386   std::vector<int> aVector;
387   int aLength, i;
388   if (_isLocal) {
389     SALOMEDS::Locker lock;
390     aVector = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl)->GetSetRowIndices(theRow);
391   }
392   else {
393     SALOMEDS::LongSeq_var aSet =
394       SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->GetRowSetIndices(theRow);
395     aLength = aSet->length();
396     for (i = 0; i < aLength; i++) aVector.push_back(aSet[i]);
397   }
398   return aVector;
399 }
400
401 void SALOMEDS_AttributeTableOfString::SetNbColumns(int theNbColumns)
402 {
403   if (_isLocal) {
404     SALOMEDS::Locker lock;
405     dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_local_impl)->SetNbColumns(theNbColumns);
406   }
407   else SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->SetNbColumns(theNbColumns);
408 }