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_AttributeTableOfString_i.cxx
21 // Author : Sergey RUIN
25 #include "SALOMEDS_AttributeTableOfString_i.hxx"
26 #include "SALOMEDS.hxx"
32 #include "Utils_ExceptHandlers.hxx"
36 UNEXPECT_CATCH(ATS_IncorrectIndex, SALOMEDS::AttributeTableOfString::IncorrectIndex);
37 UNEXPECT_CATCH(ATS_IncorrectArgumentLength, SALOMEDS::AttributeTableOfString::IncorrectArgumentLength);
39 void SALOMEDS_AttributeTableOfString_i::SetTitle(const char* theTitle)
41 SALOMEDS::Locker lock;
43 SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
44 CORBA::String_var aStr = CORBA::string_dup(theTitle);
45 aTable->SetTitle(string(aStr));
48 char* SALOMEDS_AttributeTableOfString_i::GetTitle()
50 SALOMEDS::Locker lock;
51 SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
52 CORBA::String_var c_s = CORBA::string_dup(aTable->GetTitle().c_str());
56 void SALOMEDS_AttributeTableOfString_i::SetRowTitle(CORBA::Long theIndex, const char* theTitle)
57 throw (SALOMEDS::AttributeTableOfString::IncorrectIndex)
59 SALOMEDS::Locker lock;
60 Unexpect aCatch(ATS_IncorrectIndex);
62 SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
63 if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
65 aTable->SetRowTitle(theIndex, string(theTitle));
68 void SALOMEDS_AttributeTableOfString_i::SetRowTitles(const SALOMEDS::StringSeq& theTitles)
69 throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength)
71 SALOMEDS::Locker lock;
72 Unexpect aCatch(ATS_IncorrectArgumentLength);
74 SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
75 if (theTitles.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectArgumentLength();
76 for (int i = 0; i < theTitles.length(); i++) {
77 aTable->SetRowTitle(i + 1, string((char*)theTitles[i].in()));
81 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfString_i::GetRowTitles()
83 SALOMEDS::Locker lock;
84 SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_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_AttributeTableOfString_i::SetColumnTitle(CORBA::Long theIndex, const char* theTitle)
93 throw (SALOMEDS::AttributeTableOfString::IncorrectIndex)
95 SALOMEDS::Locker lock;
96 Unexpect aCatch(ATS_IncorrectIndex);
98 SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
99 if (theIndex <= 0 || theIndex > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
100 aTable->SetColumnTitle(theIndex, string((char*)theTitle));
103 void SALOMEDS_AttributeTableOfString_i::SetColumnTitles(const SALOMEDS::StringSeq& theTitles)
104 throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength)
106 SALOMEDS::Locker lock;
107 Unexpect aCatch(ATS_IncorrectArgumentLength);
109 SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
110 if (theTitles.length() != aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfString::IncorrectArgumentLength();
111 for (int i = 0; i < theTitles.length(); i++) {
112 aTable->SetColumnTitle(i + 1, string((char*)theTitles[i].in()));
116 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfString_i::GetColumnTitles()
118 SALOMEDS::Locker lock;
119 SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_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_AttributeTableOfString_i::SetRowUnit(CORBA::Long theIndex, const char* theUnit)
129 throw (SALOMEDS::AttributeTableOfString::IncorrectIndex)
131 SALOMEDS::Locker lock;
132 Unexpect aCatch(ATS_IncorrectIndex);
134 SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
135 if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
136 aTable->SetRowUnit(theIndex, string((char*)theUnit));
139 void SALOMEDS_AttributeTableOfString_i::SetRowUnits(const SALOMEDS::StringSeq& theUnits)
140 throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength)
142 SALOMEDS::Locker lock;
143 Unexpect aCatch(ATS_IncorrectArgumentLength);
145 SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
146 if (theUnits.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectArgumentLength();
147 for (int i = 0; i < theUnits.length(); i++) {
148 aTable->SetRowUnit(i + 1, string((char*)theUnits[i].in()));
152 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfString_i::GetRowUnits()
154 SALOMEDS::Locker lock;
155 SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_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();
164 CORBA::Long SALOMEDS_AttributeTableOfString_i::GetNbRows()
166 SALOMEDS::Locker lock;
167 return dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl)->GetNbRows();
170 CORBA::Long SALOMEDS_AttributeTableOfString_i::GetNbColumns()
172 SALOMEDS::Locker lock;
173 return dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl)->GetNbColumns();
176 void SALOMEDS_AttributeTableOfString_i::AddRow(const SALOMEDS::StringSeq& theData)
177 throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength)
179 SALOMEDS::Locker lock;
180 Unexpect aCatch(ATS_IncorrectArgumentLength);
182 SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
185 for (int i = 0; i < theData.length(); i++) aRow.push_back(string(CORBA::string_dup(theData[i])));
186 aTable->SetRowData(aTable->GetNbRows() + 1, aRow);
189 void SALOMEDS_AttributeTableOfString_i::SetRow(CORBA::Long theRow, const SALOMEDS::StringSeq& theData)
190 throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength, SALOMEDS::AttributeTableOfString::IncorrectIndex)
192 SALOMEDS::Locker lock;
193 Unexpect aCatch(ATS_IncorrectArgumentLength);
195 SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
198 for (int i = 0; i < theData.length(); i++) aRow.push_back(string(CORBA::string_dup(theData[i].in())));
199 aTable->SetRowData(theRow, aRow);
202 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfString_i::GetRow(CORBA::Long theRow)
203 throw (SALOMEDS::AttributeTableOfString::IncorrectIndex)
205 SALOMEDS::Locker lock;
206 Unexpect aCatch(ATS_IncorrectIndex);
207 SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
208 if (theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
210 SALOMEDS::StringSeq_var CorbaSeq = new SALOMEDS::StringSeq;
211 vector<string> aRow = aTable->GetRowData(theRow);
212 CorbaSeq->length(aRow.size());
213 for (int i = 0; i < aRow.size(); i++) {
214 CorbaSeq[i] = CORBA::string_dup(aRow[i].c_str());
216 return CorbaSeq._retn();
219 void SALOMEDS_AttributeTableOfString_i::AddColumn(const SALOMEDS::StringSeq& theData)
220 throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength)
222 SALOMEDS::Locker lock;
223 Unexpect aCatch(ATS_IncorrectArgumentLength);
225 SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
227 vector<string> aColumn;
228 for (int i = 0; i < theData.length(); i++) aColumn.push_back(string(CORBA::string_dup(theData[i])));
229 aTable->SetColumnData(aTable->GetNbColumns() + 1, aColumn);
232 void SALOMEDS_AttributeTableOfString_i::SetColumn(CORBA::Long theColumn, const SALOMEDS::StringSeq& theData)
233 throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength, SALOMEDS::AttributeTableOfString::IncorrectIndex)
235 SALOMEDS::Locker lock;
236 Unexpect aCatch(ATS_IncorrectArgumentLength);
238 SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
240 vector<string> aColumn;
241 for (int i = 0; i < theData.length(); i++) aColumn.push_back(string(CORBA::string_dup(theData[i])));
242 aTable->SetColumnData(theColumn, aColumn);
245 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfString_i::GetColumn(CORBA::Long theColumn)
246 throw (SALOMEDS::AttributeTableOfString::IncorrectIndex)
248 SALOMEDS::Locker lock;
249 Unexpect aCatch(ATS_IncorrectIndex);
250 SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
251 if (theColumn <= 0 || theColumn > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
253 SALOMEDS::StringSeq_var CorbaSeq = new SALOMEDS::StringSeq;
254 vector<string> aColumn = aTable->GetColumnData(theColumn);
255 CorbaSeq->length(aColumn.size());
256 for (int i = 0; i < aColumn.size(); i++) {
257 CorbaSeq[i] = CORBA::string_dup(aColumn[i].c_str());
259 return CorbaSeq._retn();
262 void SALOMEDS_AttributeTableOfString_i::PutValue(const char* theValue, CORBA::Long theRow, CORBA::Long theColumn)
263 throw (SALOMEDS::AttributeTableOfString::IncorrectIndex)
265 SALOMEDS::Locker lock;
266 Unexpect aCatch(ATS_IncorrectIndex);
268 SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
269 char* aValue = CORBA::string_dup(theValue);
271 aTable->PutValue(aValue, theRow, theColumn);
274 CORBA::Boolean SALOMEDS_AttributeTableOfString_i::HasValue(CORBA::Long theRow, CORBA::Long theColumn)
276 SALOMEDS::Locker lock;
277 return dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl)->HasValue(theRow, theColumn);
280 char* SALOMEDS_AttributeTableOfString_i::GetValue(CORBA::Long theRow, CORBA::Long theColumn)
281 throw (SALOMEDS::AttributeTableOfString::IncorrectIndex)
283 SALOMEDS::Locker lock;
284 Unexpect aCatch(ATS_IncorrectIndex);
285 SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
286 if (theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
290 aValue = aTable->GetValue(theRow, theColumn);
293 throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
296 return CORBA::string_dup(aValue.c_str());
300 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfString_i::GetRowSetIndices(CORBA::Long theRow)
302 SALOMEDS::Locker lock;
303 SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
305 if(theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
307 SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
308 vector<int> aSeq = aTable->GetSetRowIndices(theRow);
309 CorbaSeq->length(aSeq.size());
310 for (int i = 0; i < aSeq.size(); i++) {
311 CorbaSeq[i] = aSeq[i];
313 return CorbaSeq._retn();
317 void SALOMEDS_AttributeTableOfString_i::SetNbColumns(CORBA::Long theNbColumns)
319 SALOMEDS::Locker lock;
320 SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
321 aTable->SetNbColumns(theNbColumns);
324 bool SALOMEDS_AttributeTableOfString_i::ReadFromFile(const SALOMEDS::TMPFile& theStream)
326 SALOMEDS::Locker lock;
327 SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
329 string aStream((char*)&theStream[0], theStream.length());
330 aTable->Load(aStream);
334 SALOMEDS::TMPFile* SALOMEDS_AttributeTableOfString_i::SaveToFile()
336 SALOMEDS::Locker lock;
337 SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
339 string aString = aTable->Save();
340 char* aBuffer = (char*)CORBA::string_dup(aString.c_str());
341 int aBufferSize = strlen((char*)aBuffer);
343 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
345 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1);
347 return aStreamFile._retn();