1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SALOMEDS_AttributeTableOfInteger_i.cxx
23 // Author : Sergey RUIN
26 #include "SALOMEDS_AttributeTableOfInteger_i.hxx"
27 #include "SALOMEDS.hxx"
29 #include "Utils_ExceptHandlers.hxx"
38 UNEXPECT_CATCH(ATI_IncorrectIndex, SALOMEDS::AttributeTableOfInteger::IncorrectIndex);
39 UNEXPECT_CATCH(ATI_IncorrectArgumentLength, SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength);
41 void SALOMEDS_AttributeTableOfInteger_i::SetTitle(const char* theTitle)
43 SALOMEDS::Locker lock;
45 CORBA::String_var aStr = CORBA::string_dup(theTitle);
46 dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl)->SetTitle(string(aStr));
49 char* SALOMEDS_AttributeTableOfInteger_i::GetTitle()
51 SALOMEDS::Locker lock;
52 SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
53 CORBA::String_var c_s = CORBA::string_dup(aTable->GetTitle().c_str());
57 void SALOMEDS_AttributeTableOfInteger_i::SetRowTitle(CORBA::Long theIndex, const char* theTitle)
58 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
60 SALOMEDS::Locker lock;
61 Unexpect aCatch (ATI_IncorrectIndex);
63 SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
64 if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
65 aTable->SetRowTitle(theIndex, string(theTitle));
68 void SALOMEDS_AttributeTableOfInteger_i::SetRowTitles(const SALOMEDS::StringSeq& theTitles)
69 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
71 SALOMEDS::Locker lock;
72 Unexpect aCatch (ATI_IncorrectArgumentLength);
74 SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
75 if (theTitles.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
76 for (int i = 0; i < theTitles.length(); i++) {
77 SetRowTitle(i + 1, theTitles[i]);
81 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfInteger_i::GetRowTitles()
83 SALOMEDS::Locker lock;
84 SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
85 SALOMEDS::StringSeq_var aTitles = new SALOMEDS::StringSeq;
86 aTitles->length(aTable->GetNbRows());
87 for(int i = 0; i < aTitles->length(); i++)
88 aTitles[i] = CORBA::string_dup(aTable->GetRowTitle(i + 1).c_str());
89 return aTitles._retn();
92 void SALOMEDS_AttributeTableOfInteger_i::SetColumnTitle(CORBA::Long theIndex, const char* theTitle)
93 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
95 SALOMEDS::Locker lock;
96 Unexpect aCatch (ATI_IncorrectIndex);
98 SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
99 if (theIndex <= 0 || theIndex > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
100 CORBA::String_var aStr = CORBA::string_dup(theTitle);
101 aTable->SetColumnTitle(theIndex, string(aStr));
104 void SALOMEDS_AttributeTableOfInteger_i::SetColumnTitles(const SALOMEDS::StringSeq& theTitles)
105 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
107 SALOMEDS::Locker lock;
108 Unexpect aCatch(ATI_IncorrectArgumentLength);
110 SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
111 if (theTitles.length() != aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
112 for (int i = 0; i < theTitles.length(); i++) {
113 aTable->SetColumnTitle(i + 1, (char*)theTitles[i].in());
117 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfInteger_i::GetColumnTitles()
119 SALOMEDS::Locker lock;
120 SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
121 SALOMEDS::StringSeq_var aTitles = new SALOMEDS::StringSeq;
122 aTitles->length(aTable->GetNbColumns());
123 for(int i = 0; i < aTitles->length(); i++)
124 aTitles[i] = CORBA::string_dup(aTable->GetColumnTitle(i + 1).c_str());
125 return aTitles._retn();
129 void SALOMEDS_AttributeTableOfInteger_i::SetRowUnit(CORBA::Long theIndex, const char* theUnit)
130 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
132 SALOMEDS::Locker lock;
133 Unexpect aCatch (ATI_IncorrectIndex);
135 SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
136 if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
137 aTable->SetRowUnit(theIndex, string(theUnit));
140 void SALOMEDS_AttributeTableOfInteger_i::SetRowUnits(const SALOMEDS::StringSeq& theUnits)
141 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
143 SALOMEDS::Locker lock;
144 Unexpect aCatch (ATI_IncorrectArgumentLength);
146 SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
147 if (theUnits.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
148 for (int i = 0; i < theUnits.length(); i++) {
149 aTable->SetRowUnit(i + 1, (char*)theUnits[i].in());
153 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfInteger_i::GetRowUnits()
155 SALOMEDS::Locker lock;
156 SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
157 SALOMEDS::StringSeq_var aUnits = new SALOMEDS::StringSeq;
158 aUnits->length(aTable->GetNbRows());
159 for(int i = 0; i < aUnits->length(); i++)
160 aUnits[i] = CORBA::string_dup(aTable->GetRowUnit(i + 1).c_str());
161 return aUnits._retn();
164 CORBA::Long SALOMEDS_AttributeTableOfInteger_i::GetNbRows()
166 SALOMEDS::Locker lock;
167 return dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl)->GetNbRows();
170 CORBA::Long SALOMEDS_AttributeTableOfInteger_i::GetNbColumns()
172 SALOMEDS::Locker lock;
173 return dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl)->GetNbColumns();
176 void SALOMEDS_AttributeTableOfInteger_i::AddRow(const SALOMEDS::LongSeq& theData)
177 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
179 SALOMEDS::Locker lock;
180 Unexpect aCatch(ATI_IncorrectArgumentLength);
182 SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
185 for (int i = 0; i < theData.length(); i++) aRow.push_back(theData[i]);
187 aTable->SetRowData(aTable->GetNbRows() + 1, aRow);
190 throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
194 void SALOMEDS_AttributeTableOfInteger_i::SetRow(CORBA::Long theRow, const SALOMEDS::LongSeq& theData)
195 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength, SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
197 SALOMEDS::Locker lock;
198 Unexpect aCatch(ATI_IncorrectArgumentLength);
200 SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
203 for (int i = 0; i < theData.length(); i++) aRow.push_back(theData[i]);
205 aTable->SetRowData(theRow, aRow);
208 throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
212 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfInteger_i::GetRow(CORBA::Long theRow)
213 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
215 SALOMEDS::Locker lock;
216 Unexpect aCatch(ATI_IncorrectIndex);
217 SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
218 if (theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
220 SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
221 vector<int> aRow = aTable->GetRowData(theRow);
222 CorbaSeq->length(aRow.size());
223 for (int i = 0; i < aRow.size(); i++) {
224 CorbaSeq[i] = aRow[i];
226 return CorbaSeq._retn();
229 void SALOMEDS_AttributeTableOfInteger_i::AddColumn(const SALOMEDS::LongSeq& theData)
230 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
232 SALOMEDS::Locker lock;
233 Unexpect aCatch(ATI_IncorrectArgumentLength);
235 SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
238 for (int i = 0; i < theData.length(); i++) aColumn.push_back(theData[i]);
240 aTable->SetColumnData(aTable->GetNbColumns() + 1, aColumn);
243 throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
247 void SALOMEDS_AttributeTableOfInteger_i::SetColumn(CORBA::Long theColumn, const SALOMEDS::LongSeq& theData)
248 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength, SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
250 SALOMEDS::Locker lock;
251 Unexpect aCatch(ATI_IncorrectArgumentLength);
253 SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
256 for (int i = 0; i < theData.length(); i++) aColumn.push_back(theData[i]);
258 aTable->SetColumnData(theColumn, aColumn);
261 throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
265 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfInteger_i::GetColumn(CORBA::Long theColumn)
266 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
268 SALOMEDS::Locker lock;
269 Unexpect aCatch(ATI_IncorrectIndex);
270 SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
271 if (theColumn <= 0 || theColumn > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
273 SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
274 vector<int> aColumn = aTable->GetColumnData(theColumn);
275 CorbaSeq->length(aColumn.size());
276 for (int i = 0; i < aColumn.size(); i++) {
277 CorbaSeq[i] = aColumn[i];
279 return CorbaSeq._retn();
282 void SALOMEDS_AttributeTableOfInteger_i::PutValue(CORBA::Long theValue, CORBA::Long theRow, CORBA::Long theColumn)
283 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
285 SALOMEDS::Locker lock;
286 Unexpect aCatch(ATI_IncorrectIndex);
288 SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
291 aTable->PutValue(theValue, theRow, theColumn);
294 throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
298 CORBA::Boolean SALOMEDS_AttributeTableOfInteger_i::HasValue(CORBA::Long theRow, CORBA::Long theColumn)
300 SALOMEDS::Locker lock;
301 return dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl)->HasValue(theRow, theColumn);
304 CORBA::Long SALOMEDS_AttributeTableOfInteger_i::GetValue(CORBA::Long theRow, CORBA::Long theColumn)
305 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
307 SALOMEDS::Locker lock;
308 Unexpect aCatch(ATI_IncorrectIndex);
309 SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
310 if (theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
314 aValue = aTable->GetValue(theRow, theColumn);
317 throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
322 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfInteger_i::GetRowSetIndices(CORBA::Long theRow)
324 SALOMEDS::Locker lock;
325 SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
327 if(theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
329 SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
330 vector<int> aSeq = aTable->GetSetRowIndices(theRow);
331 CorbaSeq->length(aSeq.size());
332 for (int i = 0; i < aSeq.size(); i++) {
333 CorbaSeq[i] = aSeq[i];
335 return CorbaSeq._retn();
339 void SALOMEDS_AttributeTableOfInteger_i::SetNbColumns(CORBA::Long theNbColumns)
341 SALOMEDS::Locker lock;
342 SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
343 aTable->SetNbColumns(theNbColumns);
346 bool SALOMEDS_AttributeTableOfInteger_i::ReadFromFile(const SALOMEDS::TMPFile& theStream)
348 SALOMEDS::Locker lock;
349 SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
351 string aStream((char*)&theStream[0], theStream.length());
352 aTable->Load(aStream);
356 SALOMEDS::TMPFile* SALOMEDS_AttributeTableOfInteger_i::SaveToFile()
358 SALOMEDS::Locker lock;
359 SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
361 string aString = aTable->Save();
363 char* aBuffer = (char*)CORBA::string_dup(aString.c_str());
364 int aBufferSize = strlen((char*)aBuffer);
366 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
368 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1);
370 return aStreamFile._retn();