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 "SALOMEDS_AttributeTableOfInteger_i.hxx"
13 #include "SALOMEDS_SObject_i.hxx"
14 #include <TColStd_HSequenceOfInteger.hxx>
15 #include <Standard_Failure.hxx>
16 #include <Standard_ErrorHandler.hxx>
22 #define SEPARATOR '\1'
24 static TCollection_ExtendedString getUnit(TCollection_ExtendedString theString)
26 TCollection_ExtendedString aString(theString);
27 int aPos = aString.Search(SEPARATOR);
28 if(aPos <= 0 || aPos == aString.Length() ) return TCollection_ExtendedString();
29 return aString.Split(aPos);
32 static TCollection_ExtendedString getTitle(TCollection_ExtendedString theString)
34 TCollection_ExtendedString aString(theString);
35 int aPos = aString.Search(SEPARATOR);
36 if(aPos < 1) return aString;
37 if(aPos == 1) return TCollection_ExtendedString();
38 aString.Split(aPos-1);
44 void SALOMEDS_AttributeTableOfInteger_i::SetTitle(const char* theTitle) {
46 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
47 CORBA::String_var aStr = CORBA::string_dup(theTitle);
48 aTable->SetTitle(TCollection_ExtendedString(aStr));
51 char* SALOMEDS_AttributeTableOfInteger_i::GetTitle() {
52 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
53 CORBA::String_var c_s = CORBA::string_dup(TCollection_AsciiString(aTable->GetTitle()).ToCString());
57 void SALOMEDS_AttributeTableOfInteger_i::SetRowTitle(CORBA::Long theIndex, const char* theTitle)
58 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
61 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
62 if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
63 CORBA::String_var aStr = CORBA::string_dup(theTitle);
64 TCollection_ExtendedString aTitle(aStr);
65 TCollection_ExtendedString aUnit = getUnit(aTable->GetRowTitle(theIndex));
66 if(aUnit.Length() > 0) {
71 aTable->SetRowTitle(theIndex, aTitle);
74 void SALOMEDS_AttributeTableOfInteger_i::SetRowTitles(const SALOMEDS::StringSeq& theTitles)
75 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
78 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
79 if (theTitles.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
80 for (int i = 0; i < theTitles.length(); i++) {
81 SetRowTitle(i + 1, theTitles[i]);
85 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfInteger_i::GetRowTitles() {
86 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
87 SALOMEDS::StringSeq_var aTitles = new SALOMEDS::StringSeq;
88 aTitles->length(aTable->GetNbRows());
89 for(int i = 0; i < aTitles->length(); i++)
90 aTitles[i] = CORBA::string_dup(TCollection_AsciiString(getTitle(aTable->GetRowTitle(i + 1))).ToCString());
91 return aTitles._retn();
94 void SALOMEDS_AttributeTableOfInteger_i::SetColumnTitle(CORBA::Long theIndex, const char* theTitle)
95 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
98 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
99 if (theIndex <= 0 || theIndex > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
100 CORBA::String_var aStr = CORBA::string_dup(theTitle);
101 aTable->SetColumnTitle(theIndex, TCollection_ExtendedString(aStr));
104 void SALOMEDS_AttributeTableOfInteger_i::SetColumnTitles(const SALOMEDS::StringSeq& theTitles)
105 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
108 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
109 if (theTitles.length() != aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
110 for (int i = 0; i < theTitles.length(); i++) {
111 SetColumnTitle(i + 1, theTitles[i]);
115 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfInteger_i::GetColumnTitles() {
116 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
117 SALOMEDS::StringSeq_var aTitles = new SALOMEDS::StringSeq;
118 aTitles->length(aTable->GetNbColumns());
119 for(int i = 0; i < aTitles->length(); i++)
120 aTitles[i] = CORBA::string_dup(TCollection_AsciiString(aTable->GetColumnTitle(i + 1)).ToCString());
121 return aTitles._retn();
125 void SALOMEDS_AttributeTableOfInteger_i::SetRowUnit(CORBA::Long theIndex, const char* theUnit)
126 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
129 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
130 if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
131 CORBA::String_var aStr = CORBA::string_dup(theUnit);
132 TCollection_ExtendedString aTitle = getTitle(aTable->GetRowTitle(theIndex));
133 TCollection_ExtendedString aUnit(aStr);
136 aTable->SetRowTitle(theIndex, aTitle);
139 void SALOMEDS_AttributeTableOfInteger_i::SetRowUnits(const SALOMEDS::StringSeq& theUnits)
140 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
143 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
144 if (theUnits.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
145 for (int i = 0; i < theUnits.length(); i++) {
146 SetRowUnit(i + 1, theUnits[i]);
150 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfInteger_i::GetRowUnits() {
151 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
152 SALOMEDS::StringSeq_var aUnits = new SALOMEDS::StringSeq;
153 aUnits->length(aTable->GetNbRows());
154 for(int i = 0; i < aUnits->length(); i++)
155 aUnits[i] = CORBA::string_dup(TCollection_AsciiString(getUnit(aTable->GetRowTitle(i + 1))).ToCString());
156 return aUnits._retn();
159 CORBA::Long SALOMEDS_AttributeTableOfInteger_i::GetNbRows() {
160 return Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr)->GetNbRows();
162 CORBA::Long SALOMEDS_AttributeTableOfInteger_i::GetNbColumns() {
163 return Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr)->GetNbColumns();
166 void SALOMEDS_AttributeTableOfInteger_i::AddRow(const SALOMEDS::LongSeq& theData)
167 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
170 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
172 Handle(TColStd_HSequenceOfInteger) aRow = new TColStd_HSequenceOfInteger;
173 for (int i = 0; i < theData.length(); i++) aRow->Append(theData[i]);
175 aTable->SetRowData(aTable->GetNbRows() + 1, aRow);
177 catch(Standard_Failure) {
178 throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
182 void SALOMEDS_AttributeTableOfInteger_i::SetRow(CORBA::Long theRow, const SALOMEDS::LongSeq& theData)
183 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength, SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
186 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
188 Handle(TColStd_HSequenceOfInteger) aRow = new TColStd_HSequenceOfInteger;
189 for (int i = 0; i < theData.length(); i++) aRow->Append(theData[i]);
191 aTable->SetRowData(theRow, aRow);
193 catch(Standard_Failure) {
194 throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
198 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfInteger_i::GetRow(CORBA::Long theRow)
199 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
201 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
202 if (theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
204 SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
205 Handle(TColStd_HSequenceOfInteger) aRow = aTable->GetRowData(theRow);
206 CorbaSeq->length(aRow->Length());
207 for (int i = 0; i < aRow->Length(); i++) {
208 CorbaSeq[i] = aRow->Value(i + 1);
210 return CorbaSeq._retn();
213 void SALOMEDS_AttributeTableOfInteger_i::AddColumn(const SALOMEDS::LongSeq& theData)
214 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
217 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
219 Handle(TColStd_HSequenceOfInteger) aColumn = new TColStd_HSequenceOfInteger;
220 for (int i = 0; i < theData.length(); i++) aColumn->Append(theData[i]);
222 aTable->SetColumnData(aTable->GetNbColumns() + 1, aColumn);
224 catch(Standard_Failure) {
225 throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
229 void SALOMEDS_AttributeTableOfInteger_i::SetColumn(CORBA::Long theColumn, const SALOMEDS::LongSeq& theData)
230 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength, SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
233 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
235 Handle(TColStd_HSequenceOfInteger) aColumn = new TColStd_HSequenceOfInteger;
236 for (int i = 0; i < theData.length(); i++) aColumn->Append(theData[i]);
238 aTable->SetColumnData(theColumn, aColumn);
240 catch(Standard_Failure) {
241 throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
245 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfInteger_i::GetColumn(CORBA::Long theColumn)
246 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
248 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
249 if (theColumn <= 0 || theColumn > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
251 SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
252 Handle(TColStd_HSequenceOfInteger) aColumn = aTable->GetColumnData(theColumn);
253 CorbaSeq->length(aColumn->Length());
254 for (int i = 0; i < aColumn->Length(); i++) {
255 CorbaSeq[i] = aColumn->Value(i + 1);
257 return CorbaSeq._retn();
260 void SALOMEDS_AttributeTableOfInteger_i::PutValue(CORBA::Long theValue, CORBA::Long theRow, CORBA::Long theColumn)
261 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
264 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
267 aTable->PutValue(theValue, theRow, theColumn);
269 catch(Standard_Failure) {
270 throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
274 CORBA::Boolean SALOMEDS_AttributeTableOfInteger_i::HasValue(CORBA::Long theRow, CORBA::Long theColumn) {
275 return Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr)->HasValue(theRow, theColumn);
278 CORBA::Long SALOMEDS_AttributeTableOfInteger_i::GetValue(CORBA::Long theRow, CORBA::Long theColumn)
279 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
281 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
282 if (theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
286 aValue = aTable->GetValue(theRow, theColumn);
288 catch(Standard_Failure) {
289 throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
294 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfInteger_i::GetRowSetIndices(CORBA::Long theRow)
296 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
298 if(theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
300 SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
301 Handle(TColStd_HSequenceOfInteger) aSeq = aTable->GetSetRowIndices(theRow);
302 CorbaSeq->length(aSeq->Length());
303 for (int i = 0; i < aSeq->Length(); i++) {
304 CorbaSeq[i] = aSeq->Value(i + 1);
306 return CorbaSeq._retn();
310 void SALOMEDS_AttributeTableOfInteger_i::SetNbColumns(CORBA::Long theNbColumns)
312 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
313 aTable->SetNbColumns(theNbColumns);
316 bool SALOMEDS_AttributeTableOfInteger_i::ReadFromFile(const SALOMEDS::TMPFile& theStream)
318 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
320 istrstream aStream((char*)&theStream[0], theStream.length());
321 return aTable->RestoreFromString(aStream);
324 SALOMEDS::TMPFile* SALOMEDS_AttributeTableOfInteger_i::SaveToFile()
326 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
330 aTable->ConvertToString(ostr);
332 aString = ostr.rdbuf()->str();
334 char* aBuffer = (char*)CORBA::string_dup(aString.c_str());
335 int aBufferSize = strlen((char*)aBuffer);
337 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
339 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1);
341 return aStreamFile._retn();