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/ or email : webmaster.salome@opencascade.com
20 // File : SALOMEDS_AttributeTableOfInteger_i.cxx
21 // Author : Sergey RUIN
25 #include "SALOMEDS_AttributeTableOfInteger_i.hxx"
26 #include "SALOMEDS.hxx"
28 #include "Utils_ExceptHandlers.hxx"
37 UNEXPECT_CATCH(ATI_IncorrectIndex, SALOMEDS::AttributeTableOfInteger::IncorrectIndex);
38 UNEXPECT_CATCH(ATI_IncorrectArgumentLength, SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength);
40 void SALOMEDS_AttributeTableOfInteger_i::SetTitle(const char* theTitle)
42 SALOMEDS::Locker lock;
44 CORBA::String_var aStr = CORBA::string_dup(theTitle);
45 dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl)->SetTitle(string(aStr));
48 char* SALOMEDS_AttributeTableOfInteger_i::GetTitle()
50 SALOMEDS::Locker lock;
51 SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
52 CORBA::String_var c_s = CORBA::string_dup(aTable->GetTitle().c_str());
56 void SALOMEDS_AttributeTableOfInteger_i::SetRowTitle(CORBA::Long theIndex, const char* theTitle)
57 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
59 SALOMEDS::Locker lock;
60 Unexpect aCatch (ATI_IncorrectIndex);
62 SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
63 if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
64 aTable->SetRowTitle(theIndex, string(theTitle));
67 void SALOMEDS_AttributeTableOfInteger_i::SetRowTitles(const SALOMEDS::StringSeq& theTitles)
68 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
70 SALOMEDS::Locker lock;
71 Unexpect aCatch (ATI_IncorrectArgumentLength);
73 SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
74 if (theTitles.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
75 for (int i = 0; i < theTitles.length(); i++) {
76 SetRowTitle(i + 1, theTitles[i]);
80 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfInteger_i::GetRowTitles()
82 SALOMEDS::Locker lock;
83 SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
84 SALOMEDS::StringSeq_var aTitles = new SALOMEDS::StringSeq;
85 aTitles->length(aTable->GetNbRows());
86 for(int i = 0; i < aTitles->length(); i++)
87 aTitles[i] = CORBA::string_dup(aTable->GetRowTitle(i + 1).c_str());
88 return aTitles._retn();
91 void SALOMEDS_AttributeTableOfInteger_i::SetColumnTitle(CORBA::Long theIndex, const char* theTitle)
92 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
94 SALOMEDS::Locker lock;
95 Unexpect aCatch (ATI_IncorrectIndex);
97 SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
98 if (theIndex <= 0 || theIndex > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
99 CORBA::String_var aStr = CORBA::string_dup(theTitle);
100 aTable->SetColumnTitle(theIndex, string(aStr));
103 void SALOMEDS_AttributeTableOfInteger_i::SetColumnTitles(const SALOMEDS::StringSeq& theTitles)
104 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
106 SALOMEDS::Locker lock;
107 Unexpect aCatch(ATI_IncorrectArgumentLength);
109 SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
110 if (theTitles.length() != aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
111 for (int i = 0; i < theTitles.length(); i++) {
112 aTable->SetColumnTitle(i + 1, (char*)theTitles[i].in());
116 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfInteger_i::GetColumnTitles()
118 SALOMEDS::Locker lock;
119 SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
120 SALOMEDS::StringSeq_var aTitles = new SALOMEDS::StringSeq;
121 aTitles->length(aTable->GetNbColumns());
122 for(int i = 0; i < aTitles->length(); i++)
123 aTitles[i] = CORBA::string_dup(aTable->GetColumnTitle(i + 1).c_str());
124 return aTitles._retn();
128 void SALOMEDS_AttributeTableOfInteger_i::SetRowUnit(CORBA::Long theIndex, const char* theUnit)
129 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
131 SALOMEDS::Locker lock;
132 Unexpect aCatch (ATI_IncorrectIndex);
134 SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
135 if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
136 aTable->SetRowUnit(theIndex, string(theUnit));
139 void SALOMEDS_AttributeTableOfInteger_i::SetRowUnits(const SALOMEDS::StringSeq& theUnits)
140 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
142 SALOMEDS::Locker lock;
143 Unexpect aCatch (ATI_IncorrectArgumentLength);
145 SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
146 if (theUnits.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
147 for (int i = 0; i < theUnits.length(); i++) {
148 aTable->SetRowUnit(i + 1, (char*)theUnits[i].in());
152 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfInteger_i::GetRowUnits()
154 SALOMEDS::Locker lock;
155 SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
156 SALOMEDS::StringSeq_var aUnits = new SALOMEDS::StringSeq;
157 aUnits->length(aTable->GetNbRows());
158 for(int i = 0; i < aUnits->length(); i++)
159 aUnits[i] = CORBA::string_dup(aTable->GetRowUnit(i + 1).c_str());
160 return aUnits._retn();
163 CORBA::Long SALOMEDS_AttributeTableOfInteger_i::GetNbRows()
165 SALOMEDS::Locker lock;
166 return dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl)->GetNbRows();
169 CORBA::Long SALOMEDS_AttributeTableOfInteger_i::GetNbColumns()
171 SALOMEDS::Locker lock;
172 return dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl)->GetNbColumns();
175 void SALOMEDS_AttributeTableOfInteger_i::AddRow(const SALOMEDS::LongSeq& theData)
176 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
178 SALOMEDS::Locker lock;
179 Unexpect aCatch(ATI_IncorrectArgumentLength);
181 SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
184 for (int i = 0; i < theData.length(); i++) aRow.push_back(theData[i]);
186 aTable->SetRowData(aTable->GetNbRows() + 1, aRow);
189 throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
193 void SALOMEDS_AttributeTableOfInteger_i::SetRow(CORBA::Long theRow, const SALOMEDS::LongSeq& theData)
194 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength, SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
196 SALOMEDS::Locker lock;
197 Unexpect aCatch(ATI_IncorrectArgumentLength);
199 SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
202 for (int i = 0; i < theData.length(); i++) aRow.push_back(theData[i]);
204 aTable->SetRowData(theRow, aRow);
207 throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
211 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfInteger_i::GetRow(CORBA::Long theRow)
212 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
214 SALOMEDS::Locker lock;
215 Unexpect aCatch(ATI_IncorrectIndex);
216 SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
217 if (theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
219 SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
220 vector<int> aRow = aTable->GetRowData(theRow);
221 CorbaSeq->length(aRow.size());
222 for (int i = 0; i < aRow.size(); i++) {
223 CorbaSeq[i] = aRow[i];
225 return CorbaSeq._retn();
228 void SALOMEDS_AttributeTableOfInteger_i::AddColumn(const SALOMEDS::LongSeq& theData)
229 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
231 SALOMEDS::Locker lock;
232 Unexpect aCatch(ATI_IncorrectArgumentLength);
234 SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
237 for (int i = 0; i < theData.length(); i++) aColumn.push_back(theData[i]);
239 aTable->SetColumnData(aTable->GetNbColumns() + 1, aColumn);
242 throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
246 void SALOMEDS_AttributeTableOfInteger_i::SetColumn(CORBA::Long theColumn, const SALOMEDS::LongSeq& theData)
247 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength, SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
249 SALOMEDS::Locker lock;
250 Unexpect aCatch(ATI_IncorrectArgumentLength);
252 SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
255 for (int i = 0; i < theData.length(); i++) aColumn.push_back(theData[i]);
257 aTable->SetColumnData(theColumn, aColumn);
260 throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
264 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfInteger_i::GetColumn(CORBA::Long theColumn)
265 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
267 SALOMEDS::Locker lock;
268 Unexpect aCatch(ATI_IncorrectIndex);
269 SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
270 if (theColumn <= 0 || theColumn > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
272 SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
273 vector<int> aColumn = aTable->GetColumnData(theColumn);
274 CorbaSeq->length(aColumn.size());
275 for (int i = 0; i < aColumn.size(); i++) {
276 CorbaSeq[i] = aColumn[i];
278 return CorbaSeq._retn();
281 void SALOMEDS_AttributeTableOfInteger_i::PutValue(CORBA::Long theValue, CORBA::Long theRow, CORBA::Long theColumn)
282 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
284 SALOMEDS::Locker lock;
285 Unexpect aCatch(ATI_IncorrectIndex);
287 SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
290 aTable->PutValue(theValue, theRow, theColumn);
293 throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
297 CORBA::Boolean SALOMEDS_AttributeTableOfInteger_i::HasValue(CORBA::Long theRow, CORBA::Long theColumn)
299 SALOMEDS::Locker lock;
300 return dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl)->HasValue(theRow, theColumn);
303 CORBA::Long SALOMEDS_AttributeTableOfInteger_i::GetValue(CORBA::Long theRow, CORBA::Long theColumn)
304 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
306 SALOMEDS::Locker lock;
307 Unexpect aCatch(ATI_IncorrectIndex);
308 SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
309 if (theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
313 aValue = aTable->GetValue(theRow, theColumn);
316 throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
321 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfInteger_i::GetRowSetIndices(CORBA::Long theRow)
323 SALOMEDS::Locker lock;
324 SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
326 if(theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
328 SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
329 vector<int> aSeq = aTable->GetSetRowIndices(theRow);
330 CorbaSeq->length(aSeq.size());
331 for (int i = 0; i < aSeq.size(); i++) {
332 CorbaSeq[i] = aSeq[i];
334 return CorbaSeq._retn();
338 void SALOMEDS_AttributeTableOfInteger_i::SetNbColumns(CORBA::Long theNbColumns)
340 SALOMEDS::Locker lock;
341 SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
342 aTable->SetNbColumns(theNbColumns);
345 bool SALOMEDS_AttributeTableOfInteger_i::ReadFromFile(const SALOMEDS::TMPFile& theStream)
347 SALOMEDS::Locker lock;
348 SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
350 string aStream((char*)&theStream[0], theStream.length());
351 aTable->Load(aStream);
355 SALOMEDS::TMPFile* SALOMEDS_AttributeTableOfInteger_i::SaveToFile()
357 SALOMEDS::Locker lock;
358 SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
360 string aString = aTable->Save();
362 char* aBuffer = (char*)CORBA::string_dup(aString.c_str());
363 int aBufferSize = strlen((char*)aBuffer);
365 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
367 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1);
369 return aStreamFile._retn();