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