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/
20 // File : SALOMEDS_AttributeTableOfString.cxx
21 // Author : Sergey RUIN
24 #include "SALOMEDS_AttributeTableOfString.hxx"
27 #include <TCollection_AsciiString.hxx>
28 #include <TCollection_ExtendedString.hxx>
29 #include <TColStd_HSequenceOfInteger.hxx>
30 #include <TColStd_HSequenceOfReal.hxx>
31 #include <TColStd_HSequenceOfExtendedString.hxx>
33 SALOMEDS_AttributeTableOfString
34 ::SALOMEDS_AttributeTableOfString(const Handle(SALOMEDSImpl_AttributeTableOfString)& theAttr)
35 :SALOMEDS_GenericAttribute(theAttr)
38 SALOMEDS_AttributeTableOfString::SALOMEDS_AttributeTableOfString(SALOMEDS::AttributeTableOfString_ptr theAttr)
39 :SALOMEDS_GenericAttribute(theAttr)
42 SALOMEDS_AttributeTableOfString::~SALOMEDS_AttributeTableOfString()
46 void SALOMEDS_AttributeTableOfString::SetTitle(const std::string& theTitle)
49 if(_isLocal) Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_local_impl)->SetTitle((char*)theTitle.c_str());
50 else SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->SetTitle(theTitle.c_str());
53 std::string SALOMEDS_AttributeTableOfString::GetTitle()
57 aStr = TCollection_AsciiString(Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_local_impl)->GetTitle()).ToCString();
58 else aStr = SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->GetTitle();
62 void SALOMEDS_AttributeTableOfString::SetRowTitle(int theIndex, const std::string& theTitle)
65 if(_isLocal) Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_local_impl)->SetRowTitle(theIndex,
66 (char*)theTitle.c_str());
67 else SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->SetRowTitle(theIndex, theTitle.c_str());
70 void SALOMEDS_AttributeTableOfString::SetRowTitles(const std::vector<std::string>& theTitles)
73 int aLength = theTitles.size(), i;
75 Handle(TColStd_HSequenceOfExtendedString) aSeq = new TColStd_HSequenceOfExtendedString;
76 for(i = 0; i < aLength; i++) aSeq->Append((char*)theTitles[i].c_str());
77 Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_local_impl)->SetRowTitles(aSeq);
80 SALOMEDS::StringSeq_var aSeq = new SALOMEDS::StringSeq();
81 aSeq->length(aLength);
82 for(i = 0; i < aLength; i++) aSeq[i] = (char*)theTitles[i].c_str();
83 SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->SetRowTitles(aSeq);
88 std::vector<std::string> SALOMEDS_AttributeTableOfString::GetRowTitles()
90 std::vector<std::string> aVector;
93 Handle(TColStd_HSequenceOfExtendedString) aSeq;
94 aSeq = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_local_impl)->GetRowTitles();
95 aLength = aSeq->Length();
96 for(i = 1; i<= aLength; i++) aVector.push_back(TCollection_AsciiString(aSeq->Value(i)).ToCString());
99 SALOMEDS::StringSeq_var aSeq = SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->GetRowTitles();
100 aLength = aSeq->length();
101 for(i = 0; i<aLength; i++) aVector.push_back((char*)aSeq[i].in());
106 void SALOMEDS_AttributeTableOfString::SetColumnTitle(int theIndex, const std::string& theTitle)
109 if(_isLocal) Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_local_impl)->SetColumnTitle(theIndex,
110 (char*)theTitle.c_str());
111 else SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->SetColumnTitle(theIndex, theTitle.c_str());
114 void SALOMEDS_AttributeTableOfString::SetColumnTitles(const std::vector<std::string>& theTitles)
117 int aLength = theTitles.size(), i;
119 Handle(TColStd_HSequenceOfExtendedString) aSeq = new TColStd_HSequenceOfExtendedString;
120 for(i = 0; i < aLength; i++) aSeq->Append((char*)theTitles[i].c_str());
121 Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_local_impl)->SetColumnTitles(aSeq);
124 SALOMEDS::StringSeq_var aSeq = new SALOMEDS::StringSeq();
125 aSeq->length(aLength);
126 for(i = 0; i < aLength; i++) aSeq[i] = (char*)theTitles[i].c_str();
127 SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->SetColumnTitles(aSeq);
131 std::vector<std::string> SALOMEDS_AttributeTableOfString::GetColumnTitles()
133 std::vector<std::string> aVector;
136 Handle(TColStd_HSequenceOfExtendedString) aSeq;
137 aSeq = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_local_impl)->GetColumnTitles();
138 aLength = aSeq->Length();
139 for(i = 1; i<= aLength; i++) aVector.push_back(TCollection_AsciiString(aSeq->Value(i)).ToCString());
142 SALOMEDS::StringSeq_var aSeq = SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->GetColumnTitles();
143 aLength = aSeq->length();
144 for(i = 0; i<aLength; i++) aVector.push_back((char*)aSeq[i].in());
149 void SALOMEDS_AttributeTableOfString::SetRowUnit(int theIndex, const std::string& theUnit)
152 if(_isLocal) Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_local_impl)->SetRowUnit(theIndex,
153 (char*)theUnit.c_str());
154 else SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->SetRowUnit(theIndex, theUnit.c_str());
157 void SALOMEDS_AttributeTableOfString::SetRowUnits(const std::vector<std::string>& theUnits)
160 int aLength = theUnits.size(), i;
162 Handle(TColStd_HSequenceOfExtendedString) aSeq = new TColStd_HSequenceOfExtendedString;
163 for(i = 0; i < aLength; i++) aSeq->Append((char*)theUnits[i].c_str());
164 Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_local_impl)->SetRowUnits(aSeq);
167 SALOMEDS::StringSeq_var aSeq = new SALOMEDS::StringSeq();
168 aSeq->length(aLength);
169 for(i = 0; i < aLength; i++) aSeq[i] = (char*)theUnits[i].c_str();
170 SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->SetRowUnits(aSeq);
174 std::vector<std::string> SALOMEDS_AttributeTableOfString::GetRowUnits()
176 std::vector<std::string> aVector;
179 Handle(TColStd_HSequenceOfExtendedString) aSeq;
180 aSeq = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_local_impl)->GetRowUnits();
181 aLength = aSeq->Length();
182 for(i = 1; i<= aLength; i++) aVector.push_back(TCollection_AsciiString(aSeq->Value(i)).ToCString());
185 SALOMEDS::StringSeq_var aSeq = SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->GetRowUnits();
186 aLength = aSeq->length();
187 for(i = 0; i<aLength; i++) aVector.push_back((char*)aSeq[i].in());
192 int SALOMEDS_AttributeTableOfString::GetNbRows()
195 if(_isLocal) aNb = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_local_impl)->GetNbRows();
196 else aNb = SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->GetNbRows();
200 int SALOMEDS_AttributeTableOfString::GetNbColumns()
203 if(_isLocal) aNb = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_local_impl)->GetNbColumns();
204 else aNb = SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->GetNbColumns();
209 void SALOMEDS_AttributeTableOfString::AddRow(const std::vector<std::string>& theData)
212 int aLength = theData.size(), i;
214 Handle(SALOMEDSImpl_AttributeTableOfString) aTable;
215 aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_local_impl);
216 Handle(TColStd_HSequenceOfExtendedString) aRow = new TColStd_HSequenceOfExtendedString;
217 for (int i = 0; i < aLength; i++) aRow->Append((char*)theData[i].c_str());
219 aTable->SetRowData(aTable->GetNbRows() + 1, aRow);
222 throw SALOMEDS::AttributeTableOfString::IncorrectArgumentLength();
226 SALOMEDS::StringSeq_var aSeq = new SALOMEDS::StringSeq();
227 aSeq->length(aLength);
228 for(i = 0; i < aLength; i++) aSeq[i] = (char*)theData[i].c_str();
229 SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->AddRow(aSeq);
233 void SALOMEDS_AttributeTableOfString::SetRow(int theRow, const std::vector<std::string>& theData)
236 int aLength = theData.size(), i;
238 Handle(SALOMEDSImpl_AttributeTableOfString) aTable;
239 aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_local_impl);
240 Handle(TColStd_HSequenceOfExtendedString) aRow = new TColStd_HSequenceOfExtendedString;
241 for (int i = 0; i < aLength; i++) aRow->Append((char*)theData[i].c_str());
243 aTable->SetRowData(theRow, aRow);
246 throw SALOMEDS::AttributeTableOfString::IncorrectArgumentLength();
250 SALOMEDS::StringSeq_var aSeq = new SALOMEDS::StringSeq();
251 aSeq->length(aLength);
252 for(i = 0; i < aLength; i++) aSeq[i] = (char*)theData[i].c_str();
253 SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->SetRow(theRow, aSeq);
257 std::vector<std::string> SALOMEDS_AttributeTableOfString::GetRow(int theRow)
259 std::vector<std::string> aVector;
262 Handle(TColStd_HSequenceOfExtendedString) aRow;
263 aRow = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_local_impl)->GetRowData(theRow);
264 aLength = aRow->Length();
265 for(i = 1; i<= aLength; i++) aVector.push_back(TCollection_AsciiString(aRow->Value(i)).ToCString());
268 SALOMEDS::StringSeq_var aRow = SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->GetRow(theRow);
269 for(i = 0; i < aLength; i++) aVector.push_back((char*)aRow[i].in());
275 void SALOMEDS_AttributeTableOfString::AddColumn(const std::vector<std::string>& theData)
278 int aLength = theData.size(), i;
280 Handle(SALOMEDSImpl_AttributeTableOfString) aTable;
281 aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_local_impl);
282 Handle(TColStd_HSequenceOfExtendedString) aColumn = new TColStd_HSequenceOfExtendedString;
283 for (int i = 0; i < aLength; i++) aColumn->Append((char*)theData[i].c_str());
285 aTable->SetColumnData(aTable->GetNbColumns() + 1, aColumn);
288 throw SALOMEDS::AttributeTableOfString::IncorrectArgumentLength();
292 SALOMEDS::StringSeq_var aColumn = new SALOMEDS::StringSeq();
293 aColumn->length(aLength);
294 for(i = 0; i < aLength; i++) aColumn[i] = (char*)theData[i].c_str();
295 SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->AddColumn(aColumn);
299 void SALOMEDS_AttributeTableOfString::SetColumn(int theColumn, const std::vector<std::string>& theData)
302 int aLength = theData.size(), i;
304 Handle(SALOMEDSImpl_AttributeTableOfString) aTable;
305 aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_local_impl);
306 Handle(TColStd_HSequenceOfExtendedString) aColumn = new TColStd_HSequenceOfExtendedString;
307 for (int i = 0; i < aLength; i++) aColumn->Append((char*)theData[i].c_str());
309 aTable->SetRowData(theColumn, aColumn);
312 throw SALOMEDS::AttributeTableOfString::IncorrectArgumentLength();
316 SALOMEDS::StringSeq_var aColumn = new SALOMEDS::StringSeq();
317 aColumn->length(aLength);
318 for(i = 0; i < aLength; i++) aColumn[i] = (char*)theData[i].c_str();
319 SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->SetRow(theColumn, aColumn);
323 std::vector<std::string> SALOMEDS_AttributeTableOfString::GetColumn(int theColumn)
325 std::vector<std::string> aVector;
328 Handle(TColStd_HSequenceOfExtendedString) aColumn;
329 aColumn = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_local_impl)->GetColumnData(theColumn);
330 aLength = aColumn->Length();
331 for(i = 1; i<= aLength; i++) aVector.push_back(TCollection_AsciiString(aColumn->Value(i)).ToCString());
334 SALOMEDS::StringSeq_var aColumn = SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->GetColumn(theColumn);
335 for(i = 0; i < aLength; i++) aVector.push_back(aColumn[i].in());
340 void SALOMEDS_AttributeTableOfString::PutValue(const std::string& theValue, int theRow, int theColumn)
345 Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_local_impl)->PutValue((char*)theValue.c_str(),
350 throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
354 SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->PutValue(theValue.c_str(), theRow, theColumn);
358 bool SALOMEDS_AttributeTableOfString::HasValue(int theRow, int theColumn)
361 if(_isLocal) ret = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_local_impl)->HasValue(theRow, theColumn);
362 else ret = SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->HasValue(theRow, theColumn);
366 std::string SALOMEDS_AttributeTableOfString::GetValue(int theRow, int theColumn)
372 TCollection_AsciiString(Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_local_impl)->GetValue(theRow,
373 theColumn)).ToCString();
376 throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
380 aValue = SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->GetValue(theRow, theColumn);
385 std::vector<int> SALOMEDS_AttributeTableOfString::GetRowSetIndices(int theRow)
387 std::vector<int> aVector;
390 Handle(TColStd_HSequenceOfInteger) aSet;
391 aSet = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_local_impl)->GetSetRowIndices(theRow);
392 aLength = aSet->Length();
393 for(i = 1; i<= aLength; i++) aVector.push_back(aSet->Value(i));
396 SALOMEDS::LongSeq_var aSet = SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->GetRowSetIndices(theRow);
397 for(i = 0; i < aLength; i++) aVector.push_back(aSet[i]);
402 void SALOMEDS_AttributeTableOfString::SetNbColumns(int theNbColumns)
404 if(_isLocal) Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_local_impl)->SetNbColumns(theNbColumns);
405 else SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->SetNbColumns(theNbColumns);