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
13 #include "SALOMEDS_AttributeTableOfInteger_i.hxx"
14 #include "SALOMEDS_SObject_i.hxx"
15 #include <TColStd_HSequenceOfInteger.hxx>
16 #include <Standard_Failure.hxx>
17 #include <Standard_ErrorHandler.hxx>
18 #include "Utils_ExceptHandlers.hxx"
24 #define SEPARATOR '\1'
26 UNEXPECT_CATCH(ATI_IncorrectIndex, SALOMEDS::AttributeTableOfInteger::IncorrectIndex);
27 UNEXPECT_CATCH(ATI_IncorrectArgumentLength, SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength);
29 static TCollection_ExtendedString getUnit(TCollection_ExtendedString theString)
31 TCollection_ExtendedString aString(theString);
32 int aPos = aString.Search(SEPARATOR);
33 if(aPos <= 0 || aPos == aString.Length() ) return TCollection_ExtendedString();
34 return aString.Split(aPos);
37 static TCollection_ExtendedString getTitle(TCollection_ExtendedString theString)
39 TCollection_ExtendedString aString(theString);
40 int aPos = aString.Search(SEPARATOR);
41 if(aPos < 1) return aString;
42 if(aPos == 1) return TCollection_ExtendedString();
43 aString.Split(aPos-1);
49 void SALOMEDS_AttributeTableOfInteger_i::SetTitle(const char* theTitle) {
51 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
52 CORBA::String_var aStr = CORBA::string_dup(theTitle);
53 aTable->SetTitle(TCollection_ExtendedString(aStr));
56 char* SALOMEDS_AttributeTableOfInteger_i::GetTitle() {
57 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
58 CORBA::String_var c_s = CORBA::string_dup(TCollection_AsciiString(aTable->GetTitle()).ToCString());
62 void SALOMEDS_AttributeTableOfInteger_i::SetRowTitle(CORBA::Long theIndex, const char* theTitle)
63 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
65 Unexpect aCatch (ATI_IncorrectIndex);
67 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
68 if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
69 CORBA::String_var aStr = CORBA::string_dup(theTitle);
70 TCollection_ExtendedString aTitle(aStr);
71 TCollection_ExtendedString aUnit = getUnit(aTable->GetRowTitle(theIndex));
72 if(aUnit.Length() > 0) {
77 aTable->SetRowTitle(theIndex, aTitle);
80 void SALOMEDS_AttributeTableOfInteger_i::SetRowTitles(const SALOMEDS::StringSeq& theTitles)
81 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
83 Unexpect aCatch (ATI_IncorrectArgumentLength);
85 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
86 if (theTitles.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
87 for (int i = 0; i < theTitles.length(); i++) {
88 SetRowTitle(i + 1, theTitles[i]);
92 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfInteger_i::GetRowTitles() {
93 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
94 SALOMEDS::StringSeq_var aTitles = new SALOMEDS::StringSeq;
95 aTitles->length(aTable->GetNbRows());
96 for(int i = 0; i < aTitles->length(); i++)
97 aTitles[i] = CORBA::string_dup(TCollection_AsciiString(getTitle(aTable->GetRowTitle(i + 1))).ToCString());
98 return aTitles._retn();
101 void SALOMEDS_AttributeTableOfInteger_i::SetColumnTitle(CORBA::Long theIndex, const char* theTitle)
102 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
104 Unexpect aCatch (ATI_IncorrectIndex);
106 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
107 if (theIndex <= 0 || theIndex > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
108 CORBA::String_var aStr = CORBA::string_dup(theTitle);
109 aTable->SetColumnTitle(theIndex, TCollection_ExtendedString(aStr));
112 void SALOMEDS_AttributeTableOfInteger_i::SetColumnTitles(const SALOMEDS::StringSeq& theTitles)
113 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
115 Unexpect aCatch(ATI_IncorrectArgumentLength);
117 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
118 if (theTitles.length() != aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
119 for (int i = 0; i < theTitles.length(); i++) {
120 SetColumnTitle(i + 1, theTitles[i]);
124 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfInteger_i::GetColumnTitles() {
125 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
126 SALOMEDS::StringSeq_var aTitles = new SALOMEDS::StringSeq;
127 aTitles->length(aTable->GetNbColumns());
128 for(int i = 0; i < aTitles->length(); i++)
129 aTitles[i] = CORBA::string_dup(TCollection_AsciiString(aTable->GetColumnTitle(i + 1)).ToCString());
130 return aTitles._retn();
134 void SALOMEDS_AttributeTableOfInteger_i::SetRowUnit(CORBA::Long theIndex, const char* theUnit)
135 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
137 Unexpect aCatch (ATI_IncorrectIndex);
139 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
140 if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
141 CORBA::String_var aStr = CORBA::string_dup(theUnit);
142 TCollection_ExtendedString aTitle = getTitle(aTable->GetRowTitle(theIndex));
143 TCollection_ExtendedString aUnit(aStr);
146 aTable->SetRowTitle(theIndex, aTitle);
149 void SALOMEDS_AttributeTableOfInteger_i::SetRowUnits(const SALOMEDS::StringSeq& theUnits)
150 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
152 Unexpect aCatch (ATI_IncorrectArgumentLength);
154 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
155 if (theUnits.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
156 for (int i = 0; i < theUnits.length(); i++) {
157 SetRowUnit(i + 1, theUnits[i]);
161 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfInteger_i::GetRowUnits() {
162 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
163 SALOMEDS::StringSeq_var aUnits = new SALOMEDS::StringSeq;
164 aUnits->length(aTable->GetNbRows());
165 for(int i = 0; i < aUnits->length(); i++)
166 aUnits[i] = CORBA::string_dup(TCollection_AsciiString(getUnit(aTable->GetRowTitle(i + 1))).ToCString());
167 return aUnits._retn();
170 CORBA::Long SALOMEDS_AttributeTableOfInteger_i::GetNbRows() {
171 return Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr)->GetNbRows();
173 CORBA::Long SALOMEDS_AttributeTableOfInteger_i::GetNbColumns() {
174 return Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr)->GetNbColumns();
177 void SALOMEDS_AttributeTableOfInteger_i::AddRow(const SALOMEDS::LongSeq& theData)
178 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
180 Unexpect aCatch(ATI_IncorrectArgumentLength);
182 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
184 Handle(TColStd_HSequenceOfInteger) aRow = new TColStd_HSequenceOfInteger;
185 for (int i = 0; i < theData.length(); i++) aRow->Append(theData[i]);
187 aTable->SetRowData(aTable->GetNbRows() + 1, aRow);
189 catch(Standard_Failure) {
190 throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
194 void SALOMEDS_AttributeTableOfInteger_i::SetRow(CORBA::Long theRow, const SALOMEDS::LongSeq& theData)
195 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength, SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
197 Unexpect aCatch(ATI_IncorrectArgumentLength);
199 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
201 Handle(TColStd_HSequenceOfInteger) aRow = new TColStd_HSequenceOfInteger;
202 for (int i = 0; i < theData.length(); i++) aRow->Append(theData[i]);
204 aTable->SetRowData(theRow, aRow);
206 catch(Standard_Failure) {
207 throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
211 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfInteger_i::GetRow(CORBA::Long theRow)
212 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
214 Unexpect aCatch(ATI_IncorrectIndex);
215 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
216 if (theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
218 SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
219 Handle(TColStd_HSequenceOfInteger) aRow = aTable->GetRowData(theRow);
220 CorbaSeq->length(aRow->Length());
221 for (int i = 0; i < aRow->Length(); i++) {
222 CorbaSeq[i] = aRow->Value(i + 1);
224 return CorbaSeq._retn();
227 void SALOMEDS_AttributeTableOfInteger_i::AddColumn(const SALOMEDS::LongSeq& theData)
228 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
230 Unexpect aCatch(ATI_IncorrectArgumentLength);
232 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
234 Handle(TColStd_HSequenceOfInteger) aColumn = new TColStd_HSequenceOfInteger;
235 for (int i = 0; i < theData.length(); i++) aColumn->Append(theData[i]);
237 aTable->SetColumnData(aTable->GetNbColumns() + 1, aColumn);
239 catch(Standard_Failure) {
240 throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
244 void SALOMEDS_AttributeTableOfInteger_i::SetColumn(CORBA::Long theColumn, const SALOMEDS::LongSeq& theData)
245 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength, SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
247 Unexpect aCatch(ATI_IncorrectArgumentLength);
249 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
251 Handle(TColStd_HSequenceOfInteger) aColumn = new TColStd_HSequenceOfInteger;
252 for (int i = 0; i < theData.length(); i++) aColumn->Append(theData[i]);
254 aTable->SetColumnData(theColumn, aColumn);
256 catch(Standard_Failure) {
257 throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
261 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfInteger_i::GetColumn(CORBA::Long theColumn)
262 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
264 Unexpect aCatch(ATI_IncorrectIndex);
265 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
266 if (theColumn <= 0 || theColumn > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
268 SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
269 Handle(TColStd_HSequenceOfInteger) aColumn = aTable->GetColumnData(theColumn);
270 CorbaSeq->length(aColumn->Length());
271 for (int i = 0; i < aColumn->Length(); i++) {
272 CorbaSeq[i] = aColumn->Value(i + 1);
274 return CorbaSeq._retn();
277 void SALOMEDS_AttributeTableOfInteger_i::PutValue(CORBA::Long theValue, CORBA::Long theRow, CORBA::Long theColumn)
278 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
280 Unexpect aCatch(ATI_IncorrectIndex);
282 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
285 aTable->PutValue(theValue, theRow, theColumn);
287 catch(Standard_Failure) {
288 throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
292 CORBA::Boolean SALOMEDS_AttributeTableOfInteger_i::HasValue(CORBA::Long theRow, CORBA::Long theColumn) {
293 return Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr)->HasValue(theRow, theColumn);
296 CORBA::Long SALOMEDS_AttributeTableOfInteger_i::GetValue(CORBA::Long theRow, CORBA::Long theColumn)
297 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
299 Unexpect aCatch(ATI_IncorrectIndex);
300 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
301 if (theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
305 aValue = aTable->GetValue(theRow, theColumn);
307 catch(Standard_Failure) {
308 throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
313 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfInteger_i::GetRowSetIndices(CORBA::Long theRow)
315 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
317 if(theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
319 SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
320 Handle(TColStd_HSequenceOfInteger) aSeq = aTable->GetSetRowIndices(theRow);
321 CorbaSeq->length(aSeq->Length());
322 for (int i = 0; i < aSeq->Length(); i++) {
323 CorbaSeq[i] = aSeq->Value(i + 1);
325 return CorbaSeq._retn();
329 void SALOMEDS_AttributeTableOfInteger_i::SetNbColumns(CORBA::Long theNbColumns)
331 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
332 aTable->SetNbColumns(theNbColumns);
335 bool SALOMEDS_AttributeTableOfInteger_i::ReadFromFile(const SALOMEDS::TMPFile& theStream)
337 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
339 istrstream aStream((char*)&theStream[0], theStream.length());
340 return aTable->RestoreFromString(aStream);
343 SALOMEDS::TMPFile* SALOMEDS_AttributeTableOfInteger_i::SaveToFile()
345 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
349 aTable->ConvertToString(ostr);
351 aString = ostr.rdbuf()->str();
353 char* aBuffer = (char*)CORBA::string_dup(aString.c_str());
354 int aBufferSize = strlen((char*)aBuffer);
356 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
358 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1);
360 return aStreamFile._retn();
363 char* SALOMEDS_AttributeTableOfInteger_i::Store() {
364 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
367 aTable->ConvertToString(ostr);
368 string aString = ostr.rdbuf()->str();
370 CORBA::String_var aBuffer = CORBA::string_dup(aString.c_str());
371 return aBuffer._retn();
374 void SALOMEDS_AttributeTableOfInteger_i::Restore(const char* value) {
375 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
377 istrstream aStream(value, strlen(value));
378 aTable->RestoreFromString(aStream);