Salome HOME
Removed includes and libraries of OCC
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_AttributeTableOfString_i.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 //  File   : SALOMEDS_AttributeTableOfString_i.cxx
21 //  Author : Sergey RUIN
22 //  Module : SALOME
23
24
25 #include "SALOMEDS_AttributeTableOfString_i.hxx"
26 #include "SALOMEDS.hxx"
27
28 #include <strstream>
29 #include <string>
30 #include <vector>
31
32 #include "Utils_ExceptHandlers.hxx"
33
34 using namespace std;
35
36 UNEXPECT_CATCH(ATS_IncorrectIndex, SALOMEDS::AttributeTableOfString::IncorrectIndex);
37 UNEXPECT_CATCH(ATS_IncorrectArgumentLength, SALOMEDS::AttributeTableOfString::IncorrectArgumentLength);
38
39 void SALOMEDS_AttributeTableOfString_i::SetTitle(const char* theTitle) 
40 {
41   SALOMEDS::Locker lock;
42   CheckLocked();
43   SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
44   CORBA::String_var aStr = CORBA::string_dup(theTitle);
45   aTable->SetTitle(string(aStr));
46 }
47
48 char* SALOMEDS_AttributeTableOfString_i::GetTitle() 
49 {
50   SALOMEDS::Locker lock;
51   SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
52   CORBA::String_var c_s = CORBA::string_dup(aTable->GetTitle().c_str());
53   return c_s._retn();
54 }
55
56 void SALOMEDS_AttributeTableOfString_i::SetRowTitle(CORBA::Long theIndex, const char* theTitle)
57      throw (SALOMEDS::AttributeTableOfString::IncorrectIndex)
58 {
59   SALOMEDS::Locker lock;
60   Unexpect aCatch(ATS_IncorrectIndex);
61   CheckLocked();
62   SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
63   if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
64
65   aTable->SetRowTitle(theIndex, string(theTitle));
66 }
67
68 void SALOMEDS_AttributeTableOfString_i::SetRowTitles(const SALOMEDS::StringSeq& theTitles)
69      throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength)
70 {
71   SALOMEDS::Locker lock;
72   Unexpect aCatch(ATS_IncorrectArgumentLength);
73   CheckLocked();
74   SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
75   if (theTitles.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectArgumentLength();
76   for (int i = 0; i < theTitles.length(); i++) {
77     aTable->SetRowTitle(i + 1, string((char*)theTitles[i].in()));
78   }
79 }
80
81 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfString_i::GetRowTitles() 
82 {
83   SALOMEDS::Locker lock;
84   SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
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(aTable->GetRowTitle(i + 1).c_str());
89   return aTitles._retn();
90 }
91
92 void SALOMEDS_AttributeTableOfString_i::SetColumnTitle(CORBA::Long theIndex, const char* theTitle)
93      throw (SALOMEDS::AttributeTableOfString::IncorrectIndex)
94 {
95   SALOMEDS::Locker lock;
96   Unexpect aCatch(ATS_IncorrectIndex);
97   CheckLocked();
98   SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
99   if (theIndex <= 0 || theIndex > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
100   aTable->SetColumnTitle(theIndex, string((char*)theTitle));
101 }
102
103 void SALOMEDS_AttributeTableOfString_i::SetColumnTitles(const SALOMEDS::StringSeq& theTitles)
104      throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength)
105 {
106   SALOMEDS::Locker lock;
107   Unexpect aCatch(ATS_IncorrectArgumentLength);
108   CheckLocked();
109   SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
110   if (theTitles.length() != aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfString::IncorrectArgumentLength();
111   for (int i = 0; i < theTitles.length(); i++) {
112     aTable->SetColumnTitle(i + 1, string((char*)theTitles[i].in()));
113   }
114 }
115
116 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfString_i::GetColumnTitles() 
117 {
118   SALOMEDS::Locker lock;
119   SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
120   SALOMEDS::StringSeq_var aTitles = new SALOMEDS::StringSeq;
121   aTitles->length(aTable->GetNbColumns());
122   for(int i = 0; i < aTitles->length(); i++)
123     aTitles[i] = CORBA::string_dup(aTable->GetColumnTitle(i + 1).c_str());
124   return aTitles._retn();
125 }
126
127 //Units support
128 void SALOMEDS_AttributeTableOfString_i::SetRowUnit(CORBA::Long theIndex, const char* theUnit)
129      throw (SALOMEDS::AttributeTableOfString::IncorrectIndex)
130 {
131   SALOMEDS::Locker lock;
132   Unexpect aCatch(ATS_IncorrectIndex);
133   CheckLocked();
134   SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
135   if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
136   aTable->SetRowUnit(theIndex, string((char*)theUnit));
137 }
138
139 void SALOMEDS_AttributeTableOfString_i::SetRowUnits(const SALOMEDS::StringSeq& theUnits)
140      throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength)
141 {
142   SALOMEDS::Locker lock;
143   Unexpect aCatch(ATS_IncorrectArgumentLength);
144   CheckLocked();
145   SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
146   if (theUnits.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectArgumentLength();
147   for (int i = 0; i < theUnits.length(); i++) {
148     aTable->SetRowUnit(i + 1, string((char*)theUnits[i].in()));
149   }
150 }
151
152 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfString_i::GetRowUnits() 
153 {
154   SALOMEDS::Locker lock;
155   SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
156   SALOMEDS::StringSeq_var aUnits = new SALOMEDS::StringSeq;
157   aUnits->length(aTable->GetNbRows());
158   for(int i = 0; i < aUnits->length(); i++)
159     aUnits[i] = CORBA::string_dup(aTable->GetRowUnit(i + 1).c_str());
160   return aUnits._retn();
161 }
162
163
164 CORBA::Long SALOMEDS_AttributeTableOfString_i::GetNbRows() 
165 {
166   SALOMEDS::Locker lock;
167   return dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl)->GetNbRows();
168 }
169
170 CORBA::Long SALOMEDS_AttributeTableOfString_i::GetNbColumns() 
171 {
172   SALOMEDS::Locker lock;
173   return dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl)->GetNbColumns();
174 }
175
176 void SALOMEDS_AttributeTableOfString_i::AddRow(const SALOMEDS::StringSeq& theData)
177      throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength)
178 {
179   SALOMEDS::Locker lock;
180   Unexpect aCatch(ATS_IncorrectArgumentLength);
181   CheckLocked();
182   SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
183   
184   vector<string> aRow;
185   for (int i = 0; i < theData.length(); i++) aRow.push_back(string(CORBA::string_dup(theData[i])));
186   aTable->SetRowData(aTable->GetNbRows() + 1, aRow);
187 }
188
189 void SALOMEDS_AttributeTableOfString_i::SetRow(CORBA::Long theRow, const SALOMEDS::StringSeq& theData)
190      throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength, SALOMEDS::AttributeTableOfString::IncorrectIndex)
191 {
192   SALOMEDS::Locker lock;
193   Unexpect aCatch(ATS_IncorrectArgumentLength);
194   CheckLocked();
195   SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
196   
197   vector<string> aRow;
198   for (int i = 0; i < theData.length(); i++) aRow.push_back(string(CORBA::string_dup(theData[i].in())));
199   aTable->SetRowData(theRow, aRow);
200 }
201
202 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfString_i::GetRow(CORBA::Long theRow)
203      throw (SALOMEDS::AttributeTableOfString::IncorrectIndex)
204 {
205   SALOMEDS::Locker lock;
206   Unexpect aCatch(ATS_IncorrectIndex);
207   SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
208   if (theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
209
210   SALOMEDS::StringSeq_var CorbaSeq = new SALOMEDS::StringSeq;
211   vector<string> aRow = aTable->GetRowData(theRow);
212   CorbaSeq->length(aRow.size());
213   for (int i = 0; i < aRow.size(); i++) {
214     CorbaSeq[i] = CORBA::string_dup(aRow[i].c_str());
215   }
216   return CorbaSeq._retn();
217 }
218
219 void SALOMEDS_AttributeTableOfString_i::AddColumn(const SALOMEDS::StringSeq& theData)
220      throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength)
221 {
222   SALOMEDS::Locker lock;
223   Unexpect aCatch(ATS_IncorrectArgumentLength);
224   CheckLocked();
225   SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
226   
227   vector<string> aColumn;
228   for (int i = 0; i < theData.length(); i++) aColumn.push_back(string(CORBA::string_dup(theData[i])));
229   aTable->SetColumnData(aTable->GetNbColumns() + 1, aColumn);
230 }
231
232 void SALOMEDS_AttributeTableOfString_i::SetColumn(CORBA::Long theColumn, const SALOMEDS::StringSeq& theData)
233      throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength, SALOMEDS::AttributeTableOfString::IncorrectIndex)
234 {
235   SALOMEDS::Locker lock;
236   Unexpect aCatch(ATS_IncorrectArgumentLength);
237   CheckLocked();
238   SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
239   
240   vector<string> aColumn;
241   for (int i = 0; i < theData.length(); i++) aColumn.push_back(string(CORBA::string_dup(theData[i])));
242   aTable->SetColumnData(theColumn, aColumn);
243 }
244
245 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfString_i::GetColumn(CORBA::Long theColumn)
246      throw (SALOMEDS::AttributeTableOfString::IncorrectIndex)
247 {
248   SALOMEDS::Locker lock;
249   Unexpect aCatch(ATS_IncorrectIndex);
250   SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
251   if (theColumn <= 0 || theColumn > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
252
253   SALOMEDS::StringSeq_var CorbaSeq = new SALOMEDS::StringSeq;
254   vector<string> aColumn = aTable->GetColumnData(theColumn);
255   CorbaSeq->length(aColumn.size());
256   for (int i = 0; i < aColumn.size(); i++) {
257     CorbaSeq[i] = CORBA::string_dup(aColumn[i].c_str());
258   }
259   return CorbaSeq._retn();
260 }
261
262 void SALOMEDS_AttributeTableOfString_i::PutValue(const char* theValue, CORBA::Long theRow, CORBA::Long theColumn)
263      throw (SALOMEDS::AttributeTableOfString::IncorrectIndex)
264 {
265   SALOMEDS::Locker lock;
266   Unexpect aCatch(ATS_IncorrectIndex);
267   CheckLocked();
268   SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
269   char* aValue = CORBA::string_dup(theValue);
270
271   aTable->PutValue(aValue, theRow, theColumn);
272 }
273
274 CORBA::Boolean SALOMEDS_AttributeTableOfString_i::HasValue(CORBA::Long theRow, CORBA::Long theColumn) 
275 {
276   SALOMEDS::Locker lock;
277   return dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl)->HasValue(theRow, theColumn);
278 }
279
280 char* SALOMEDS_AttributeTableOfString_i::GetValue(CORBA::Long theRow, CORBA::Long theColumn)
281      throw (SALOMEDS::AttributeTableOfString::IncorrectIndex)
282 {
283   SALOMEDS::Locker lock;
284   Unexpect aCatch(ATS_IncorrectIndex);
285   SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
286   if (theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
287
288   string aValue;
289   try {
290     aValue = aTable->GetValue(theRow, theColumn);
291   }
292   catch(...) {
293     throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
294   }
295
296   return CORBA::string_dup(aValue.c_str());
297 }
298
299
300 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfString_i::GetRowSetIndices(CORBA::Long theRow) 
301 {
302   SALOMEDS::Locker lock;
303   SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
304
305   if(theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex();
306
307   SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
308   vector<int> aSeq = aTable->GetSetRowIndices(theRow);
309   CorbaSeq->length(aSeq.size());
310   for (int i = 0; i < aSeq.size(); i++) {
311     CorbaSeq[i] = aSeq[i];
312   }
313   return CorbaSeq._retn(); 
314 }
315
316
317 void SALOMEDS_AttributeTableOfString_i::SetNbColumns(CORBA::Long theNbColumns)
318 {
319   SALOMEDS::Locker lock;
320   SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
321   aTable->SetNbColumns(theNbColumns);
322 }
323
324 bool SALOMEDS_AttributeTableOfString_i::ReadFromFile(const SALOMEDS::TMPFile& theStream) 
325 {
326   SALOMEDS::Locker lock;
327   SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
328
329   string aStream((char*)&theStream[0], theStream.length());
330   aTable->Load(aStream);
331   return true;
332 }
333
334 SALOMEDS::TMPFile*  SALOMEDS_AttributeTableOfString_i::SaveToFile()
335 {
336   SALOMEDS::Locker lock;
337   SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfString*>(_impl);
338
339  string aString = aTable->Save();
340   char* aBuffer = (char*)CORBA::string_dup(aString.c_str());
341   int aBufferSize = strlen((char*)aBuffer);
342
343   CORBA::Octet* anOctetBuf =  (CORBA::Octet*)aBuffer;
344
345   SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1);
346
347   return aStreamFile._retn();
348 }
349