Salome HOME
PR: merge from branch BR_UnitTests tag mergeto_trunk_17oct05
[modules/yacs.git] / src / SALOMEDS / SALOMEDS_AttributeTableOfInteger_i.cxx
1 //  File   : SALOMEDS_AttributeTableOfInteger_i.cxx
2 //  Author : Sergey RUIN
3 //  Module : SALOME
4
5
6 #include "SALOMEDS_AttributeTableOfInteger_i.hxx"
7 #include "SALOMEDS.hxx"
8
9 #include <TColStd_HSequenceOfInteger.hxx>
10 #include <Standard_Failure.hxx>
11 #include <Standard_ErrorHandler.hxx>
12 #include "Utils_ExceptHandlers.hxx"
13
14 #include <stdexcept>
15 #include <strstream>
16 #include <string>
17
18 using namespace std;
19
20 UNEXPECT_CATCH(ATI_IncorrectIndex, SALOMEDS::AttributeTableOfInteger::IncorrectIndex);
21 UNEXPECT_CATCH(ATI_IncorrectArgumentLength, SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength);
22
23 void SALOMEDS_AttributeTableOfInteger_i::SetTitle(const char* theTitle) 
24 {
25   SALOMEDS::Locker lock;
26   CheckLocked();
27   CORBA::String_var aStr = CORBA::string_dup(theTitle);
28   Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl)->SetTitle(TCollection_ExtendedString(aStr));
29 }
30
31 char* SALOMEDS_AttributeTableOfInteger_i::GetTitle() 
32 {
33   SALOMEDS::Locker lock;
34   Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
35   CORBA::String_var c_s = CORBA::string_dup(TCollection_AsciiString(aTable->GetTitle()).ToCString());
36   return c_s._retn();
37 }
38
39 void SALOMEDS_AttributeTableOfInteger_i::SetRowTitle(CORBA::Long theIndex, const char* theTitle)
40      throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
41 {
42   SALOMEDS::Locker lock;
43   Unexpect aCatch (ATI_IncorrectIndex);
44   CheckLocked();
45   Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
46   if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
47   aTable->SetRowTitle(theIndex, TCollection_ExtendedString((char*)theTitle));
48 }
49
50 void SALOMEDS_AttributeTableOfInteger_i::SetRowTitles(const SALOMEDS::StringSeq& theTitles)
51      throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
52 {
53   SALOMEDS::Locker lock;
54   Unexpect aCatch (ATI_IncorrectArgumentLength);
55   CheckLocked();
56   Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
57   if (theTitles.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
58   for (int i = 0; i < theTitles.length(); i++) {
59     SetRowTitle(i + 1, theTitles[i]);
60   }
61 }
62
63 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfInteger_i::GetRowTitles() 
64 {
65   SALOMEDS::Locker lock;
66   Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
67   SALOMEDS::StringSeq_var aTitles = new SALOMEDS::StringSeq;
68   aTitles->length(aTable->GetNbRows());
69   for(int i = 0; i < aTitles->length(); i++)
70     aTitles[i] = CORBA::string_dup(TCollection_AsciiString(aTable->GetRowTitle(i + 1)).ToCString());
71   return aTitles._retn();
72 }
73
74 void SALOMEDS_AttributeTableOfInteger_i::SetColumnTitle(CORBA::Long theIndex, const char* theTitle)
75      throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
76 {
77   SALOMEDS::Locker lock;
78   Unexpect aCatch (ATI_IncorrectIndex);
79   CheckLocked();
80   Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
81   if (theIndex <= 0 || theIndex > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
82   CORBA::String_var aStr = CORBA::string_dup(theTitle);
83   aTable->SetColumnTitle(theIndex, TCollection_ExtendedString(aStr));
84 }
85
86 void SALOMEDS_AttributeTableOfInteger_i::SetColumnTitles(const SALOMEDS::StringSeq& theTitles)
87      throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
88 {
89   SALOMEDS::Locker lock;
90   Unexpect aCatch(ATI_IncorrectArgumentLength);
91   CheckLocked();
92   Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
93   if (theTitles.length() != aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
94   for (int i = 0; i < theTitles.length(); i++) {
95     aTable->SetColumnTitle(i + 1, (char*)theTitles[i].in());
96   }
97 }
98
99 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfInteger_i::GetColumnTitles() 
100 {
101   SALOMEDS::Locker lock;
102   Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
103   SALOMEDS::StringSeq_var aTitles = new SALOMEDS::StringSeq;
104   aTitles->length(aTable->GetNbColumns());
105   for(int i = 0; i < aTitles->length(); i++)
106     aTitles[i] = CORBA::string_dup(TCollection_AsciiString(aTable->GetColumnTitle(i + 1)).ToCString());
107   return aTitles._retn();
108 }
109
110 //Units support
111 void SALOMEDS_AttributeTableOfInteger_i::SetRowUnit(CORBA::Long theIndex, const char* theUnit)
112      throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
113 {
114   SALOMEDS::Locker lock;
115   Unexpect aCatch (ATI_IncorrectIndex);
116   CheckLocked();
117   Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
118   if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
119   aTable->SetRowUnit(theIndex, TCollection_ExtendedString((char*)theUnit));
120 }
121
122 void SALOMEDS_AttributeTableOfInteger_i::SetRowUnits(const SALOMEDS::StringSeq& theUnits)
123      throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
124 {
125   SALOMEDS::Locker lock;
126   Unexpect aCatch (ATI_IncorrectArgumentLength);
127   CheckLocked();
128   Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
129   if (theUnits.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
130   for (int i = 0; i < theUnits.length(); i++) {
131     aTable->SetRowUnit(i + 1, (char*)theUnits[i].in());
132   }
133 }
134
135 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfInteger_i::GetRowUnits() 
136 {
137   SALOMEDS::Locker lock;
138   Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
139   SALOMEDS::StringSeq_var aUnits = new SALOMEDS::StringSeq;
140   aUnits->length(aTable->GetNbRows());
141   for(int i = 0; i < aUnits->length(); i++)
142     aUnits[i] = CORBA::string_dup(TCollection_AsciiString(aTable->GetRowUnit(i + 1)).ToCString());
143   return aUnits._retn();
144 }
145
146 CORBA::Long SALOMEDS_AttributeTableOfInteger_i::GetNbRows() 
147 {
148   SALOMEDS::Locker lock;
149   return Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl)->GetNbRows();
150 }
151
152 CORBA::Long SALOMEDS_AttributeTableOfInteger_i::GetNbColumns() 
153 {
154   SALOMEDS::Locker lock;
155   return Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl)->GetNbColumns();
156 }
157
158 void SALOMEDS_AttributeTableOfInteger_i::AddRow(const SALOMEDS::LongSeq& theData)
159      throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
160 {
161   SALOMEDS::Locker lock;
162   Unexpect aCatch(ATI_IncorrectArgumentLength);
163   CheckLocked();
164   Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
165   
166   Handle(TColStd_HSequenceOfInteger) aRow = new TColStd_HSequenceOfInteger;
167   for (int i = 0; i < theData.length(); i++) aRow->Append(theData[i]);
168   try {
169     aTable->SetRowData(aTable->GetNbRows() + 1, aRow);
170   }
171   catch(Standard_Failure) {
172     throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
173   }
174 }
175
176 void SALOMEDS_AttributeTableOfInteger_i::SetRow(CORBA::Long theRow, const SALOMEDS::LongSeq& theData)
177      throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength, SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
178 {
179   SALOMEDS::Locker lock;
180   Unexpect aCatch(ATI_IncorrectArgumentLength);
181   CheckLocked();
182   Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
183   
184   Handle(TColStd_HSequenceOfInteger) aRow = new TColStd_HSequenceOfInteger;
185   for (int i = 0; i < theData.length(); i++) aRow->Append(theData[i]);
186   try {
187     aTable->SetRowData(theRow, aRow);
188   }
189   catch(Standard_Failure) {
190     throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
191   }  
192 }
193
194 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfInteger_i::GetRow(CORBA::Long theRow)
195      throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
196 {
197   SALOMEDS::Locker lock;
198   Unexpect aCatch(ATI_IncorrectIndex);
199   Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
200   if (theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
201
202   SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
203   Handle(TColStd_HSequenceOfInteger) aRow = aTable->GetRowData(theRow);
204   CorbaSeq->length(aRow->Length());
205   for (int i = 0; i < aRow->Length(); i++) {
206     CorbaSeq[i] = aRow->Value(i + 1);
207   }
208   return CorbaSeq._retn();
209 }
210
211 void SALOMEDS_AttributeTableOfInteger_i::AddColumn(const SALOMEDS::LongSeq& theData)
212      throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
213 {
214   SALOMEDS::Locker lock;
215   Unexpect aCatch(ATI_IncorrectArgumentLength);
216   CheckLocked();
217   Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
218   
219   Handle(TColStd_HSequenceOfInteger) aColumn = new TColStd_HSequenceOfInteger;
220   for (int i = 0; i < theData.length(); i++) aColumn->Append(theData[i]);
221   try {
222     aTable->SetColumnData(aTable->GetNbColumns() + 1, aColumn);
223   }
224   catch(Standard_Failure) {
225     throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
226   }  
227 }
228
229 void SALOMEDS_AttributeTableOfInteger_i::SetColumn(CORBA::Long theColumn, const SALOMEDS::LongSeq& theData)
230      throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength, SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
231 {
232   SALOMEDS::Locker lock;
233   Unexpect aCatch(ATI_IncorrectArgumentLength);
234   CheckLocked();
235   Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
236   
237   Handle(TColStd_HSequenceOfInteger) aColumn = new TColStd_HSequenceOfInteger;
238   for (int i = 0; i < theData.length(); i++) aColumn->Append(theData[i]);
239   try {
240     aTable->SetColumnData(theColumn, aColumn);
241   }
242   catch(Standard_Failure) {
243     throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
244   }
245 }
246
247 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfInteger_i::GetColumn(CORBA::Long theColumn)
248      throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
249 {
250   SALOMEDS::Locker lock;
251   Unexpect aCatch(ATI_IncorrectIndex);
252   Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
253   if (theColumn <= 0 || theColumn > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
254
255   SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
256   Handle(TColStd_HSequenceOfInteger) aColumn = aTable->GetColumnData(theColumn);
257   CorbaSeq->length(aColumn->Length());
258   for (int i = 0; i < aColumn->Length(); i++) {
259     CorbaSeq[i] = aColumn->Value(i + 1);
260   }
261   return CorbaSeq._retn();
262 }
263
264 void SALOMEDS_AttributeTableOfInteger_i::PutValue(CORBA::Long theValue, CORBA::Long theRow, CORBA::Long theColumn)
265      throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
266 {
267   SALOMEDS::Locker lock;
268   Unexpect aCatch(ATI_IncorrectIndex);
269   CheckLocked();
270   Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
271
272   try {
273     aTable->PutValue(theValue, theRow, theColumn);
274   }
275   catch(Standard_Failure) {
276     throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
277   }
278 }
279
280 CORBA::Boolean SALOMEDS_AttributeTableOfInteger_i::HasValue(CORBA::Long theRow, CORBA::Long theColumn) 
281 {
282   SALOMEDS::Locker lock;
283   return Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl)->HasValue(theRow, theColumn);
284 }
285
286 CORBA::Long SALOMEDS_AttributeTableOfInteger_i::GetValue(CORBA::Long theRow, CORBA::Long theColumn)
287      throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
288 {
289   SALOMEDS::Locker lock;
290   Unexpect aCatch(ATI_IncorrectIndex);
291   Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
292   if (theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
293
294   CORBA::Long aValue;
295   try {
296     aValue = aTable->GetValue(theRow, theColumn);
297   }
298   catch(Standard_Failure) {
299     throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
300   }
301   return aValue;
302 }
303
304 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfInteger_i::GetRowSetIndices(CORBA::Long theRow) 
305 {
306   SALOMEDS::Locker lock;
307   Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
308
309   if(theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
310
311   SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
312   Handle(TColStd_HSequenceOfInteger) aSeq = aTable->GetSetRowIndices(theRow);
313   CorbaSeq->length(aSeq->Length());
314   for (int i = 0; i < aSeq->Length(); i++) {
315     CorbaSeq[i] = aSeq->Value(i + 1);
316   }
317   return CorbaSeq._retn(); 
318 }
319
320
321 void SALOMEDS_AttributeTableOfInteger_i::SetNbColumns(CORBA::Long theNbColumns)
322 {
323   SALOMEDS::Locker lock;
324   Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
325   aTable->SetNbColumns(theNbColumns);
326 }
327
328 bool SALOMEDS_AttributeTableOfInteger_i::ReadFromFile(const SALOMEDS::TMPFile& theStream) 
329 {
330   SALOMEDS::Locker lock;
331   Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
332
333   istrstream aStream((char*)&theStream[0], theStream.length());
334   return aTable->RestoreFromString(aStream);
335 }
336
337 SALOMEDS::TMPFile*  SALOMEDS_AttributeTableOfInteger_i::SaveToFile()
338 {
339   SALOMEDS::Locker lock;
340   Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
341
342   ostrstream ostr;
343   string aString;
344   aTable->ConvertToString(ostr);
345
346   aString = ostr.rdbuf()->str();
347
348   char* aBuffer = (char*)CORBA::string_dup(aString.c_str());
349   int aBufferSize = strlen((char*)aBuffer);
350
351   CORBA::Octet* anOctetBuf =  (CORBA::Octet*)aBuffer;
352
353   SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1);
354
355   return aStreamFile._retn();
356 }
357
358