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>
16 #include "SALOMEDS_AttributeTableOfInteger_i.hxx"
17 #include "SALOMEDS.hxx"
18 #include "Utils_ExceptHandlers.hxx"
26 #define SEPARATOR '\1'
28 UNEXPECT_CATCH(ATI_IncorrectIndex, SALOMEDS::AttributeTableOfInteger::IncorrectIndex);
29 UNEXPECT_CATCH(ATI_IncorrectArgumentLength, SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength);
31 static TCollection_ExtendedString getUnit(TCollection_ExtendedString theString)
33 TCollection_ExtendedString aString(theString);
34 int aPos = aString.Search(SEPARATOR);
35 if(aPos <= 0 || aPos == aString.Length() ) return TCollection_ExtendedString();
36 return aString.Split(aPos);
39 static TCollection_ExtendedString getTitle(TCollection_ExtendedString theString)
41 TCollection_ExtendedString aString(theString);
42 int aPos = aString.Search(SEPARATOR);
43 if(aPos < 1) return aString;
44 if(aPos == 1) return TCollection_ExtendedString();
45 aString.Split(aPos-1);
49 void SALOMEDS_AttributeTableOfInteger_i::SetTitle(const char* theTitle) {
50 SALOMEDS::Locker lock;
53 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
54 CORBA::String_var aStr = CORBA::string_dup(theTitle);
55 aTable->SetTitle(TCollection_ExtendedString(aStr));
58 char* SALOMEDS_AttributeTableOfInteger_i::GetTitle() {
59 SALOMEDS::Locker lock;
61 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
62 CORBA::String_var c_s = CORBA::string_dup(TCollection_AsciiString(aTable->GetTitle()).ToCString());
66 void SALOMEDS_AttributeTableOfInteger_i::SetRowTitle(CORBA::Long theIndex, const char* theTitle)
67 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
69 SALOMEDS::Locker lock;
71 Unexpect aCatch (ATI_IncorrectIndex);
73 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
74 if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
75 CORBA::String_var aStr = CORBA::string_dup(theTitle);
76 TCollection_ExtendedString aTitle(aStr);
77 TCollection_ExtendedString aUnit = getUnit(aTable->GetRowTitle(theIndex));
78 if(aUnit.Length() > 0) {
83 aTable->SetRowTitle(theIndex, aTitle);
86 void SALOMEDS_AttributeTableOfInteger_i::SetRowTitles(const SALOMEDS::StringSeq& theTitles)
87 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
89 SALOMEDS::Locker lock;
91 Unexpect aCatch (ATI_IncorrectArgumentLength);
93 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
94 if (theTitles.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
95 for (int i = 0; i < theTitles.length(); i++) {
96 SetRowTitle(i + 1, theTitles[i]);
100 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfInteger_i::GetRowTitles() {
101 SALOMEDS::Locker lock;
103 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
104 SALOMEDS::StringSeq_var aTitles = new SALOMEDS::StringSeq;
105 aTitles->length(aTable->GetNbRows());
106 for(int i = 0; i < aTitles->length(); i++)
107 aTitles[i] = CORBA::string_dup(TCollection_AsciiString(getTitle(aTable->GetRowTitle(i + 1))).ToCString());
108 return aTitles._retn();
111 void SALOMEDS_AttributeTableOfInteger_i::SetColumnTitle(CORBA::Long theIndex, const char* theTitle)
112 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
114 SALOMEDS::Locker lock;
116 Unexpect aCatch (ATI_IncorrectIndex);
118 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
119 if (theIndex <= 0 || theIndex > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
120 CORBA::String_var aStr = CORBA::string_dup(theTitle);
121 aTable->SetColumnTitle(theIndex, TCollection_ExtendedString(aStr));
124 void SALOMEDS_AttributeTableOfInteger_i::SetColumnTitles(const SALOMEDS::StringSeq& theTitles)
125 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
127 SALOMEDS::Locker lock;
129 Unexpect aCatch(ATI_IncorrectArgumentLength);
131 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
132 if (theTitles.length() != aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
133 for (int i = 0; i < theTitles.length(); i++) {
134 SetColumnTitle(i + 1, theTitles[i]);
138 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfInteger_i::GetColumnTitles() {
139 SALOMEDS::Locker lock;
141 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
142 SALOMEDS::StringSeq_var aTitles = new SALOMEDS::StringSeq;
143 aTitles->length(aTable->GetNbColumns());
144 for(int i = 0; i < aTitles->length(); i++)
145 aTitles[i] = CORBA::string_dup(TCollection_AsciiString(aTable->GetColumnTitle(i + 1)).ToCString());
146 return aTitles._retn();
150 void SALOMEDS_AttributeTableOfInteger_i::SetRowUnit(CORBA::Long theIndex, const char* theUnit)
151 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
153 SALOMEDS::Locker lock;
155 Unexpect aCatch (ATI_IncorrectIndex);
157 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
158 if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
159 CORBA::String_var aStr = CORBA::string_dup(theUnit);
160 TCollection_ExtendedString aTitle = getTitle(aTable->GetRowTitle(theIndex));
161 TCollection_ExtendedString aUnit(aStr);
164 aTable->SetRowTitle(theIndex, aTitle);
167 void SALOMEDS_AttributeTableOfInteger_i::SetRowUnits(const SALOMEDS::StringSeq& theUnits)
168 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
170 SALOMEDS::Locker lock;
172 Unexpect aCatch (ATI_IncorrectArgumentLength);
174 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
175 if (theUnits.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
176 for (int i = 0; i < theUnits.length(); i++) {
177 SetRowUnit(i + 1, theUnits[i]);
181 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfInteger_i::GetRowUnits() {
182 SALOMEDS::Locker lock;
184 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
185 SALOMEDS::StringSeq_var aUnits = new SALOMEDS::StringSeq;
186 aUnits->length(aTable->GetNbRows());
187 for(int i = 0; i < aUnits->length(); i++)
188 aUnits[i] = CORBA::string_dup(TCollection_AsciiString(getUnit(aTable->GetRowTitle(i + 1))).ToCString());
189 return aUnits._retn();
192 CORBA::Long SALOMEDS_AttributeTableOfInteger_i::GetNbRows() {
193 SALOMEDS::Locker lock;
195 return Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr)->GetNbRows();
197 CORBA::Long SALOMEDS_AttributeTableOfInteger_i::GetNbColumns() {
198 SALOMEDS::Locker lock;
200 return Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr)->GetNbColumns();
203 void SALOMEDS_AttributeTableOfInteger_i::AddRow(const SALOMEDS::LongSeq& theData)
204 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
206 SALOMEDS::Locker lock;
208 Unexpect aCatch(ATI_IncorrectArgumentLength);
210 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
212 Handle(TColStd_HSequenceOfInteger) aRow = new TColStd_HSequenceOfInteger;
213 for (int i = 0; i < theData.length(); i++) aRow->Append(theData[i]);
215 aTable->SetRowData(aTable->GetNbRows() + 1, aRow);
217 catch(Standard_Failure) {
218 throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
222 void SALOMEDS_AttributeTableOfInteger_i::SetRow(CORBA::Long theRow, const SALOMEDS::LongSeq& theData)
223 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength, SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
225 SALOMEDS::Locker lock;
227 Unexpect aCatch(ATI_IncorrectArgumentLength);
229 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
231 Handle(TColStd_HSequenceOfInteger) aRow = new TColStd_HSequenceOfInteger;
232 for (int i = 0; i < theData.length(); i++) aRow->Append(theData[i]);
234 aTable->SetRowData(theRow, aRow);
236 catch(Standard_Failure) {
237 throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
241 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfInteger_i::GetRow(CORBA::Long theRow)
242 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
244 SALOMEDS::Locker lock;
246 Unexpect aCatch(ATI_IncorrectIndex);
247 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
248 if (theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
250 SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
251 Handle(TColStd_HSequenceOfInteger) aRow = aTable->GetRowData(theRow);
252 CorbaSeq->length(aRow->Length());
253 for (int i = 0; i < aRow->Length(); i++) {
254 CorbaSeq[i] = aRow->Value(i + 1);
256 return CorbaSeq._retn();
259 void SALOMEDS_AttributeTableOfInteger_i::AddColumn(const SALOMEDS::LongSeq& theData)
260 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
262 SALOMEDS::Locker lock;
264 Unexpect aCatch(ATI_IncorrectArgumentLength);
266 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
268 Handle(TColStd_HSequenceOfInteger) aColumn = new TColStd_HSequenceOfInteger;
269 for (int i = 0; i < theData.length(); i++) aColumn->Append(theData[i]);
271 aTable->SetColumnData(aTable->GetNbColumns() + 1, aColumn);
273 catch(Standard_Failure) {
274 throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
278 void SALOMEDS_AttributeTableOfInteger_i::SetColumn(CORBA::Long theColumn, const SALOMEDS::LongSeq& theData)
279 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength, SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
281 SALOMEDS::Locker lock;
283 Unexpect aCatch(ATI_IncorrectArgumentLength);
285 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
287 Handle(TColStd_HSequenceOfInteger) aColumn = new TColStd_HSequenceOfInteger;
288 for (int i = 0; i < theData.length(); i++) aColumn->Append(theData[i]);
290 aTable->SetColumnData(theColumn, aColumn);
292 catch(Standard_Failure) {
293 throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
297 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfInteger_i::GetColumn(CORBA::Long theColumn)
298 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
300 SALOMEDS::Locker lock;
302 Unexpect aCatch(ATI_IncorrectIndex);
303 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
304 if (theColumn <= 0 || theColumn > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
306 SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
307 Handle(TColStd_HSequenceOfInteger) aColumn = aTable->GetColumnData(theColumn);
308 CorbaSeq->length(aColumn->Length());
309 for (int i = 0; i < aColumn->Length(); i++) {
310 CorbaSeq[i] = aColumn->Value(i + 1);
312 return CorbaSeq._retn();
315 void SALOMEDS_AttributeTableOfInteger_i::PutValue(CORBA::Long theValue, CORBA::Long theRow, CORBA::Long theColumn)
316 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
318 SALOMEDS::Locker lock;
320 Unexpect aCatch(ATI_IncorrectIndex);
322 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
325 aTable->PutValue(theValue, theRow, theColumn);
327 catch(Standard_Failure) {
328 throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
332 CORBA::Boolean SALOMEDS_AttributeTableOfInteger_i::HasValue(CORBA::Long theRow, CORBA::Long theColumn) {
333 SALOMEDS::Locker lock;
335 return Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr)->HasValue(theRow, theColumn);
338 CORBA::Long SALOMEDS_AttributeTableOfInteger_i::GetValue(CORBA::Long theRow, CORBA::Long theColumn)
339 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
341 SALOMEDS::Locker lock;
343 Unexpect aCatch(ATI_IncorrectIndex);
344 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
345 if (theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
349 aValue = aTable->GetValue(theRow, theColumn);
351 catch(Standard_Failure) {
352 throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
357 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfInteger_i::GetRowSetIndices(CORBA::Long theRow)
359 SALOMEDS::Locker lock;
361 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
363 if(theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
365 SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
366 Handle(TColStd_HSequenceOfInteger) aSeq = aTable->GetSetRowIndices(theRow);
367 CorbaSeq->length(aSeq->Length());
368 for (int i = 0; i < aSeq->Length(); i++) {
369 CorbaSeq[i] = aSeq->Value(i + 1);
371 return CorbaSeq._retn();
375 void SALOMEDS_AttributeTableOfInteger_i::SetNbColumns(CORBA::Long theNbColumns)
377 SALOMEDS::Locker lock;
379 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
380 aTable->SetNbColumns(theNbColumns);
383 bool SALOMEDS_AttributeTableOfInteger_i::ReadFromFile(const SALOMEDS::TMPFile& theStream)
385 SALOMEDS::Locker lock;
387 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
389 istrstream aStream((char*)&theStream[0], theStream.length());
390 return aTable->RestoreFromString(aStream);
393 SALOMEDS::TMPFile* SALOMEDS_AttributeTableOfInteger_i::SaveToFile()
395 SALOMEDS::Locker lock;
397 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
401 aTable->ConvertToString(ostr);
403 aString = ostr.rdbuf()->str();
405 char* aBuffer = (char*)CORBA::string_dup(aString.c_str());
406 int aBufferSize = strlen((char*)aBuffer);
408 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
410 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1);
412 return aStreamFile._retn();
415 char* SALOMEDS_AttributeTableOfInteger_i::Store() {
416 SALOMEDS::Locker lock;
418 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
421 aTable->ConvertToString(ostr);
422 string aString = ostr.rdbuf()->str();
424 CORBA::String_var aBuffer = CORBA::string_dup(aString.c_str());
425 return aBuffer._retn();
428 void SALOMEDS_AttributeTableOfInteger_i::Restore(const char* value) {
429 SALOMEDS::Locker lock;
431 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
433 istrstream aStream(value, strlen(value));
434 aTable->RestoreFromString(aStream);