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