1 // File : SALOMEDS_AttributeTableOfInteger_i.cxx
2 // Author : Sergey RUIN
6 #include "SALOMEDS_AttributeTableOfInteger_i.hxx"
7 #include "SALOMEDS.hxx"
9 #include <TColStd_HSequenceOfInteger.hxx>
10 #include <Standard_Failure.hxx>
11 #include <Standard_ErrorHandler.hxx>
12 #include "Utils_ExceptHandlers.hxx"
20 UNEXPECT_CATCH(ATI_IncorrectIndex, SALOMEDS::AttributeTableOfInteger::IncorrectIndex);
21 UNEXPECT_CATCH(ATI_IncorrectArgumentLength, SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength);
23 void SALOMEDS_AttributeTableOfInteger_i::SetTitle(const char* theTitle)
25 SALOMEDS::Locker lock;
27 CORBA::String_var aStr = CORBA::string_dup(theTitle);
28 Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl)->SetTitle(TCollection_ExtendedString(aStr));
31 char* SALOMEDS_AttributeTableOfInteger_i::GetTitle()
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());
39 void SALOMEDS_AttributeTableOfInteger_i::SetRowTitle(CORBA::Long theIndex, const char* theTitle)
40 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
42 SALOMEDS::Locker lock;
43 Unexpect aCatch (ATI_IncorrectIndex);
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));
50 void SALOMEDS_AttributeTableOfInteger_i::SetRowTitles(const SALOMEDS::StringSeq& theTitles)
51 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
53 SALOMEDS::Locker lock;
54 Unexpect aCatch (ATI_IncorrectArgumentLength);
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]);
63 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfInteger_i::GetRowTitles()
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();
74 void SALOMEDS_AttributeTableOfInteger_i::SetColumnTitle(CORBA::Long theIndex, const char* theTitle)
75 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
77 SALOMEDS::Locker lock;
78 Unexpect aCatch (ATI_IncorrectIndex);
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));
86 void SALOMEDS_AttributeTableOfInteger_i::SetColumnTitles(const SALOMEDS::StringSeq& theTitles)
87 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
89 SALOMEDS::Locker lock;
90 Unexpect aCatch(ATI_IncorrectArgumentLength);
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());
99 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfInteger_i::GetColumnTitles()
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();
111 void SALOMEDS_AttributeTableOfInteger_i::SetRowUnit(CORBA::Long theIndex, const char* theUnit)
112 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
114 SALOMEDS::Locker lock;
115 Unexpect aCatch (ATI_IncorrectIndex);
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));
122 void SALOMEDS_AttributeTableOfInteger_i::SetRowUnits(const SALOMEDS::StringSeq& theUnits)
123 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
125 SALOMEDS::Locker lock;
126 Unexpect aCatch (ATI_IncorrectArgumentLength);
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());
135 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfInteger_i::GetRowUnits()
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();
146 CORBA::Long SALOMEDS_AttributeTableOfInteger_i::GetNbRows()
148 SALOMEDS::Locker lock;
149 return Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl)->GetNbRows();
152 CORBA::Long SALOMEDS_AttributeTableOfInteger_i::GetNbColumns()
154 SALOMEDS::Locker lock;
155 return Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl)->GetNbColumns();
158 void SALOMEDS_AttributeTableOfInteger_i::AddRow(const SALOMEDS::LongSeq& theData)
159 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
161 SALOMEDS::Locker lock;
162 Unexpect aCatch(ATI_IncorrectArgumentLength);
164 Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
166 Handle(TColStd_HSequenceOfInteger) aRow = new TColStd_HSequenceOfInteger;
167 for (int i = 0; i < theData.length(); i++) aRow->Append(theData[i]);
169 aTable->SetRowData(aTable->GetNbRows() + 1, aRow);
171 catch(Standard_Failure) {
172 throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
176 void SALOMEDS_AttributeTableOfInteger_i::SetRow(CORBA::Long theRow, const SALOMEDS::LongSeq& theData)
177 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength, SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
179 SALOMEDS::Locker lock;
180 Unexpect aCatch(ATI_IncorrectArgumentLength);
182 Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
184 Handle(TColStd_HSequenceOfInteger) aRow = new TColStd_HSequenceOfInteger;
185 for (int i = 0; i < theData.length(); i++) aRow->Append(theData[i]);
187 aTable->SetRowData(theRow, aRow);
189 catch(Standard_Failure) {
190 throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
194 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfInteger_i::GetRow(CORBA::Long theRow)
195 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
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();
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);
208 return CorbaSeq._retn();
211 void SALOMEDS_AttributeTableOfInteger_i::AddColumn(const SALOMEDS::LongSeq& theData)
212 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
214 SALOMEDS::Locker lock;
215 Unexpect aCatch(ATI_IncorrectArgumentLength);
217 Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
219 Handle(TColStd_HSequenceOfInteger) aColumn = new TColStd_HSequenceOfInteger;
220 for (int i = 0; i < theData.length(); i++) aColumn->Append(theData[i]);
222 aTable->SetColumnData(aTable->GetNbColumns() + 1, aColumn);
224 catch(Standard_Failure) {
225 throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
229 void SALOMEDS_AttributeTableOfInteger_i::SetColumn(CORBA::Long theColumn, const SALOMEDS::LongSeq& theData)
230 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength, SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
232 SALOMEDS::Locker lock;
233 Unexpect aCatch(ATI_IncorrectArgumentLength);
235 Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
237 Handle(TColStd_HSequenceOfInteger) aColumn = new TColStd_HSequenceOfInteger;
238 for (int i = 0; i < theData.length(); i++) aColumn->Append(theData[i]);
240 aTable->SetColumnData(theColumn, aColumn);
242 catch(Standard_Failure) {
243 throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
247 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfInteger_i::GetColumn(CORBA::Long theColumn)
248 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
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();
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);
261 return CorbaSeq._retn();
264 void SALOMEDS_AttributeTableOfInteger_i::PutValue(CORBA::Long theValue, CORBA::Long theRow, CORBA::Long theColumn)
265 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
267 SALOMEDS::Locker lock;
268 Unexpect aCatch(ATI_IncorrectIndex);
270 Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
273 aTable->PutValue(theValue, theRow, theColumn);
275 catch(Standard_Failure) {
276 throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
280 CORBA::Boolean SALOMEDS_AttributeTableOfInteger_i::HasValue(CORBA::Long theRow, CORBA::Long theColumn)
282 SALOMEDS::Locker lock;
283 return Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl)->HasValue(theRow, theColumn);
286 CORBA::Long SALOMEDS_AttributeTableOfInteger_i::GetValue(CORBA::Long theRow, CORBA::Long theColumn)
287 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
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();
296 aValue = aTable->GetValue(theRow, theColumn);
298 catch(Standard_Failure) {
299 throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
304 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfInteger_i::GetRowSetIndices(CORBA::Long theRow)
306 SALOMEDS::Locker lock;
307 Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
309 if(theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
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);
317 return CorbaSeq._retn();
321 void SALOMEDS_AttributeTableOfInteger_i::SetNbColumns(CORBA::Long theNbColumns)
323 SALOMEDS::Locker lock;
324 Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
325 aTable->SetNbColumns(theNbColumns);
328 bool SALOMEDS_AttributeTableOfInteger_i::ReadFromFile(const SALOMEDS::TMPFile& theStream)
330 SALOMEDS::Locker lock;
331 Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
333 istrstream aStream((char*)&theStream[0], theStream.length());
334 return aTable->RestoreFromString(aStream);
337 SALOMEDS::TMPFile* SALOMEDS_AttributeTableOfInteger_i::SaveToFile()
339 SALOMEDS::Locker lock;
340 Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
344 aTable->ConvertToString(ostr);
346 aString = ostr.rdbuf()->str();
348 char* aBuffer = (char*)CORBA::string_dup(aString.c_str());
349 int aBufferSize = strlen((char*)aBuffer);
351 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
353 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1);
355 return aStreamFile._retn();