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