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