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