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_AttributeTableOfString_i.cxx
23 // Author : Sergey RUIN
26 #include "SALOMEDS_AttributeTableOfString_i.hxx"
27 #include "SALOMEDS.hxx"
33 #include "Utils_ExceptHandlers.hxx"
37 UNEXPECT_CATCH(ATS_IncorrectIndex, SALOMEDS::AttributeTableOfString::IncorrectIndex);
38 UNEXPECT_CATCH(ATS_IncorrectArgumentLength, SALOMEDS::AttributeTableOfString::IncorrectArgumentLength);
40 void SALOMEDS_AttributeTableOfString_i::SetTitle(const char* theTitle)
42 SALOMEDS::Locker lock;
44 SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
45 CORBA::String_var aStr = CORBA::string_dup(theTitle);
46 aTable->SetTitle(string(aStr));
49 char* SALOMEDS_AttributeTableOfString_i::GetTitle()
51 SALOMEDS::Locker lock;
52 SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
53 CORBA::String_var c_s = CORBA::string_dup(aTable->GetTitle().c_str());
57 void SALOMEDS_AttributeTableOfString_i::SetRowTitle(CORBA::Long theIndex, const char* theTitle)
58 throw (SALOMEDS::AttributeTableOfString::IncorrectIndex)
60 SALOMEDS::Locker lock;
61 Unexpect aCatch(ATS_IncorrectIndex);
63 SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
64 if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
66 aTable->SetRowTitle(theIndex, string(theTitle));
69 void SALOMEDS_AttributeTableOfString_i::SetRowTitles(const SALOMEDS::StringSeq& theTitles)
70 throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength)
72 SALOMEDS::Locker lock;
73 Unexpect aCatch(ATS_IncorrectArgumentLength);
75 SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
76 if (theTitles.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectArgumentLength();
77 for (int i = 0; i < theTitles.length(); i++) {
78 aTable->SetRowTitle(i + 1, string((char*)theTitles[i].in()));
82 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfString_i::GetRowTitles()
84 SALOMEDS::Locker lock;
85 SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_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(aTable->GetRowTitle(i + 1).c_str());
90 return aTitles._retn();
93 void SALOMEDS_AttributeTableOfString_i::SetColumnTitle(CORBA::Long theIndex, const char* theTitle)
94 throw (SALOMEDS::AttributeTableOfString::IncorrectIndex)
96 SALOMEDS::Locker lock;
97 Unexpect aCatch(ATS_IncorrectIndex);
99 SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
100 if (theIndex <= 0 || theIndex > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
101 aTable->SetColumnTitle(theIndex, string((char*)theTitle));
104 void SALOMEDS_AttributeTableOfString_i::SetColumnTitles(const SALOMEDS::StringSeq& theTitles)
105 throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength)
107 SALOMEDS::Locker lock;
108 Unexpect aCatch(ATS_IncorrectArgumentLength);
110 SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
111 if (theTitles.length() != aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfString::IncorrectArgumentLength();
112 for (int i = 0; i < theTitles.length(); i++) {
113 aTable->SetColumnTitle(i + 1, string((char*)theTitles[i].in()));
117 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfString_i::GetColumnTitles()
119 SALOMEDS::Locker lock;
120 SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_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_AttributeTableOfString_i::SetRowUnit(CORBA::Long theIndex, const char* theUnit)
130 throw (SALOMEDS::AttributeTableOfString::IncorrectIndex)
132 SALOMEDS::Locker lock;
133 Unexpect aCatch(ATS_IncorrectIndex);
135 SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
136 if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
137 aTable->SetRowUnit(theIndex, string((char*)theUnit));
140 void SALOMEDS_AttributeTableOfString_i::SetRowUnits(const SALOMEDS::StringSeq& theUnits)
141 throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength)
143 SALOMEDS::Locker lock;
144 Unexpect aCatch(ATS_IncorrectArgumentLength);
146 SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
147 if (theUnits.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectArgumentLength();
148 for (int i = 0; i < theUnits.length(); i++) {
149 aTable->SetRowUnit(i + 1, string((char*)theUnits[i].in()));
153 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfString_i::GetRowUnits()
155 SALOMEDS::Locker lock;
156 SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_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();
165 CORBA::Long SALOMEDS_AttributeTableOfString_i::GetNbRows()
167 SALOMEDS::Locker lock;
168 return dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl)->GetNbRows();
171 CORBA::Long SALOMEDS_AttributeTableOfString_i::GetNbColumns()
173 SALOMEDS::Locker lock;
174 return dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl)->GetNbColumns();
177 void SALOMEDS_AttributeTableOfString_i::AddRow(const SALOMEDS::StringSeq& theData)
178 throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength)
180 SALOMEDS::Locker lock;
181 Unexpect aCatch(ATS_IncorrectArgumentLength);
183 SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
186 for (int i = 0; i < theData.length(); i++) aRow.push_back(string(CORBA::string_dup(theData[i])));
187 aTable->SetRowData(aTable->GetNbRows() + 1, aRow);
190 void SALOMEDS_AttributeTableOfString_i::SetRow(CORBA::Long theRow, const SALOMEDS::StringSeq& theData)
191 throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength, SALOMEDS::AttributeTableOfString::IncorrectIndex)
193 SALOMEDS::Locker lock;
194 Unexpect aCatch(ATS_IncorrectArgumentLength);
196 SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
199 for (int i = 0; i < theData.length(); i++) aRow.push_back(string(CORBA::string_dup(theData[i].in())));
200 aTable->SetRowData(theRow, aRow);
203 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfString_i::GetRow(CORBA::Long theRow)
204 throw (SALOMEDS::AttributeTableOfString::IncorrectIndex)
206 SALOMEDS::Locker lock;
207 Unexpect aCatch(ATS_IncorrectIndex);
208 SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
209 if (theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
211 SALOMEDS::StringSeq_var CorbaSeq = new SALOMEDS::StringSeq;
212 vector<string> aRow = aTable->GetRowData(theRow);
213 CorbaSeq->length(aRow.size());
214 for (int i = 0; i < aRow.size(); i++) {
215 CorbaSeq[i] = CORBA::string_dup(aRow[i].c_str());
217 return CorbaSeq._retn();
220 void SALOMEDS_AttributeTableOfString_i::AddColumn(const SALOMEDS::StringSeq& theData)
221 throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength)
223 SALOMEDS::Locker lock;
224 Unexpect aCatch(ATS_IncorrectArgumentLength);
226 SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
228 vector<string> aColumn;
229 for (int i = 0; i < theData.length(); i++) aColumn.push_back(string(CORBA::string_dup(theData[i])));
230 aTable->SetColumnData(aTable->GetNbColumns() + 1, aColumn);
233 void SALOMEDS_AttributeTableOfString_i::SetColumn(CORBA::Long theColumn, const SALOMEDS::StringSeq& theData)
234 throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength, SALOMEDS::AttributeTableOfString::IncorrectIndex)
236 SALOMEDS::Locker lock;
237 Unexpect aCatch(ATS_IncorrectArgumentLength);
239 SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
241 vector<string> aColumn;
242 for (int i = 0; i < theData.length(); i++) aColumn.push_back(string(CORBA::string_dup(theData[i])));
243 aTable->SetColumnData(theColumn, aColumn);
246 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfString_i::GetColumn(CORBA::Long theColumn)
247 throw (SALOMEDS::AttributeTableOfString::IncorrectIndex)
249 SALOMEDS::Locker lock;
250 Unexpect aCatch(ATS_IncorrectIndex);
251 SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
252 if (theColumn <= 0 || theColumn > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
254 SALOMEDS::StringSeq_var CorbaSeq = new SALOMEDS::StringSeq;
255 vector<string> aColumn = aTable->GetColumnData(theColumn);
256 CorbaSeq->length(aColumn.size());
257 for (int i = 0; i < aColumn.size(); i++) {
258 CorbaSeq[i] = CORBA::string_dup(aColumn[i].c_str());
260 return CorbaSeq._retn();
263 void SALOMEDS_AttributeTableOfString_i::PutValue(const char* theValue, CORBA::Long theRow, CORBA::Long theColumn)
264 throw (SALOMEDS::AttributeTableOfString::IncorrectIndex)
266 SALOMEDS::Locker lock;
267 Unexpect aCatch(ATS_IncorrectIndex);
269 SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
270 char* aValue = CORBA::string_dup(theValue);
272 aTable->PutValue(aValue, theRow, theColumn);
275 CORBA::Boolean SALOMEDS_AttributeTableOfString_i::HasValue(CORBA::Long theRow, CORBA::Long theColumn)
277 SALOMEDS::Locker lock;
278 return dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl)->HasValue(theRow, theColumn);
281 char* SALOMEDS_AttributeTableOfString_i::GetValue(CORBA::Long theRow, CORBA::Long theColumn)
282 throw (SALOMEDS::AttributeTableOfString::IncorrectIndex)
284 SALOMEDS::Locker lock;
285 Unexpect aCatch(ATS_IncorrectIndex);
286 SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
287 if (theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
291 aValue = aTable->GetValue(theRow, theColumn);
294 throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
297 return CORBA::string_dup(aValue.c_str());
301 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfString_i::GetRowSetIndices(CORBA::Long theRow)
303 SALOMEDS::Locker lock;
304 SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
306 if(theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
308 SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
309 vector<int> aSeq = aTable->GetSetRowIndices(theRow);
310 CorbaSeq->length(aSeq.size());
311 for (int i = 0; i < aSeq.size(); i++) {
312 CorbaSeq[i] = aSeq[i];
314 return CorbaSeq._retn();
318 void SALOMEDS_AttributeTableOfString_i::SetNbColumns(CORBA::Long theNbColumns)
320 SALOMEDS::Locker lock;
321 SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
322 aTable->SetNbColumns(theNbColumns);
325 bool SALOMEDS_AttributeTableOfString_i::ReadFromFile(const SALOMEDS::TMPFile& theStream)
327 SALOMEDS::Locker lock;
328 SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
330 string aStream((char*)&theStream[0], theStream.length());
331 aTable->Load(aStream);
335 SALOMEDS::TMPFile* SALOMEDS_AttributeTableOfString_i::SaveToFile()
337 SALOMEDS::Locker lock;
338 SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
340 string aString = aTable->Save();
341 char* aBuffer = (char*)CORBA::string_dup(aString.c_str());
342 int aBufferSize = strlen((char*)aBuffer);
344 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
346 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1);
348 return aStreamFile._retn();