1 // SALOME SALOMEDS : data structure of SALOME and sources of Salome data server
3 // Copyright (C) 2003 CEA/DEN, EDF R&D
7 // File : SALOMEDS_AttributeTableOfInteger_i.cxx
8 // Author : Michael Ponikarov
12 #include <TColStd_HSequenceOfInteger.hxx>
13 #include <TCollection_AsciiString.hxx>
14 #include <Standard_Failure.hxx>
15 #include <Standard_ErrorHandler.hxx>
17 #include "SALOMEDS_AttributeTableOfInteger_i.hxx"
18 #include "SALOMEDS.hxx"
19 #include "Utils_ExceptHandlers.hxx"
27 #define SEPARATOR '\1'
29 UNEXPECT_CATCH(ATI_IncorrectIndex, SALOMEDS::AttributeTableOfInteger::IncorrectIndex);
30 UNEXPECT_CATCH(ATI_IncorrectArgumentLength, SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength);
32 static TCollection_ExtendedString getUnit(TCollection_ExtendedString theString)
34 TCollection_ExtendedString aString(theString);
35 int aPos = aString.Search(SEPARATOR);
36 if(aPos <= 0 || aPos == aString.Length() ) return TCollection_ExtendedString();
37 return aString.Split(aPos);
40 static TCollection_ExtendedString getTitle(TCollection_ExtendedString theString)
42 TCollection_ExtendedString aString(theString);
43 int aPos = aString.Search(SEPARATOR);
44 if(aPos < 1) return aString;
45 if(aPos == 1) return TCollection_ExtendedString();
46 aString.Split(aPos-1);
50 void SALOMEDS_AttributeTableOfInteger_i::SetTitle(const char* theTitle) {
51 SALOMEDS::Locker lock;
54 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
55 CORBA::String_var aStr = CORBA::string_dup(theTitle);
56 aTable->SetTitle(TCollection_ExtendedString(aStr));
59 char* SALOMEDS_AttributeTableOfInteger_i::GetTitle() {
60 SALOMEDS::Locker lock;
62 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
63 CORBA::String_var c_s = CORBA::string_dup(TCollection_AsciiString(aTable->GetTitle()).ToCString());
67 void SALOMEDS_AttributeTableOfInteger_i::SetRowTitle(CORBA::Long theIndex, const char* theTitle)
68 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
70 SALOMEDS::Locker lock;
72 Unexpect aCatch (ATI_IncorrectIndex);
74 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
75 if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
76 CORBA::String_var aStr = CORBA::string_dup(theTitle);
77 TCollection_ExtendedString aTitle(aStr);
78 TCollection_ExtendedString aUnit = getUnit(aTable->GetRowTitle(theIndex));
79 if(aUnit.Length() > 0) {
84 aTable->SetRowTitle(theIndex, aTitle);
87 void SALOMEDS_AttributeTableOfInteger_i::SetRowTitles(const SALOMEDS::StringSeq& theTitles)
88 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
90 SALOMEDS::Locker lock;
92 Unexpect aCatch (ATI_IncorrectArgumentLength);
94 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
95 if (theTitles.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
96 for (int i = 0; i < theTitles.length(); i++) {
97 SetRowTitle(i + 1, theTitles[i]);
101 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfInteger_i::GetRowTitles() {
102 SALOMEDS::Locker lock;
104 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
105 SALOMEDS::StringSeq_var aTitles = new SALOMEDS::StringSeq;
106 aTitles->length(aTable->GetNbRows());
107 for(int i = 0; i < aTitles->length(); i++)
108 aTitles[i] = CORBA::string_dup(TCollection_AsciiString(getTitle(aTable->GetRowTitle(i + 1))).ToCString());
109 return aTitles._retn();
112 void SALOMEDS_AttributeTableOfInteger_i::SetColumnTitle(CORBA::Long theIndex, const char* theTitle)
113 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
115 SALOMEDS::Locker lock;
117 Unexpect aCatch (ATI_IncorrectIndex);
119 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
120 if (theIndex <= 0 || theIndex > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
121 CORBA::String_var aStr = CORBA::string_dup(theTitle);
122 aTable->SetColumnTitle(theIndex, TCollection_ExtendedString(aStr));
125 void SALOMEDS_AttributeTableOfInteger_i::SetColumnTitles(const SALOMEDS::StringSeq& theTitles)
126 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
128 SALOMEDS::Locker lock;
130 Unexpect aCatch(ATI_IncorrectArgumentLength);
132 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
133 if (theTitles.length() != aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
134 for (int i = 0; i < theTitles.length(); i++) {
135 SetColumnTitle(i + 1, theTitles[i]);
139 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfInteger_i::GetColumnTitles() {
140 SALOMEDS::Locker lock;
142 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
143 SALOMEDS::StringSeq_var aTitles = new SALOMEDS::StringSeq;
144 aTitles->length(aTable->GetNbColumns());
145 for(int i = 0; i < aTitles->length(); i++)
146 aTitles[i] = CORBA::string_dup(TCollection_AsciiString(aTable->GetColumnTitle(i + 1)).ToCString());
147 return aTitles._retn();
151 void SALOMEDS_AttributeTableOfInteger_i::SetRowUnit(CORBA::Long theIndex, const char* theUnit)
152 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
154 SALOMEDS::Locker lock;
156 Unexpect aCatch (ATI_IncorrectIndex);
158 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
159 if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
160 CORBA::String_var aStr = CORBA::string_dup(theUnit);
161 TCollection_ExtendedString aTitle = getTitle(aTable->GetRowTitle(theIndex));
162 TCollection_ExtendedString aUnit(aStr);
165 aTable->SetRowTitle(theIndex, aTitle);
168 void SALOMEDS_AttributeTableOfInteger_i::SetRowUnits(const SALOMEDS::StringSeq& theUnits)
169 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
171 SALOMEDS::Locker lock;
173 Unexpect aCatch (ATI_IncorrectArgumentLength);
175 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
176 if (theUnits.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
177 for (int i = 0; i < theUnits.length(); i++) {
178 SetRowUnit(i + 1, theUnits[i]);
182 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfInteger_i::GetRowUnits() {
183 SALOMEDS::Locker lock;
185 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
186 SALOMEDS::StringSeq_var aUnits = new SALOMEDS::StringSeq;
187 aUnits->length(aTable->GetNbRows());
188 for(int i = 0; i < aUnits->length(); i++)
189 aUnits[i] = CORBA::string_dup(TCollection_AsciiString(getUnit(aTable->GetRowTitle(i + 1))).ToCString());
190 return aUnits._retn();
193 CORBA::Long SALOMEDS_AttributeTableOfInteger_i::GetNbRows() {
194 SALOMEDS::Locker lock;
196 return Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr)->GetNbRows();
198 CORBA::Long SALOMEDS_AttributeTableOfInteger_i::GetNbColumns() {
199 SALOMEDS::Locker lock;
201 return Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr)->GetNbColumns();
204 void SALOMEDS_AttributeTableOfInteger_i::AddRow(const SALOMEDS::LongSeq& theData)
205 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
207 SALOMEDS::Locker lock;
209 Unexpect aCatch(ATI_IncorrectArgumentLength);
211 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
213 Handle(TColStd_HSequenceOfInteger) aRow = new TColStd_HSequenceOfInteger;
214 for (int i = 0; i < theData.length(); i++) aRow->Append(theData[i]);
216 aTable->SetRowData(aTable->GetNbRows() + 1, aRow);
218 catch(Standard_Failure) {
219 throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
223 void SALOMEDS_AttributeTableOfInteger_i::SetRow(CORBA::Long theRow, const SALOMEDS::LongSeq& theData)
224 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength, SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
226 SALOMEDS::Locker lock;
228 Unexpect aCatch(ATI_IncorrectArgumentLength);
230 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
232 Handle(TColStd_HSequenceOfInteger) aRow = new TColStd_HSequenceOfInteger;
233 for (int i = 0; i < theData.length(); i++) aRow->Append(theData[i]);
235 aTable->SetRowData(theRow, aRow);
237 catch(Standard_Failure) {
238 throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
242 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfInteger_i::GetRow(CORBA::Long theRow)
243 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
245 SALOMEDS::Locker lock;
247 Unexpect aCatch(ATI_IncorrectIndex);
248 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
249 if (theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
251 SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
252 Handle(TColStd_HSequenceOfInteger) aRow = aTable->GetRowData(theRow);
253 CorbaSeq->length(aRow->Length());
254 for (int i = 0; i < aRow->Length(); i++) {
255 CorbaSeq[i] = aRow->Value(i + 1);
257 return CorbaSeq._retn();
260 void SALOMEDS_AttributeTableOfInteger_i::AddColumn(const SALOMEDS::LongSeq& theData)
261 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
263 SALOMEDS::Locker lock;
265 Unexpect aCatch(ATI_IncorrectArgumentLength);
267 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
269 Handle(TColStd_HSequenceOfInteger) aColumn = new TColStd_HSequenceOfInteger;
270 for (int i = 0; i < theData.length(); i++) aColumn->Append(theData[i]);
272 aTable->SetColumnData(aTable->GetNbColumns() + 1, aColumn);
274 catch(Standard_Failure) {
275 throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
279 void SALOMEDS_AttributeTableOfInteger_i::SetColumn(CORBA::Long theColumn, const SALOMEDS::LongSeq& theData)
280 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength, SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
282 SALOMEDS::Locker lock;
284 Unexpect aCatch(ATI_IncorrectArgumentLength);
286 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
288 Handle(TColStd_HSequenceOfInteger) aColumn = new TColStd_HSequenceOfInteger;
289 for (int i = 0; i < theData.length(); i++) aColumn->Append(theData[i]);
291 aTable->SetColumnData(theColumn, aColumn);
293 catch(Standard_Failure) {
294 throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
298 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfInteger_i::GetColumn(CORBA::Long theColumn)
299 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
301 SALOMEDS::Locker lock;
303 Unexpect aCatch(ATI_IncorrectIndex);
304 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
305 if (theColumn <= 0 || theColumn > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
307 SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
308 Handle(TColStd_HSequenceOfInteger) aColumn = aTable->GetColumnData(theColumn);
309 CorbaSeq->length(aColumn->Length());
310 for (int i = 0; i < aColumn->Length(); i++) {
311 CorbaSeq[i] = aColumn->Value(i + 1);
313 return CorbaSeq._retn();
316 void SALOMEDS_AttributeTableOfInteger_i::PutValue(CORBA::Long theValue, CORBA::Long theRow, CORBA::Long theColumn)
317 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
319 SALOMEDS::Locker lock;
321 Unexpect aCatch(ATI_IncorrectIndex);
323 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
326 aTable->PutValue(theValue, theRow, theColumn);
328 catch(Standard_Failure) {
329 throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
333 CORBA::Boolean SALOMEDS_AttributeTableOfInteger_i::HasValue(CORBA::Long theRow, CORBA::Long theColumn) {
334 SALOMEDS::Locker lock;
336 return Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr)->HasValue(theRow, theColumn);
339 CORBA::Long SALOMEDS_AttributeTableOfInteger_i::GetValue(CORBA::Long theRow, CORBA::Long theColumn)
340 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
342 SALOMEDS::Locker lock;
344 Unexpect aCatch(ATI_IncorrectIndex);
345 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
346 if (theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
350 aValue = aTable->GetValue(theRow, theColumn);
352 catch(Standard_Failure) {
353 throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
358 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfInteger_i::GetRowSetIndices(CORBA::Long theRow)
360 SALOMEDS::Locker lock;
362 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
364 if(theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
366 SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
367 Handle(TColStd_HSequenceOfInteger) aSeq = aTable->GetSetRowIndices(theRow);
368 CorbaSeq->length(aSeq->Length());
369 for (int i = 0; i < aSeq->Length(); i++) {
370 CorbaSeq[i] = aSeq->Value(i + 1);
372 return CorbaSeq._retn();
376 void SALOMEDS_AttributeTableOfInteger_i::SetNbColumns(CORBA::Long theNbColumns)
378 SALOMEDS::Locker lock;
380 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
381 aTable->SetNbColumns(theNbColumns);
384 bool SALOMEDS_AttributeTableOfInteger_i::ReadFromFile(const SALOMEDS::TMPFile& theStream)
386 SALOMEDS::Locker lock;
388 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
390 istrstream aStream((char*)&theStream[0], theStream.length());
391 return aTable->RestoreFromString(aStream);
394 SALOMEDS::TMPFile* SALOMEDS_AttributeTableOfInteger_i::SaveToFile()
396 SALOMEDS::Locker lock;
398 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
402 aTable->ConvertToString(ostr);
404 aString = ostr.rdbuf()->str();
406 char* aBuffer = (char*)CORBA::string_dup(aString.c_str());
407 int aBufferSize = strlen((char*)aBuffer);
409 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
411 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1);
413 return aStreamFile._retn();
416 char* SALOMEDS_AttributeTableOfInteger_i::Store() {
417 SALOMEDS::Locker lock;
419 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
422 aTable->ConvertToString(ostr);
423 string aString = ostr.rdbuf()->str();
425 CORBA::String_var aBuffer = CORBA::string_dup(aString.c_str());
426 return aBuffer._retn();
429 void SALOMEDS_AttributeTableOfInteger_i::Restore(const char* value) {
430 SALOMEDS::Locker lock;
432 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
434 istrstream aStream(value, strlen(value));
435 aTable->RestoreFromString(aStream);