1 // File : SALOMEDS_AttributeTableOfString_i.cxx
2 // Author : Sergey RUIN
6 #include <TCollection_ExtendedString.hxx>
7 #include <TCollection_AsciiString.hxx>
9 #include "SALOMEDS_AttributeTableOfString_i.hxx"
10 #include "SALOMEDS.hxx"
12 #include <TColStd_HSequenceOfExtendedString.hxx>
13 #include <Standard_Failure.hxx>
14 #include <Standard_ErrorHandler.hxx>
19 #include "Utils_ExceptHandlers.hxx"
23 UNEXPECT_CATCH(ATS_IncorrectIndex, SALOMEDS::AttributeTableOfString::IncorrectIndex);
24 UNEXPECT_CATCH(ATS_IncorrectArgumentLength, SALOMEDS::AttributeTableOfString::IncorrectArgumentLength);
26 void SALOMEDS_AttributeTableOfString_i::SetTitle(const char* theTitle)
28 SALOMEDS::Locker lock;
30 Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
31 CORBA::String_var aStr = CORBA::string_dup(theTitle);
32 aTable->SetTitle(TCollection_ExtendedString(aStr));
35 char* SALOMEDS_AttributeTableOfString_i::GetTitle()
37 SALOMEDS::Locker lock;
38 Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
39 CORBA::String_var c_s = CORBA::string_dup(TCollection_AsciiString(aTable->GetTitle()).ToCString());
43 void SALOMEDS_AttributeTableOfString_i::SetRowTitle(CORBA::Long theIndex, const char* theTitle)
44 throw (SALOMEDS::AttributeTableOfString::IncorrectIndex)
46 SALOMEDS::Locker lock;
47 Unexpect aCatch(ATS_IncorrectIndex);
49 Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
50 if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
52 aTable->SetRowTitle(theIndex, TCollection_ExtendedString((char*)theTitle));
55 void SALOMEDS_AttributeTableOfString_i::SetRowTitles(const SALOMEDS::StringSeq& theTitles)
56 throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength)
58 SALOMEDS::Locker lock;
59 Unexpect aCatch(ATS_IncorrectArgumentLength);
61 Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
62 if (theTitles.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectArgumentLength();
63 for (int i = 0; i < theTitles.length(); i++) {
64 aTable->SetRowTitle(i + 1, TCollection_ExtendedString((char*)theTitles[i].in()));
68 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfString_i::GetRowTitles()
70 SALOMEDS::Locker lock;
71 Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
72 SALOMEDS::StringSeq_var aTitles = new SALOMEDS::StringSeq;
73 aTitles->length(aTable->GetNbRows());
74 for(int i = 0; i < aTitles->length(); i++)
75 aTitles[i] =CORBA::string_dup(TCollection_AsciiString(aTable->GetRowTitle(i + 1)).ToCString());
76 return aTitles._retn();
79 void SALOMEDS_AttributeTableOfString_i::SetColumnTitle(CORBA::Long theIndex, const char* theTitle)
80 throw (SALOMEDS::AttributeTableOfString::IncorrectIndex)
82 SALOMEDS::Locker lock;
83 Unexpect aCatch(ATS_IncorrectIndex);
85 Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
86 if (theIndex <= 0 || theIndex > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
87 aTable->SetColumnTitle(theIndex, TCollection_ExtendedString((char*)theTitle));
90 void SALOMEDS_AttributeTableOfString_i::SetColumnTitles(const SALOMEDS::StringSeq& theTitles)
91 throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength)
93 SALOMEDS::Locker lock;
94 Unexpect aCatch(ATS_IncorrectArgumentLength);
96 Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
97 if (theTitles.length() != aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfString::IncorrectArgumentLength();
98 for (int i = 0; i < theTitles.length(); i++) {
99 aTable->SetColumnTitle(i + 1, TCollection_ExtendedString((char*)theTitles[i].in()));
103 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfString_i::GetColumnTitles()
105 SALOMEDS::Locker lock;
106 Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
107 SALOMEDS::StringSeq_var aTitles = new SALOMEDS::StringSeq;
108 aTitles->length(aTable->GetNbColumns());
109 for(int i = 0; i < aTitles->length(); i++)
110 aTitles[i] = CORBA::string_dup(TCollection_AsciiString(aTable->GetColumnTitle(i + 1)).ToCString());
111 return aTitles._retn();
115 void SALOMEDS_AttributeTableOfString_i::SetRowUnit(CORBA::Long theIndex, const char* theUnit)
116 throw (SALOMEDS::AttributeTableOfString::IncorrectIndex)
118 SALOMEDS::Locker lock;
119 Unexpect aCatch(ATS_IncorrectIndex);
121 Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
122 if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
123 aTable->SetRowUnit(theIndex, TCollection_ExtendedString((char*)theUnit));
126 void SALOMEDS_AttributeTableOfString_i::SetRowUnits(const SALOMEDS::StringSeq& theUnits)
127 throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength)
129 SALOMEDS::Locker lock;
130 Unexpect aCatch(ATS_IncorrectArgumentLength);
132 Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
133 if (theUnits.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectArgumentLength();
134 for (int i = 0; i < theUnits.length(); i++) {
135 aTable->SetRowUnit(i + 1, TCollection_ExtendedString((char*)theUnits[i].in()));
139 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfString_i::GetRowUnits()
141 SALOMEDS::Locker lock;
142 Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
143 SALOMEDS::StringSeq_var aUnits = new SALOMEDS::StringSeq;
144 aUnits->length(aTable->GetNbRows());
145 for(int i = 0; i < aUnits->length(); i++)
146 aUnits[i] = CORBA::string_dup(TCollection_AsciiString(aTable->GetRowTitle(i + 1)).ToCString());
147 return aUnits._retn();
151 CORBA::Long SALOMEDS_AttributeTableOfString_i::GetNbRows()
153 SALOMEDS::Locker lock;
154 return Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl)->GetNbRows();
157 CORBA::Long SALOMEDS_AttributeTableOfString_i::GetNbColumns()
159 SALOMEDS::Locker lock;
160 return Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl)->GetNbColumns();
163 void SALOMEDS_AttributeTableOfString_i::AddRow(const SALOMEDS::StringSeq& theData)
164 throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength)
166 SALOMEDS::Locker lock;
167 Unexpect aCatch(ATS_IncorrectArgumentLength);
169 Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
171 Handle(TColStd_HSequenceOfExtendedString) aRow = new TColStd_HSequenceOfExtendedString;
172 for (int i = 0; i < theData.length(); i++) aRow->Append(TCollection_AsciiString(CORBA::string_dup(theData[i])));
173 aTable->SetRowData(aTable->GetNbRows() + 1, aRow);
176 void SALOMEDS_AttributeTableOfString_i::SetRow(CORBA::Long theRow, const SALOMEDS::StringSeq& theData)
177 throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength, SALOMEDS::AttributeTableOfString::IncorrectIndex)
179 SALOMEDS::Locker lock;
180 Unexpect aCatch(ATS_IncorrectArgumentLength);
182 Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
184 Handle(TColStd_HSequenceOfExtendedString) aRow = new TColStd_HSequenceOfExtendedString;
185 for (int i = 0; i < theData.length(); i++) aRow->Append(TCollection_AsciiString(CORBA::string_dup(theData[i])));
186 aTable->SetRowData(theRow, aRow);
189 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfString_i::GetRow(CORBA::Long theRow)
190 throw (SALOMEDS::AttributeTableOfString::IncorrectIndex)
192 SALOMEDS::Locker lock;
193 Unexpect aCatch(ATS_IncorrectIndex);
194 Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
195 if (theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
197 SALOMEDS::StringSeq_var CorbaSeq = new SALOMEDS::StringSeq;
198 Handle(TColStd_HSequenceOfExtendedString) aRow = aTable->GetRowData(theRow);
199 CorbaSeq->length(aRow->Length());
200 for (int i = 0; i < aRow->Length(); i++) {
201 CorbaSeq[i] = CORBA::string_dup((TCollection_AsciiString(aRow->Value(i + 1))).ToCString());
203 return CorbaSeq._retn();
206 void SALOMEDS_AttributeTableOfString_i::AddColumn(const SALOMEDS::StringSeq& theData)
207 throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength)
209 SALOMEDS::Locker lock;
210 Unexpect aCatch(ATS_IncorrectArgumentLength);
212 Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
214 Handle(TColStd_HSequenceOfExtendedString) aColumn = new TColStd_HSequenceOfExtendedString;
215 for (int i = 0; i < theData.length(); i++) aColumn->Append(TCollection_AsciiString(CORBA::string_dup(theData[i])));
216 aTable->SetColumnData(aTable->GetNbColumns() + 1, aColumn);
219 void SALOMEDS_AttributeTableOfString_i::SetColumn(CORBA::Long theColumn, const SALOMEDS::StringSeq& theData)
220 throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength, SALOMEDS::AttributeTableOfString::IncorrectIndex)
222 SALOMEDS::Locker lock;
223 Unexpect aCatch(ATS_IncorrectArgumentLength);
225 Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
227 Handle(TColStd_HSequenceOfExtendedString) aColumn = new TColStd_HSequenceOfExtendedString;
228 for (int i = 0; i < theData.length(); i++) aColumn->Append(TCollection_AsciiString(CORBA::string_dup(theData[i])));
229 aTable->SetColumnData(theColumn, aColumn);
232 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfString_i::GetColumn(CORBA::Long theColumn)
233 throw (SALOMEDS::AttributeTableOfString::IncorrectIndex)
235 SALOMEDS::Locker lock;
236 Unexpect aCatch(ATS_IncorrectIndex);
237 Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
238 if (theColumn <= 0 || theColumn > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
240 SALOMEDS::StringSeq_var CorbaSeq = new SALOMEDS::StringSeq;
241 Handle(TColStd_HSequenceOfExtendedString) aColumn = aTable->GetColumnData(theColumn);
242 CorbaSeq->length(aColumn->Length());
243 for (int i = 0; i < aColumn->Length(); i++) {
244 CorbaSeq[i] = CORBA::string_dup((TCollection_AsciiString(aColumn->Value(i + 1))).ToCString());
246 return CorbaSeq._retn();
249 void SALOMEDS_AttributeTableOfString_i::PutValue(const char* theValue, CORBA::Long theRow, CORBA::Long theColumn)
250 throw (SALOMEDS::AttributeTableOfString::IncorrectIndex)
252 SALOMEDS::Locker lock;
253 Unexpect aCatch(ATS_IncorrectIndex);
255 Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
256 char* aValue = CORBA::string_dup(theValue);
258 aTable->PutValue(aValue, theRow, theColumn);
261 CORBA::Boolean SALOMEDS_AttributeTableOfString_i::HasValue(CORBA::Long theRow, CORBA::Long theColumn)
263 SALOMEDS::Locker lock;
264 return Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl)->HasValue(theRow, theColumn);
267 char* SALOMEDS_AttributeTableOfString_i::GetValue(CORBA::Long theRow, CORBA::Long theColumn)
268 throw (SALOMEDS::AttributeTableOfString::IncorrectIndex)
270 SALOMEDS::Locker lock;
271 Unexpect aCatch(ATS_IncorrectIndex);
272 Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
273 if (theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
275 TCollection_AsciiString aValue;
278 aValue = aTable->GetValue(theRow, theColumn);
280 catch(Standard_Failure) {
281 throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
284 return CORBA::string_dup(aValue.ToCString());
288 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfString_i::GetRowSetIndices(CORBA::Long theRow)
290 SALOMEDS::Locker lock;
291 Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
293 if(theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
295 SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
296 Handle(TColStd_HSequenceOfInteger) aSeq = aTable->GetSetRowIndices(theRow);
297 CorbaSeq->length(aSeq->Length());
298 for (int i = 0; i < aSeq->Length(); i++) {
299 CorbaSeq[i] = aSeq->Value(i + 1);
301 return CorbaSeq._retn();
305 void SALOMEDS_AttributeTableOfString_i::SetNbColumns(CORBA::Long theNbColumns)
307 SALOMEDS::Locker lock;
308 Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
309 aTable->SetNbColumns(theNbColumns);
312 bool SALOMEDS_AttributeTableOfString_i::ReadFromFile(const SALOMEDS::TMPFile& theStream)
314 SALOMEDS::Locker lock;
315 Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
317 istrstream aStream((char*)&theStream[0], theStream.length());
318 return aTable->RestoreFromString(aStream);
321 SALOMEDS::TMPFile* SALOMEDS_AttributeTableOfString_i::SaveToFile()
323 SALOMEDS::Locker lock;
324 Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
327 aTable->ConvertToString(ostr);
328 CORBA::Octet* anOctetBuf = (CORBA::Octet*)ostr.rdbuf()->str();
329 unsigned long aSize = ostr.pcount();
330 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(aSize, aSize, anOctetBuf, 1);
331 return aStreamFile._retn();