1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
18 // See http://www.salome-platform.org/
20 // File : SALOMEDS_AttributeTableOfInteger_i.cxx
21 // Author : Sergey RUIN
25 #include "SALOMEDS_AttributeTableOfInteger_i.hxx"
26 #include "SALOMEDS.hxx"
28 #include <TColStd_HSequenceOfInteger.hxx>
29 #include <Standard_Failure.hxx>
30 #include <Standard_ErrorHandler.hxx>
31 #include "Utils_ExceptHandlers.hxx"
39 UNEXPECT_CATCH(ATI_IncorrectIndex, SALOMEDS::AttributeTableOfInteger::IncorrectIndex);
40 UNEXPECT_CATCH(ATI_IncorrectArgumentLength, SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength);
42 void SALOMEDS_AttributeTableOfInteger_i::SetTitle(const char* theTitle)
44 SALOMEDS::Locker lock;
46 CORBA::String_var aStr = CORBA::string_dup(theTitle);
47 Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl)->SetTitle(TCollection_ExtendedString(aStr));
50 char* SALOMEDS_AttributeTableOfInteger_i::GetTitle()
52 SALOMEDS::Locker lock;
53 Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
54 CORBA::String_var c_s = CORBA::string_dup(TCollection_AsciiString(aTable->GetTitle()).ToCString());
58 void SALOMEDS_AttributeTableOfInteger_i::SetRowTitle(CORBA::Long theIndex, const char* theTitle)
59 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
61 SALOMEDS::Locker lock;
62 Unexpect aCatch (ATI_IncorrectIndex);
64 Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
65 if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
66 aTable->SetRowTitle(theIndex, TCollection_ExtendedString((char*)theTitle));
69 void SALOMEDS_AttributeTableOfInteger_i::SetRowTitles(const SALOMEDS::StringSeq& theTitles)
70 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
72 SALOMEDS::Locker lock;
73 Unexpect aCatch (ATI_IncorrectArgumentLength);
75 Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
76 if (theTitles.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
77 for (int i = 0; i < theTitles.length(); i++) {
78 SetRowTitle(i + 1, theTitles[i]);
82 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfInteger_i::GetRowTitles()
84 SALOMEDS::Locker lock;
85 Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
86 SALOMEDS::StringSeq_var aTitles = new SALOMEDS::StringSeq;
87 aTitles->length(aTable->GetNbRows());
88 for(int i = 0; i < aTitles->length(); i++)
89 aTitles[i] = CORBA::string_dup(TCollection_AsciiString(aTable->GetRowTitle(i + 1)).ToCString());
90 return aTitles._retn();
93 void SALOMEDS_AttributeTableOfInteger_i::SetColumnTitle(CORBA::Long theIndex, const char* theTitle)
94 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
96 SALOMEDS::Locker lock;
97 Unexpect aCatch (ATI_IncorrectIndex);
99 Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
100 if (theIndex <= 0 || theIndex > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
101 CORBA::String_var aStr = CORBA::string_dup(theTitle);
102 aTable->SetColumnTitle(theIndex, TCollection_ExtendedString(aStr));
105 void SALOMEDS_AttributeTableOfInteger_i::SetColumnTitles(const SALOMEDS::StringSeq& theTitles)
106 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
108 SALOMEDS::Locker lock;
109 Unexpect aCatch(ATI_IncorrectArgumentLength);
111 Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
112 if (theTitles.length() != aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
113 for (int i = 0; i < theTitles.length(); i++) {
114 aTable->SetColumnTitle(i + 1, (char*)theTitles[i].in());
118 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfInteger_i::GetColumnTitles()
120 SALOMEDS::Locker lock;
121 Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
122 SALOMEDS::StringSeq_var aTitles = new SALOMEDS::StringSeq;
123 aTitles->length(aTable->GetNbColumns());
124 for(int i = 0; i < aTitles->length(); i++)
125 aTitles[i] = CORBA::string_dup(TCollection_AsciiString(aTable->GetColumnTitle(i + 1)).ToCString());
126 return aTitles._retn();
130 void SALOMEDS_AttributeTableOfInteger_i::SetRowUnit(CORBA::Long theIndex, const char* theUnit)
131 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
133 SALOMEDS::Locker lock;
134 Unexpect aCatch (ATI_IncorrectIndex);
136 Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
137 if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
138 aTable->SetRowUnit(theIndex, TCollection_ExtendedString((char*)theUnit));
141 void SALOMEDS_AttributeTableOfInteger_i::SetRowUnits(const SALOMEDS::StringSeq& theUnits)
142 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
144 SALOMEDS::Locker lock;
145 Unexpect aCatch (ATI_IncorrectArgumentLength);
147 Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
148 if (theUnits.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
149 for (int i = 0; i < theUnits.length(); i++) {
150 aTable->SetRowUnit(i + 1, (char*)theUnits[i].in());
154 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfInteger_i::GetRowUnits()
156 SALOMEDS::Locker lock;
157 Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
158 SALOMEDS::StringSeq_var aUnits = new SALOMEDS::StringSeq;
159 aUnits->length(aTable->GetNbRows());
160 for(int i = 0; i < aUnits->length(); i++)
161 aUnits[i] = CORBA::string_dup(TCollection_AsciiString(aTable->GetRowUnit(i + 1)).ToCString());
162 return aUnits._retn();
165 CORBA::Long SALOMEDS_AttributeTableOfInteger_i::GetNbRows()
167 SALOMEDS::Locker lock;
168 return Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl)->GetNbRows();
171 CORBA::Long SALOMEDS_AttributeTableOfInteger_i::GetNbColumns()
173 SALOMEDS::Locker lock;
174 return Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl)->GetNbColumns();
177 void SALOMEDS_AttributeTableOfInteger_i::AddRow(const SALOMEDS::LongSeq& theData)
178 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
180 SALOMEDS::Locker lock;
181 Unexpect aCatch(ATI_IncorrectArgumentLength);
183 Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
185 Handle(TColStd_HSequenceOfInteger) aRow = new TColStd_HSequenceOfInteger;
186 for (int i = 0; i < theData.length(); i++) aRow->Append(theData[i]);
188 aTable->SetRowData(aTable->GetNbRows() + 1, aRow);
190 catch(Standard_Failure) {
191 throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
195 void SALOMEDS_AttributeTableOfInteger_i::SetRow(CORBA::Long theRow, const SALOMEDS::LongSeq& theData)
196 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength, SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
198 SALOMEDS::Locker lock;
199 Unexpect aCatch(ATI_IncorrectArgumentLength);
201 Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
203 Handle(TColStd_HSequenceOfInteger) aRow = new TColStd_HSequenceOfInteger;
204 for (int i = 0; i < theData.length(); i++) aRow->Append(theData[i]);
206 aTable->SetRowData(theRow, aRow);
208 catch(Standard_Failure) {
209 throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
213 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfInteger_i::GetRow(CORBA::Long theRow)
214 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
216 SALOMEDS::Locker lock;
217 Unexpect aCatch(ATI_IncorrectIndex);
218 Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
219 if (theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
221 SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
222 Handle(TColStd_HSequenceOfInteger) aRow = aTable->GetRowData(theRow);
223 CorbaSeq->length(aRow->Length());
224 for (int i = 0; i < aRow->Length(); i++) {
225 CorbaSeq[i] = aRow->Value(i + 1);
227 return CorbaSeq._retn();
230 void SALOMEDS_AttributeTableOfInteger_i::AddColumn(const SALOMEDS::LongSeq& theData)
231 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
233 SALOMEDS::Locker lock;
234 Unexpect aCatch(ATI_IncorrectArgumentLength);
236 Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
238 Handle(TColStd_HSequenceOfInteger) aColumn = new TColStd_HSequenceOfInteger;
239 for (int i = 0; i < theData.length(); i++) aColumn->Append(theData[i]);
241 aTable->SetColumnData(aTable->GetNbColumns() + 1, aColumn);
243 catch(Standard_Failure) {
244 throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
248 void SALOMEDS_AttributeTableOfInteger_i::SetColumn(CORBA::Long theColumn, const SALOMEDS::LongSeq& theData)
249 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength, SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
251 SALOMEDS::Locker lock;
252 Unexpect aCatch(ATI_IncorrectArgumentLength);
254 Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
256 Handle(TColStd_HSequenceOfInteger) aColumn = new TColStd_HSequenceOfInteger;
257 for (int i = 0; i < theData.length(); i++) aColumn->Append(theData[i]);
259 aTable->SetColumnData(theColumn, aColumn);
261 catch(Standard_Failure) {
262 throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
266 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfInteger_i::GetColumn(CORBA::Long theColumn)
267 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
269 SALOMEDS::Locker lock;
270 Unexpect aCatch(ATI_IncorrectIndex);
271 Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
272 if (theColumn <= 0 || theColumn > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
274 SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
275 Handle(TColStd_HSequenceOfInteger) aColumn = aTable->GetColumnData(theColumn);
276 CorbaSeq->length(aColumn->Length());
277 for (int i = 0; i < aColumn->Length(); i++) {
278 CorbaSeq[i] = aColumn->Value(i + 1);
280 return CorbaSeq._retn();
283 void SALOMEDS_AttributeTableOfInteger_i::PutValue(CORBA::Long theValue, CORBA::Long theRow, CORBA::Long theColumn)
284 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
286 SALOMEDS::Locker lock;
287 Unexpect aCatch(ATI_IncorrectIndex);
289 Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
292 aTable->PutValue(theValue, theRow, theColumn);
294 catch(Standard_Failure) {
295 throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
299 CORBA::Boolean SALOMEDS_AttributeTableOfInteger_i::HasValue(CORBA::Long theRow, CORBA::Long theColumn)
301 SALOMEDS::Locker lock;
302 return Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl)->HasValue(theRow, theColumn);
305 CORBA::Long SALOMEDS_AttributeTableOfInteger_i::GetValue(CORBA::Long theRow, CORBA::Long theColumn)
306 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
308 SALOMEDS::Locker lock;
309 Unexpect aCatch(ATI_IncorrectIndex);
310 Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
311 if (theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
315 aValue = aTable->GetValue(theRow, theColumn);
317 catch(Standard_Failure) {
318 throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
323 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfInteger_i::GetRowSetIndices(CORBA::Long theRow)
325 SALOMEDS::Locker lock;
326 Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
328 if(theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
330 SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
331 Handle(TColStd_HSequenceOfInteger) aSeq = aTable->GetSetRowIndices(theRow);
332 CorbaSeq->length(aSeq->Length());
333 for (int i = 0; i < aSeq->Length(); i++) {
334 CorbaSeq[i] = aSeq->Value(i + 1);
336 return CorbaSeq._retn();
340 void SALOMEDS_AttributeTableOfInteger_i::SetNbColumns(CORBA::Long theNbColumns)
342 SALOMEDS::Locker lock;
343 Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
344 aTable->SetNbColumns(theNbColumns);
347 bool SALOMEDS_AttributeTableOfInteger_i::ReadFromFile(const SALOMEDS::TMPFile& theStream)
349 SALOMEDS::Locker lock;
350 Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
352 istrstream aStream((char*)&theStream[0], theStream.length());
353 return aTable->RestoreFromString(aStream);
356 SALOMEDS::TMPFile* SALOMEDS_AttributeTableOfInteger_i::SaveToFile()
358 SALOMEDS::Locker lock;
359 Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_impl);
363 aTable->ConvertToString(ostr);
365 aString = ostr.rdbuf()->str();
367 char* aBuffer = (char*)CORBA::string_dup(aString.c_str());
368 int aBufferSize = strlen((char*)aBuffer);
370 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
372 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1);
374 return aStreamFile._retn();