]> SALOME platform Git repositories - modules/kernel.git/blob - src/SALOMEDS/SALOMEDS_AttributeTableOfString_i.cxx
Salome HOME
Preparation of 3.1.0a2 - compilation error on Fedora3 platform
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_AttributeTableOfString_i.cxx
1 //  File   : SALOMEDS_AttributeTableOfString_i.cxx
2 //  Author : Sergey RUIN
3 //  Module : SALOME
4
5
6 #include <TCollection_ExtendedString.hxx>
7 #include <TCollection_AsciiString.hxx>
8
9 #include "SALOMEDS_AttributeTableOfString_i.hxx"
10 #include "SALOMEDS.hxx"
11
12 #include <TColStd_HSequenceOfExtendedString.hxx>
13 #include <Standard_Failure.hxx>
14 #include <Standard_ErrorHandler.hxx>
15
16 #include <strstream>
17 #include <string>
18
19 #include "Utils_ExceptHandlers.hxx"
20
21 using namespace std;
22
23 UNEXPECT_CATCH(ATS_IncorrectIndex, SALOMEDS::AttributeTableOfString::IncorrectIndex);
24 UNEXPECT_CATCH(ATS_IncorrectArgumentLength, SALOMEDS::AttributeTableOfString::IncorrectArgumentLength);
25
26 void SALOMEDS_AttributeTableOfString_i::SetTitle(const char* theTitle) 
27 {
28   SALOMEDS::Locker lock;
29   CheckLocked();
30   Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
31   CORBA::String_var aStr = CORBA::string_dup(theTitle);
32   aTable->SetTitle(TCollection_ExtendedString(aStr));
33 }
34
35 char* SALOMEDS_AttributeTableOfString_i::GetTitle() 
36 {
37   SALOMEDS::Locker lock;
38   Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
39   CORBA::String_var c_s = CORBA::string_dup(TCollection_AsciiString(aTable->GetTitle()).ToCString());
40   return c_s._retn();
41 }
42
43 void SALOMEDS_AttributeTableOfString_i::SetRowTitle(CORBA::Long theIndex, const char* theTitle)
44      throw (SALOMEDS::AttributeTableOfString::IncorrectIndex)
45 {
46   SALOMEDS::Locker lock;
47   Unexpect aCatch(ATS_IncorrectIndex);
48   CheckLocked();
49   Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
50   if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
51
52   aTable->SetRowTitle(theIndex, TCollection_ExtendedString((char*)theTitle));
53 }
54
55 void SALOMEDS_AttributeTableOfString_i::SetRowTitles(const SALOMEDS::StringSeq& theTitles)
56      throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength)
57 {
58   SALOMEDS::Locker lock;
59   Unexpect aCatch(ATS_IncorrectArgumentLength);
60   CheckLocked();
61   Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
62   if (theTitles.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectArgumentLength();
63   for (int i = 0; i < theTitles.length(); i++) {
64     aTable->SetRowTitle(i + 1, TCollection_ExtendedString((char*)theTitles[i].in()));
65   }
66 }
67
68 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfString_i::GetRowTitles() 
69 {
70   SALOMEDS::Locker lock;
71   Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
72   SALOMEDS::StringSeq_var aTitles = new SALOMEDS::StringSeq;
73   aTitles->length(aTable->GetNbRows());
74   for(int i = 0; i < aTitles->length(); i++)
75     aTitles[i] =CORBA::string_dup(TCollection_AsciiString(aTable->GetRowTitle(i + 1)).ToCString());
76   return aTitles._retn();
77 }
78
79 void SALOMEDS_AttributeTableOfString_i::SetColumnTitle(CORBA::Long theIndex, const char* theTitle)
80      throw (SALOMEDS::AttributeTableOfString::IncorrectIndex)
81 {
82   SALOMEDS::Locker lock;
83   Unexpect aCatch(ATS_IncorrectIndex);
84   CheckLocked();
85   Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
86   if (theIndex <= 0 || theIndex > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
87   aTable->SetColumnTitle(theIndex, TCollection_ExtendedString((char*)theTitle));
88 }
89
90 void SALOMEDS_AttributeTableOfString_i::SetColumnTitles(const SALOMEDS::StringSeq& theTitles)
91      throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength)
92 {
93   SALOMEDS::Locker lock;
94   Unexpect aCatch(ATS_IncorrectArgumentLength);
95   CheckLocked();
96   Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
97   if (theTitles.length() != aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfString::IncorrectArgumentLength();
98   for (int i = 0; i < theTitles.length(); i++) {
99     aTable->SetColumnTitle(i + 1, TCollection_ExtendedString((char*)theTitles[i].in()));
100   }
101 }
102
103 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfString_i::GetColumnTitles() 
104 {
105   SALOMEDS::Locker lock;
106   Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
107   SALOMEDS::StringSeq_var aTitles = new SALOMEDS::StringSeq;
108   aTitles->length(aTable->GetNbColumns());
109   for(int i = 0; i < aTitles->length(); i++)
110     aTitles[i] = CORBA::string_dup(TCollection_AsciiString(aTable->GetColumnTitle(i + 1)).ToCString());
111   return aTitles._retn();
112 }
113
114 //Units support
115 void SALOMEDS_AttributeTableOfString_i::SetRowUnit(CORBA::Long theIndex, const char* theUnit)
116      throw (SALOMEDS::AttributeTableOfString::IncorrectIndex)
117 {
118   SALOMEDS::Locker lock;
119   Unexpect aCatch(ATS_IncorrectIndex);
120   CheckLocked();
121   Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
122   if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
123   aTable->SetRowUnit(theIndex, TCollection_ExtendedString((char*)theUnit));
124 }
125
126 void SALOMEDS_AttributeTableOfString_i::SetRowUnits(const SALOMEDS::StringSeq& theUnits)
127      throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength)
128 {
129   SALOMEDS::Locker lock;
130   Unexpect aCatch(ATS_IncorrectArgumentLength);
131   CheckLocked();
132   Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
133   if (theUnits.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectArgumentLength();
134   for (int i = 0; i < theUnits.length(); i++) {
135     aTable->SetRowUnit(i + 1, TCollection_ExtendedString((char*)theUnits[i].in()));
136   }
137 }
138
139 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfString_i::GetRowUnits() 
140 {
141   SALOMEDS::Locker lock;
142   Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
143   SALOMEDS::StringSeq_var aUnits = new SALOMEDS::StringSeq;
144   aUnits->length(aTable->GetNbRows());
145   for(int i = 0; i < aUnits->length(); i++)
146     aUnits[i] = CORBA::string_dup(TCollection_AsciiString(aTable->GetRowUnit(i + 1)).ToCString());
147   return aUnits._retn();
148 }
149
150
151 CORBA::Long SALOMEDS_AttributeTableOfString_i::GetNbRows() 
152 {
153   SALOMEDS::Locker lock;
154   return Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl)->GetNbRows();
155 }
156
157 CORBA::Long SALOMEDS_AttributeTableOfString_i::GetNbColumns() 
158 {
159   SALOMEDS::Locker lock;
160   return Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl)->GetNbColumns();
161 }
162
163 void SALOMEDS_AttributeTableOfString_i::AddRow(const SALOMEDS::StringSeq& theData)
164      throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength)
165 {
166   SALOMEDS::Locker lock;
167   Unexpect aCatch(ATS_IncorrectArgumentLength);
168   CheckLocked();
169   Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
170   
171   Handle(TColStd_HSequenceOfExtendedString) aRow = new TColStd_HSequenceOfExtendedString;
172   for (int i = 0; i < theData.length(); i++) aRow->Append(TCollection_AsciiString(CORBA::string_dup(theData[i])));
173   aTable->SetRowData(aTable->GetNbRows() + 1, aRow);
174 }
175
176 void SALOMEDS_AttributeTableOfString_i::SetRow(CORBA::Long theRow, const SALOMEDS::StringSeq& theData)
177      throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength, SALOMEDS::AttributeTableOfString::IncorrectIndex)
178 {
179   SALOMEDS::Locker lock;
180   Unexpect aCatch(ATS_IncorrectArgumentLength);
181   CheckLocked();
182   Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
183   
184   Handle(TColStd_HSequenceOfExtendedString) aRow = new TColStd_HSequenceOfExtendedString;
185   for (int i = 0; i < theData.length(); i++) aRow->Append(TCollection_AsciiString(CORBA::string_dup(theData[i])));
186   aTable->SetRowData(theRow, aRow);
187 }
188
189 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfString_i::GetRow(CORBA::Long theRow)
190      throw (SALOMEDS::AttributeTableOfString::IncorrectIndex)
191 {
192   SALOMEDS::Locker lock;
193   Unexpect aCatch(ATS_IncorrectIndex);
194   Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
195   if (theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
196
197   SALOMEDS::StringSeq_var CorbaSeq = new SALOMEDS::StringSeq;
198   Handle(TColStd_HSequenceOfExtendedString) aRow = aTable->GetRowData(theRow);
199   CorbaSeq->length(aRow->Length());
200   for (int i = 0; i < aRow->Length(); i++) {
201     CorbaSeq[i] = CORBA::string_dup((TCollection_AsciiString(aRow->Value(i + 1))).ToCString());
202   }
203   return CorbaSeq._retn();
204 }
205
206 void SALOMEDS_AttributeTableOfString_i::AddColumn(const SALOMEDS::StringSeq& theData)
207      throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength)
208 {
209   SALOMEDS::Locker lock;
210   Unexpect aCatch(ATS_IncorrectArgumentLength);
211   CheckLocked();
212   Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
213   
214   Handle(TColStd_HSequenceOfExtendedString) aColumn = new TColStd_HSequenceOfExtendedString;
215   for (int i = 0; i < theData.length(); i++) aColumn->Append(TCollection_AsciiString(CORBA::string_dup(theData[i])));
216   aTable->SetColumnData(aTable->GetNbColumns() + 1, aColumn);
217 }
218
219 void SALOMEDS_AttributeTableOfString_i::SetColumn(CORBA::Long theColumn, const SALOMEDS::StringSeq& theData)
220      throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength, SALOMEDS::AttributeTableOfString::IncorrectIndex)
221 {
222   SALOMEDS::Locker lock;
223   Unexpect aCatch(ATS_IncorrectArgumentLength);
224   CheckLocked();
225   Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
226   
227   Handle(TColStd_HSequenceOfExtendedString) aColumn = new TColStd_HSequenceOfExtendedString;
228   for (int i = 0; i < theData.length(); i++) aColumn->Append(TCollection_AsciiString(CORBA::string_dup(theData[i])));
229   aTable->SetColumnData(theColumn, aColumn);
230 }
231
232 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfString_i::GetColumn(CORBA::Long theColumn)
233      throw (SALOMEDS::AttributeTableOfString::IncorrectIndex)
234 {
235   SALOMEDS::Locker lock;
236   Unexpect aCatch(ATS_IncorrectIndex);
237   Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
238   if (theColumn <= 0 || theColumn > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
239
240   SALOMEDS::StringSeq_var CorbaSeq = new SALOMEDS::StringSeq;
241   Handle(TColStd_HSequenceOfExtendedString) aColumn = aTable->GetColumnData(theColumn);
242   CorbaSeq->length(aColumn->Length());
243   for (int i = 0; i < aColumn->Length(); i++) {
244     CorbaSeq[i] = CORBA::string_dup((TCollection_AsciiString(aColumn->Value(i + 1))).ToCString());
245   }
246   return CorbaSeq._retn();
247 }
248
249 void SALOMEDS_AttributeTableOfString_i::PutValue(const char* theValue, CORBA::Long theRow, CORBA::Long theColumn)
250      throw (SALOMEDS::AttributeTableOfString::IncorrectIndex)
251 {
252   SALOMEDS::Locker lock;
253   Unexpect aCatch(ATS_IncorrectIndex);
254   CheckLocked();
255   Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
256   char* aValue = CORBA::string_dup(theValue);
257
258   aTable->PutValue(aValue, theRow, theColumn);
259 }
260
261 CORBA::Boolean SALOMEDS_AttributeTableOfString_i::HasValue(CORBA::Long theRow, CORBA::Long theColumn) 
262 {
263   SALOMEDS::Locker lock;
264   return Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl)->HasValue(theRow, theColumn);
265 }
266
267 char* SALOMEDS_AttributeTableOfString_i::GetValue(CORBA::Long theRow, CORBA::Long theColumn)
268      throw (SALOMEDS::AttributeTableOfString::IncorrectIndex)
269 {
270   SALOMEDS::Locker lock;
271   Unexpect aCatch(ATS_IncorrectIndex);
272   Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
273   if (theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
274
275   TCollection_AsciiString aValue;
276
277   try {
278     aValue = aTable->GetValue(theRow, theColumn);
279   }
280   catch(Standard_Failure) {
281     throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
282   }
283
284   return CORBA::string_dup(aValue.ToCString());
285 }
286
287
288 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfString_i::GetRowSetIndices(CORBA::Long theRow) 
289 {
290   SALOMEDS::Locker lock;
291   Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
292
293   if(theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
294
295   SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
296   Handle(TColStd_HSequenceOfInteger) aSeq = aTable->GetSetRowIndices(theRow);
297   CorbaSeq->length(aSeq->Length());
298   for (int i = 0; i < aSeq->Length(); i++) {
299     CorbaSeq[i] = aSeq->Value(i + 1);
300   }
301   return CorbaSeq._retn(); 
302 }
303
304
305 void SALOMEDS_AttributeTableOfString_i::SetNbColumns(CORBA::Long theNbColumns)
306 {
307   SALOMEDS::Locker lock;
308   Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
309   aTable->SetNbColumns(theNbColumns);
310 }
311
312 bool SALOMEDS_AttributeTableOfString_i::ReadFromFile(const SALOMEDS::TMPFile& theStream) 
313 {
314   SALOMEDS::Locker lock;
315   Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
316
317   istrstream aStream((char*)&theStream[0], theStream.length());
318   return aTable->RestoreFromString(aStream);
319 }
320
321 SALOMEDS::TMPFile*  SALOMEDS_AttributeTableOfString_i::SaveToFile()
322 {
323   SALOMEDS::Locker lock;
324   Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(_impl);
325
326   ostrstream ostr;
327   aTable->ConvertToString(ostr);
328   CORBA::Octet* anOctetBuf =  (CORBA::Octet*)ostr.rdbuf()->str();
329   unsigned long aSize = ostr.pcount();
330   SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(aSize, aSize, anOctetBuf, 1);
331   return aStreamFile._retn();
332 }
333