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