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 <TCollection_ExtendedString.hxx>
26 #include <TCollection_AsciiString.hxx>
28 #include "SALOMEDS_AttributeTableOfString_i.hxx"
29 #include "SALOMEDS.hxx"
31 #include <TColStd_HSequenceOfExtendedString.hxx>
32 #include <Standard_Failure.hxx>
33 #include <Standard_ErrorHandler.hxx>
38 #include "Utils_ExceptHandlers.hxx"
42 UNEXPECT_CATCH(ATS_IncorrectIndex, SALOMEDS::AttributeTableOfString::IncorrectIndex);
43 UNEXPECT_CATCH(ATS_IncorrectArgumentLength, SALOMEDS::AttributeTableOfString::IncorrectArgumentLength);
45 void SALOMEDS_AttributeTableOfString_i::SetTitle(const char* theTitle)
47 SALOMEDS::Locker lock;
49 Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
50 CORBA::String_var aStr = CORBA::string_dup(theTitle);
51 aTable->SetTitle(TCollection_ExtendedString(aStr));
54 char* SALOMEDS_AttributeTableOfString_i::GetTitle()
56 SALOMEDS::Locker lock;
57 Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
58 CORBA::String_var c_s = CORBA::string_dup(TCollection_AsciiString(aTable->GetTitle()).ToCString());
62 void SALOMEDS_AttributeTableOfString_i::SetRowTitle(CORBA::Long theIndex, const char* theTitle)
63 throw (SALOMEDS::AttributeTableOfString::IncorrectIndex)
65 SALOMEDS::Locker lock;
66 Unexpect aCatch(ATS_IncorrectIndex);
68 Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
69 if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
71 aTable->SetRowTitle(theIndex, TCollection_ExtendedString((char*)theTitle));
74 void SALOMEDS_AttributeTableOfString_i::SetRowTitles(const SALOMEDS::StringSeq& theTitles)
75 throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength)
77 SALOMEDS::Locker lock;
78 Unexpect aCatch(ATS_IncorrectArgumentLength);
80 Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
81 if (theTitles.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectArgumentLength();
82 for (int i = 0; i < theTitles.length(); i++) {
83 aTable->SetRowTitle(i + 1, TCollection_ExtendedString((char*)theTitles[i].in()));
87 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfString_i::GetRowTitles()
89 SALOMEDS::Locker lock;
90 Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
91 SALOMEDS::StringSeq_var aTitles = new SALOMEDS::StringSeq;
92 aTitles->length(aTable->GetNbRows());
93 for(int i = 0; i < aTitles->length(); i++)
94 aTitles[i] =CORBA::string_dup(TCollection_AsciiString(aTable->GetRowTitle(i + 1)).ToCString());
95 return aTitles._retn();
98 void SALOMEDS_AttributeTableOfString_i::SetColumnTitle(CORBA::Long theIndex, const char* theTitle)
99 throw (SALOMEDS::AttributeTableOfString::IncorrectIndex)
101 SALOMEDS::Locker lock;
102 Unexpect aCatch(ATS_IncorrectIndex);
104 Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
105 if (theIndex <= 0 || theIndex > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
106 aTable->SetColumnTitle(theIndex, TCollection_ExtendedString((char*)theTitle));
109 void SALOMEDS_AttributeTableOfString_i::SetColumnTitles(const SALOMEDS::StringSeq& theTitles)
110 throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength)
112 SALOMEDS::Locker lock;
113 Unexpect aCatch(ATS_IncorrectArgumentLength);
115 Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
116 if (theTitles.length() != aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfString::IncorrectArgumentLength();
117 for (int i = 0; i < theTitles.length(); i++) {
118 aTable->SetColumnTitle(i + 1, TCollection_ExtendedString((char*)theTitles[i].in()));
122 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfString_i::GetColumnTitles()
124 SALOMEDS::Locker lock;
125 Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
126 SALOMEDS::StringSeq_var aTitles = new SALOMEDS::StringSeq;
127 aTitles->length(aTable->GetNbColumns());
128 for(int i = 0; i < aTitles->length(); i++)
129 aTitles[i] = CORBA::string_dup(TCollection_AsciiString(aTable->GetColumnTitle(i + 1)).ToCString());
130 return aTitles._retn();
134 void SALOMEDS_AttributeTableOfString_i::SetRowUnit(CORBA::Long theIndex, const char* theUnit)
135 throw (SALOMEDS::AttributeTableOfString::IncorrectIndex)
137 SALOMEDS::Locker lock;
138 Unexpect aCatch(ATS_IncorrectIndex);
140 Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
141 if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
142 aTable->SetRowUnit(theIndex, TCollection_ExtendedString((char*)theUnit));
145 void SALOMEDS_AttributeTableOfString_i::SetRowUnits(const SALOMEDS::StringSeq& theUnits)
146 throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength)
148 SALOMEDS::Locker lock;
149 Unexpect aCatch(ATS_IncorrectArgumentLength);
151 Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
152 if (theUnits.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectArgumentLength();
153 for (int i = 0; i < theUnits.length(); i++) {
154 aTable->SetRowUnit(i + 1, TCollection_ExtendedString((char*)theUnits[i].in()));
158 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfString_i::GetRowUnits()
160 SALOMEDS::Locker lock;
161 Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
162 SALOMEDS::StringSeq_var aUnits = new SALOMEDS::StringSeq;
163 aUnits->length(aTable->GetNbRows());
164 for(int i = 0; i < aUnits->length(); i++)
165 aUnits[i] = CORBA::string_dup(TCollection_AsciiString(aTable->GetRowUnit(i + 1)).ToCString());
166 return aUnits._retn();
170 CORBA::Long SALOMEDS_AttributeTableOfString_i::GetNbRows()
172 SALOMEDS::Locker lock;
173 return Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl)->GetNbRows();
176 CORBA::Long SALOMEDS_AttributeTableOfString_i::GetNbColumns()
178 SALOMEDS::Locker lock;
179 return Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl)->GetNbColumns();
182 void SALOMEDS_AttributeTableOfString_i::AddRow(const SALOMEDS::StringSeq& theData)
183 throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength)
185 SALOMEDS::Locker lock;
186 Unexpect aCatch(ATS_IncorrectArgumentLength);
188 Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
190 Handle(TColStd_HSequenceOfExtendedString) aRow = new TColStd_HSequenceOfExtendedString;
191 for (int i = 0; i < theData.length(); i++) aRow->Append(TCollection_AsciiString(CORBA::string_dup(theData[i])));
192 aTable->SetRowData(aTable->GetNbRows() + 1, aRow);
195 void SALOMEDS_AttributeTableOfString_i::SetRow(CORBA::Long theRow, const SALOMEDS::StringSeq& theData)
196 throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength, SALOMEDS::AttributeTableOfString::IncorrectIndex)
198 SALOMEDS::Locker lock;
199 Unexpect aCatch(ATS_IncorrectArgumentLength);
201 Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
203 Handle(TColStd_HSequenceOfExtendedString) aRow = new TColStd_HSequenceOfExtendedString;
204 for (int i = 0; i < theData.length(); i++) aRow->Append(TCollection_AsciiString(CORBA::string_dup(theData[i])));
205 aTable->SetRowData(theRow, aRow);
208 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfString_i::GetRow(CORBA::Long theRow)
209 throw (SALOMEDS::AttributeTableOfString::IncorrectIndex)
211 SALOMEDS::Locker lock;
212 Unexpect aCatch(ATS_IncorrectIndex);
213 Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
214 if (theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
216 SALOMEDS::StringSeq_var CorbaSeq = new SALOMEDS::StringSeq;
217 Handle(TColStd_HSequenceOfExtendedString) aRow = aTable->GetRowData(theRow);
218 CorbaSeq->length(aRow->Length());
219 for (int i = 0; i < aRow->Length(); i++) {
220 CorbaSeq[i] = CORBA::string_dup((TCollection_AsciiString(aRow->Value(i + 1))).ToCString());
222 return CorbaSeq._retn();
225 void SALOMEDS_AttributeTableOfString_i::AddColumn(const SALOMEDS::StringSeq& theData)
226 throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength)
228 SALOMEDS::Locker lock;
229 Unexpect aCatch(ATS_IncorrectArgumentLength);
231 Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
233 Handle(TColStd_HSequenceOfExtendedString) aColumn = new TColStd_HSequenceOfExtendedString;
234 for (int i = 0; i < theData.length(); i++) aColumn->Append(TCollection_AsciiString(CORBA::string_dup(theData[i])));
235 aTable->SetColumnData(aTable->GetNbColumns() + 1, aColumn);
238 void SALOMEDS_AttributeTableOfString_i::SetColumn(CORBA::Long theColumn, const SALOMEDS::StringSeq& theData)
239 throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength, SALOMEDS::AttributeTableOfString::IncorrectIndex)
241 SALOMEDS::Locker lock;
242 Unexpect aCatch(ATS_IncorrectArgumentLength);
244 Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
246 Handle(TColStd_HSequenceOfExtendedString) aColumn = new TColStd_HSequenceOfExtendedString;
247 for (int i = 0; i < theData.length(); i++) aColumn->Append(TCollection_AsciiString(CORBA::string_dup(theData[i])));
248 aTable->SetColumnData(theColumn, aColumn);
251 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfString_i::GetColumn(CORBA::Long theColumn)
252 throw (SALOMEDS::AttributeTableOfString::IncorrectIndex)
254 SALOMEDS::Locker lock;
255 Unexpect aCatch(ATS_IncorrectIndex);
256 Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
257 if (theColumn <= 0 || theColumn > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
259 SALOMEDS::StringSeq_var CorbaSeq = new SALOMEDS::StringSeq;
260 Handle(TColStd_HSequenceOfExtendedString) aColumn = aTable->GetColumnData(theColumn);
261 CorbaSeq->length(aColumn->Length());
262 for (int i = 0; i < aColumn->Length(); i++) {
263 CorbaSeq[i] = CORBA::string_dup((TCollection_AsciiString(aColumn->Value(i + 1))).ToCString());
265 return CorbaSeq._retn();
268 void SALOMEDS_AttributeTableOfString_i::PutValue(const char* theValue, CORBA::Long theRow, CORBA::Long theColumn)
269 throw (SALOMEDS::AttributeTableOfString::IncorrectIndex)
271 SALOMEDS::Locker lock;
272 Unexpect aCatch(ATS_IncorrectIndex);
274 Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
275 char* aValue = CORBA::string_dup(theValue);
277 aTable->PutValue(aValue, theRow, theColumn);
280 CORBA::Boolean SALOMEDS_AttributeTableOfString_i::HasValue(CORBA::Long theRow, CORBA::Long theColumn)
282 SALOMEDS::Locker lock;
283 return Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl)->HasValue(theRow, theColumn);
286 char* SALOMEDS_AttributeTableOfString_i::GetValue(CORBA::Long theRow, CORBA::Long theColumn)
287 throw (SALOMEDS::AttributeTableOfString::IncorrectIndex)
289 SALOMEDS::Locker lock;
290 Unexpect aCatch(ATS_IncorrectIndex);
291 Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
292 if (theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
294 TCollection_AsciiString aValue;
297 aValue = aTable->GetValue(theRow, theColumn);
299 catch(Standard_Failure) {
300 throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
303 return CORBA::string_dup(aValue.ToCString());
307 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfString_i::GetRowSetIndices(CORBA::Long theRow)
309 SALOMEDS::Locker lock;
310 Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
312 if(theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
314 SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
315 Handle(TColStd_HSequenceOfInteger) aSeq = aTable->GetSetRowIndices(theRow);
316 CorbaSeq->length(aSeq->Length());
317 for (int i = 0; i < aSeq->Length(); i++) {
318 CorbaSeq[i] = aSeq->Value(i + 1);
320 return CorbaSeq._retn();
324 void SALOMEDS_AttributeTableOfString_i::SetNbColumns(CORBA::Long theNbColumns)
326 SALOMEDS::Locker lock;
327 Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
328 aTable->SetNbColumns(theNbColumns);
331 bool SALOMEDS_AttributeTableOfString_i::ReadFromFile(const SALOMEDS::TMPFile& theStream)
333 SALOMEDS::Locker lock;
334 Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
336 istrstream aStream((char*)&theStream[0], theStream.length());
337 return aTable->RestoreFromString(aStream);
340 SALOMEDS::TMPFile* SALOMEDS_AttributeTableOfString_i::SaveToFile()
342 SALOMEDS::Locker lock;
343 Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
346 aTable->ConvertToString(ostr);
347 CORBA::Octet* anOctetBuf = (CORBA::Octet*)ostr.rdbuf()->str();
348 unsigned long aSize = ostr.pcount();
349 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(aSize, aSize, anOctetBuf, 1);
350 return aStreamFile._retn();