1 // File : SALOMEDS_AttributeTableOfReal_i.cxx
2 // Author : Sergey RUIN
6 #include "SALOMEDS_AttributeTableOfReal_i.hxx"
7 #include "SALOMEDS.hxx"
9 #include <TColStd_HSequenceOfReal.hxx>
10 #include <Standard_Failure.hxx>
11 #include <Standard_ErrorHandler.hxx>
18 #include "Utils_ExceptHandlers.hxx"
19 UNEXPECT_CATCH(ATR_IncorrectIndex, SALOMEDS::AttributeTableOfReal::IncorrectIndex);
20 UNEXPECT_CATCH(ATR_IncorrectArgumentLength, SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength);
22 void SALOMEDS_AttributeTableOfReal_i::SetTitle(const char* theTitle)
24 SALOMEDS::Locker lock;
26 Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
27 CORBA::String_var aStr = CORBA::string_dup(theTitle);
28 aTable->SetTitle(TCollection_ExtendedString(aStr));
31 char* SALOMEDS_AttributeTableOfReal_i::GetTitle()
33 SALOMEDS::Locker lock;
34 Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
35 CORBA::String_var c_s = CORBA::string_dup(TCollection_AsciiString(aTable->GetTitle()).ToCString());
39 void SALOMEDS_AttributeTableOfReal_i::SetRowTitle(CORBA::Long theIndex, const char* theTitle)
40 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
42 SALOMEDS::Locker lock;
43 Unexpect aCatch (ATR_IncorrectIndex);
45 Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
46 if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
47 aTable->SetRowTitle(theIndex, TCollection_ExtendedString((char*)theTitle));
50 void SALOMEDS_AttributeTableOfReal_i::SetRowTitles(const SALOMEDS::StringSeq& theTitles)
51 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
53 SALOMEDS::Locker lock;
54 Unexpect aCatch (ATR_IncorrectArgumentLength);
56 Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
57 if (theTitles.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength();
58 for (int i = 0; i < theTitles.length(); i++) {
59 aTable->SetRowTitle(i + 1, (char*)theTitles[i].in());
63 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfReal_i::GetRowTitles()
65 SALOMEDS::Locker lock;
66 Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
67 SALOMEDS::StringSeq_var aTitles = new SALOMEDS::StringSeq;
68 aTitles->length(aTable->GetNbRows());
69 for(int i = 0; i < aTitles->length(); i++)
70 aTitles[i] = CORBA::string_dup(TCollection_AsciiString(aTable->GetRowTitle(i + 1)).ToCString());
71 return aTitles._retn();
74 void SALOMEDS_AttributeTableOfReal_i::SetColumnTitle(CORBA::Long theIndex, const char* theTitle)
75 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
77 SALOMEDS::Locker lock;
78 Unexpect aCatch (ATR_IncorrectIndex);
80 Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
81 if (theIndex <= 0 || theIndex > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
82 CORBA::String_var aStr = CORBA::string_dup(theTitle);
83 aTable->SetColumnTitle(theIndex, TCollection_ExtendedString(aStr));
86 void SALOMEDS_AttributeTableOfReal_i::SetColumnTitles(const SALOMEDS::StringSeq& theTitles)
87 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
89 SALOMEDS::Locker lock;
90 Unexpect aCatch(ATR_IncorrectArgumentLength);
92 Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
93 if (theTitles.length() != aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength();
94 for (int i = 0; i < theTitles.length(); i++) {
95 aTable->SetColumnTitle(i + 1, (char*)theTitles[i].in());
99 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfReal_i::GetColumnTitles()
101 SALOMEDS::Locker lock;
102 Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
103 SALOMEDS::StringSeq_var aTitles = new SALOMEDS::StringSeq;
104 aTitles->length(aTable->GetNbColumns());
105 for(int i = 0; i < aTitles->length(); i++)
106 aTitles[i] = CORBA::string_dup(TCollection_AsciiString(aTable->GetColumnTitle(i + 1)).ToCString());
107 return aTitles._retn();
111 void SALOMEDS_AttributeTableOfReal_i::SetRowUnit(CORBA::Long theIndex, const char* theUnit)
112 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
114 SALOMEDS::Locker lock;
115 Unexpect aCatch (ATR_IncorrectIndex);
117 Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
118 if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
119 aTable->SetRowUnit(theIndex, TCollection_ExtendedString((char*)theUnit));
122 void SALOMEDS_AttributeTableOfReal_i::SetRowUnits(const SALOMEDS::StringSeq& theUnits)
123 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
125 SALOMEDS::Locker lock;
126 Unexpect aCatch (ATR_IncorrectArgumentLength);
128 Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
129 if (theUnits.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength();
130 for (int i = 0; i < theUnits.length(); i++) {
131 aTable->SetRowUnit(i + 1, (char*)theUnits[i].in());
135 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfReal_i::GetRowUnits()
137 SALOMEDS::Locker lock;
138 Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
139 SALOMEDS::StringSeq_var aUnits = new SALOMEDS::StringSeq;
140 aUnits->length(aTable->GetNbRows());
141 for(int i = 0; i < aUnits->length(); i++)
142 aUnits[i] = CORBA::string_dup(TCollection_AsciiString(aTable->GetRowUnit(i + 1)).ToCString());
143 return aUnits._retn();
147 CORBA::Long SALOMEDS_AttributeTableOfReal_i::GetNbRows()
149 SALOMEDS::Locker lock;
150 return Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl)->GetNbRows();
153 CORBA::Long SALOMEDS_AttributeTableOfReal_i::GetNbColumns()
155 SALOMEDS::Locker lock;
156 return Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl)->GetNbColumns();
159 void SALOMEDS_AttributeTableOfReal_i::AddRow(const SALOMEDS::DoubleSeq& theData)
160 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
162 SALOMEDS::Locker lock;
163 Unexpect aCatch(ATR_IncorrectArgumentLength);
165 Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
167 Handle(TColStd_HSequenceOfReal) aRow = new TColStd_HSequenceOfReal;
168 for (int i = 0; i < theData.length(); i++) aRow->Append(theData[i]);
169 aTable->SetRowData(aTable->GetNbRows() + 1, aRow);
172 void SALOMEDS_AttributeTableOfReal_i::SetRow(CORBA::Long theRow, const SALOMEDS::DoubleSeq& theData)
173 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength, SALOMEDS::AttributeTableOfReal::IncorrectIndex)
175 SALOMEDS::Locker lock;
176 Unexpect aCatch(ATR_IncorrectArgumentLength);
178 Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
180 Handle(TColStd_HSequenceOfReal) aRow = new TColStd_HSequenceOfReal;
181 for (int i = 0; i < theData.length(); i++) aRow->Append(theData[i]);
182 aTable->SetRowData(theRow, aRow);
185 SALOMEDS::DoubleSeq* SALOMEDS_AttributeTableOfReal_i::GetRow(CORBA::Long theRow)
186 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
188 SALOMEDS::Locker lock;
189 Unexpect aCatch(ATR_IncorrectIndex);
190 Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
191 if (theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
193 SALOMEDS::DoubleSeq_var CorbaSeq = new SALOMEDS::DoubleSeq;
194 Handle(TColStd_HSequenceOfReal) aRow = aTable->GetRowData(theRow);
195 CorbaSeq->length(aRow->Length());
196 for (int i = 0; i < aRow->Length(); i++) {
197 CorbaSeq[i] = aRow->Value(i + 1);
199 return CorbaSeq._retn();
202 void SALOMEDS_AttributeTableOfReal_i::AddColumn(const SALOMEDS::DoubleSeq& theData)
203 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
205 SALOMEDS::Locker lock;
206 Unexpect aCatch(ATR_IncorrectArgumentLength);
208 Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
210 Handle(TColStd_HSequenceOfReal) aColumn = new TColStd_HSequenceOfReal;
211 for (int i = 0; i < theData.length(); i++) aColumn->Append(theData[i]);
212 aTable->SetColumnData(aTable->GetNbColumns() + 1, aColumn);
215 void SALOMEDS_AttributeTableOfReal_i::SetColumn(CORBA::Long theColumn, const SALOMEDS::DoubleSeq& theData)
216 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength, SALOMEDS::AttributeTableOfReal::IncorrectIndex)
218 SALOMEDS::Locker lock;
219 Unexpect aCatch(ATR_IncorrectArgumentLength);
221 Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
223 Handle(TColStd_HSequenceOfReal) aColumn = new TColStd_HSequenceOfReal;
224 for (int i = 0; i < theData.length(); i++) aColumn->Append(theData[i]);
225 aTable->SetColumnData(theColumn, aColumn);
228 SALOMEDS::DoubleSeq* SALOMEDS_AttributeTableOfReal_i::GetColumn(CORBA::Long theColumn)
229 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
231 SALOMEDS::Locker lock;
232 Unexpect aCatch(ATR_IncorrectIndex);
233 Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
234 if (theColumn <= 0 || theColumn > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
236 SALOMEDS::DoubleSeq_var CorbaSeq = new SALOMEDS::DoubleSeq;
237 Handle(TColStd_HSequenceOfReal) aColumn = aTable->GetColumnData(theColumn);
238 CorbaSeq->length(aColumn->Length());
239 for (int i = 0; i < aColumn->Length(); i++) {
240 CorbaSeq[i] = aColumn->Value(i + 1);
242 return CorbaSeq._retn();
245 void SALOMEDS_AttributeTableOfReal_i::PutValue(CORBA::Double theValue, CORBA::Long theRow, CORBA::Long theColumn)
246 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
248 SALOMEDS::Locker lock;
249 Unexpect aCatch(ATR_IncorrectIndex);
251 Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
253 aTable->PutValue(theValue, theRow, theColumn);
256 CORBA::Boolean SALOMEDS_AttributeTableOfReal_i::HasValue(CORBA::Long theRow, CORBA::Long theColumn)
258 SALOMEDS::Locker lock;
259 return Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl)->HasValue(theRow, theColumn);
262 CORBA::Double SALOMEDS_AttributeTableOfReal_i::GetValue(CORBA::Long theRow, CORBA::Long theColumn)
263 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
265 SALOMEDS::Locker lock;
266 Unexpect aCatch(ATR_IncorrectIndex);
267 Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
268 if (theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
270 CORBA::Double aValue;
273 aValue = aTable->GetValue(theRow, theColumn);
275 catch(Standard_Failure) {
276 throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
283 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfReal_i::GetRowSetIndices(CORBA::Long theRow)
285 SALOMEDS::Locker lock;
286 Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
288 if(theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
290 SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
291 Handle(TColStd_HSequenceOfInteger) aSeq = aTable->GetSetRowIndices(theRow);
292 CorbaSeq->length(aSeq->Length());
293 for (int i = 0; i < aSeq->Length(); i++) {
294 CorbaSeq[i] = aSeq->Value(i + 1);
296 return CorbaSeq._retn();
300 void SALOMEDS_AttributeTableOfReal_i::SetNbColumns(CORBA::Long theNbColumns)
302 SALOMEDS::Locker lock;
303 Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
304 aTable->SetNbColumns(theNbColumns);
307 bool SALOMEDS_AttributeTableOfReal_i::ReadFromFile(const SALOMEDS::TMPFile& theStream)
309 SALOMEDS::Locker lock;
310 Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
312 istrstream aStream((char*)&theStream[0], theStream.length());
313 return aTable->RestoreFromString(aStream);
316 SALOMEDS::TMPFile* SALOMEDS_AttributeTableOfReal_i::SaveToFile()
318 SALOMEDS::Locker lock;
319 Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
323 aTable->ConvertToString(ostr);
325 aString = ostr.rdbuf()->str();
327 char* aBuffer = (char*)CORBA::string_dup(aString.c_str());
328 int aBufferSize = strlen((char*)aBuffer);
330 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
332 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1);
334 return aStreamFile._retn();