2 // File : SALOMEDS_AttributeTableOfInteger_i.cxx
3 // Created : Tue Oct 8 10:13:30 2002
4 // Author : Michael Ponikarov
7 // Copyright : Open CASCADE
11 #include "SALOMEDS_AttributeTableOfInteger_i.hxx"
12 #include "SALOMEDS_SObject_i.hxx"
13 #include <TColStd_HSequenceOfInteger.hxx>
14 #include <Standard_Failure.hxx>
15 #include <Standard_ErrorHandler.hxx>
20 #define SEPARATOR '\1'
22 static TCollection_ExtendedString getUnit(TCollection_ExtendedString theString)
24 TCollection_ExtendedString aString(theString);
25 int aPos = aString.Search(SEPARATOR);
26 if(aPos <= 0 || aPos == aString.Length() ) return TCollection_ExtendedString();
27 return aString.Split(aPos);
30 static TCollection_ExtendedString getTitle(TCollection_ExtendedString theString)
32 TCollection_ExtendedString aString(theString);
33 int aPos = aString.Search(SEPARATOR);
34 if(aPos < 1) return aString;
35 if(aPos == 1) return TCollection_ExtendedString();
36 aString.Split(aPos-1);
42 void SALOMEDS_AttributeTableOfInteger_i::SetTitle(const char* theTitle) {
44 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
45 CORBA::String_var aStr = CORBA::string_dup(theTitle);
46 aTable->SetTitle(TCollection_ExtendedString(aStr));
49 char* SALOMEDS_AttributeTableOfInteger_i::GetTitle() {
50 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
51 CORBA::String_var c_s = CORBA::string_dup(TCollection_AsciiString(aTable->GetTitle()).ToCString());
55 void SALOMEDS_AttributeTableOfInteger_i::SetRowTitle(CORBA::Long theIndex, const char* theTitle)
56 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
59 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
60 if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
61 CORBA::String_var aStr = CORBA::string_dup(theTitle);
62 TCollection_ExtendedString aTitle(aStr);
63 TCollection_ExtendedString aUnit = getUnit(aTable->GetRowTitle(theIndex));
64 if(aUnit.Length() > 0) {
69 aTable->SetRowTitle(theIndex, aTitle);
72 void SALOMEDS_AttributeTableOfInteger_i::SetRowTitles(const SALOMEDS::StringSeq& theTitles)
73 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
76 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
77 if (theTitles.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
78 for (int i = 0; i < theTitles.length(); i++) {
79 SetRowTitle(i + 1, theTitles[i]);
83 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfInteger_i::GetRowTitles() {
84 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
85 SALOMEDS::StringSeq_var aTitles = new SALOMEDS::StringSeq;
86 aTitles->length(aTable->GetNbRows());
87 for(int i = 0; i < aTitles->length(); i++)
88 aTitles[i] = CORBA::string_dup(TCollection_AsciiString(getTitle(aTable->GetRowTitle(i + 1))).ToCString());
89 return aTitles._retn();
92 void SALOMEDS_AttributeTableOfInteger_i::SetColumnTitle(CORBA::Long theIndex, const char* theTitle)
93 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
96 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
97 if (theIndex <= 0 || theIndex > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
98 CORBA::String_var aStr = CORBA::string_dup(theTitle);
99 aTable->SetColumnTitle(theIndex, TCollection_ExtendedString(aStr));
102 void SALOMEDS_AttributeTableOfInteger_i::SetColumnTitles(const SALOMEDS::StringSeq& theTitles)
103 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
106 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
107 if (theTitles.length() != aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
108 for (int i = 0; i < theTitles.length(); i++) {
109 SetColumnTitle(i + 1, theTitles[i]);
113 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfInteger_i::GetColumnTitles() {
114 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
115 SALOMEDS::StringSeq_var aTitles = new SALOMEDS::StringSeq;
116 aTitles->length(aTable->GetNbColumns());
117 for(int i = 0; i < aTitles->length(); i++)
118 aTitles[i] = CORBA::string_dup(TCollection_AsciiString(aTable->GetColumnTitle(i + 1)).ToCString());
119 return aTitles._retn();
123 void SALOMEDS_AttributeTableOfInteger_i::SetRowUnit(CORBA::Long theIndex, const char* theUnit)
124 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
127 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
128 if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
129 CORBA::String_var aStr = CORBA::string_dup(theUnit);
130 TCollection_ExtendedString aTitle = getTitle(aTable->GetRowTitle(theIndex));
131 TCollection_ExtendedString aUnit(aStr);
134 aTable->SetRowTitle(theIndex, aTitle);
137 void SALOMEDS_AttributeTableOfInteger_i::SetRowUnits(const SALOMEDS::StringSeq& theUnits)
138 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
141 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
142 if (theUnits.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
143 for (int i = 0; i < theUnits.length(); i++) {
144 SetRowUnit(i + 1, theUnits[i]);
148 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfInteger_i::GetRowUnits() {
149 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
150 SALOMEDS::StringSeq_var aUnits = new SALOMEDS::StringSeq;
151 aUnits->length(aTable->GetNbRows());
152 for(int i = 0; i < aUnits->length(); i++)
153 aUnits[i] = CORBA::string_dup(TCollection_AsciiString(getUnit(aTable->GetRowTitle(i + 1))).ToCString());
154 return aUnits._retn();
157 CORBA::Long SALOMEDS_AttributeTableOfInteger_i::GetNbRows() {
158 return Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr)->GetNbRows();
160 CORBA::Long SALOMEDS_AttributeTableOfInteger_i::GetNbColumns() {
161 return Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr)->GetNbColumns();
164 void SALOMEDS_AttributeTableOfInteger_i::AddRow(const SALOMEDS::LongSeq& theData)
165 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
168 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
170 Handle(TColStd_HSequenceOfInteger) aRow = new TColStd_HSequenceOfInteger;
171 for (int i = 0; i < theData.length(); i++) aRow->Append(theData[i]);
173 aTable->SetRowData(aTable->GetNbRows() + 1, aRow);
175 catch(Standard_Failure) {
176 throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
180 void SALOMEDS_AttributeTableOfInteger_i::SetRow(CORBA::Long theRow, const SALOMEDS::LongSeq& theData)
181 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength, SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
184 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
186 Handle(TColStd_HSequenceOfInteger) aRow = new TColStd_HSequenceOfInteger;
187 for (int i = 0; i < theData.length(); i++) aRow->Append(theData[i]);
189 aTable->SetRowData(theRow, aRow);
191 catch(Standard_Failure) {
192 throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
196 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfInteger_i::GetRow(CORBA::Long theRow)
197 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
199 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
200 if (theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
202 SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
203 Handle(TColStd_HSequenceOfInteger) aRow = aTable->GetRowData(theRow);
204 CorbaSeq->length(aRow->Length());
205 for (int i = 0; i < aRow->Length(); i++) {
206 CorbaSeq[i] = aRow->Value(i + 1);
208 return CorbaSeq._retn();
211 void SALOMEDS_AttributeTableOfInteger_i::AddColumn(const SALOMEDS::LongSeq& theData)
212 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
215 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
217 Handle(TColStd_HSequenceOfInteger) aColumn = new TColStd_HSequenceOfInteger;
218 for (int i = 0; i < theData.length(); i++) aColumn->Append(theData[i]);
220 aTable->SetColumnData(aTable->GetNbColumns() + 1, aColumn);
222 catch(Standard_Failure) {
223 throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
227 void SALOMEDS_AttributeTableOfInteger_i::SetColumn(CORBA::Long theColumn, const SALOMEDS::LongSeq& theData)
228 throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength, SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
231 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
233 Handle(TColStd_HSequenceOfInteger) aColumn = new TColStd_HSequenceOfInteger;
234 for (int i = 0; i < theData.length(); i++) aColumn->Append(theData[i]);
236 aTable->SetColumnData(theColumn, aColumn);
238 catch(Standard_Failure) {
239 throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
243 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfInteger_i::GetColumn(CORBA::Long theColumn)
244 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
246 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
247 if (theColumn <= 0 || theColumn > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
249 SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
250 Handle(TColStd_HSequenceOfInteger) aColumn = aTable->GetColumnData(theColumn);
251 CorbaSeq->length(aColumn->Length());
252 for (int i = 0; i < aColumn->Length(); i++) {
253 CorbaSeq[i] = aColumn->Value(i + 1);
255 return CorbaSeq._retn();
258 void SALOMEDS_AttributeTableOfInteger_i::PutValue(CORBA::Long theValue, CORBA::Long theRow, CORBA::Long theColumn)
259 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
262 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
265 aTable->PutValue(theValue, theRow, theColumn);
267 catch(Standard_Failure) {
268 throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
272 CORBA::Boolean SALOMEDS_AttributeTableOfInteger_i::HasValue(CORBA::Long theRow, CORBA::Long theColumn) {
273 return Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr)->HasValue(theRow, theColumn);
276 CORBA::Long SALOMEDS_AttributeTableOfInteger_i::GetValue(CORBA::Long theRow, CORBA::Long theColumn)
277 throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
279 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
280 if (theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
284 aValue = aTable->GetValue(theRow, theColumn);
286 catch(Standard_Failure) {
287 throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
292 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfInteger_i::GetRowSetIndices(CORBA::Long theRow)
294 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
296 if(theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
298 SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
299 Handle(TColStd_HSequenceOfInteger) aSeq = aTable->GetSetRowIndices(theRow);
300 CorbaSeq->length(aSeq->Length());
301 for (int i = 0; i < aSeq->Length(); i++) {
302 CorbaSeq[i] = aSeq->Value(i + 1);
304 return CorbaSeq._retn();
308 void SALOMEDS_AttributeTableOfInteger_i::SetNbColumns(CORBA::Long theNbColumns)
310 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
311 aTable->SetNbColumns(theNbColumns);
314 bool SALOMEDS_AttributeTableOfInteger_i::ReadFromFile(const SALOMEDS::TMPFile& theStream)
316 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
318 istrstream aStream((char*)&theStream[0], theStream.length());
319 return aTable->RestoreFromString(aStream);
322 SALOMEDS::TMPFile* SALOMEDS_AttributeTableOfInteger_i::SaveToFile()
324 Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
328 aTable->ConvertToString(ostr);
330 aString = ostr.rdbuf()->str();
332 char* aBuffer = (char*)CORBA::string_dup(aString.c_str());
333 int aBufferSize = strlen((char*)aBuffer);
335 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
337 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1);
339 return aStreamFile._retn();