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