Salome HOME
Added @BOOST_CPPFLAGS@
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_AttributeTableOfInteger_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_AttributeTableOfInteger_i.cxx
21 //  Author : Sergey RUIN
22 //  Module : SALOME
23
24
25 #include "SALOMEDS_AttributeTableOfInteger_i.hxx"
26 #include "SALOMEDS.hxx"
27
28 #include "Utils_ExceptHandlers.hxx"
29
30 #include <stdexcept>
31 #include <strstream>
32 #include <string>
33 #include <vector>
34
35 using namespace std;
36
37 UNEXPECT_CATCH(ATI_IncorrectIndex, SALOMEDS::AttributeTableOfInteger::IncorrectIndex);
38 UNEXPECT_CATCH(ATI_IncorrectArgumentLength, SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength);
39
40 void SALOMEDS_AttributeTableOfInteger_i::SetTitle(const char* theTitle) 
41 {
42   SALOMEDS::Locker lock;
43   CheckLocked();
44   CORBA::String_var aStr = CORBA::string_dup(theTitle);
45   dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl)->SetTitle(string(aStr));
46 }
47
48 char* SALOMEDS_AttributeTableOfInteger_i::GetTitle() 
49 {
50   SALOMEDS::Locker lock;
51   SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
52   CORBA::String_var c_s = CORBA::string_dup(aTable->GetTitle().c_str());
53   return c_s._retn();
54 }
55
56 void SALOMEDS_AttributeTableOfInteger_i::SetRowTitle(CORBA::Long theIndex, const char* theTitle)
57      throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
58 {
59   SALOMEDS::Locker lock;
60   Unexpect aCatch (ATI_IncorrectIndex);
61   CheckLocked();
62   SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
63   if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
64   aTable->SetRowTitle(theIndex, string(theTitle));
65 }
66
67 void SALOMEDS_AttributeTableOfInteger_i::SetRowTitles(const SALOMEDS::StringSeq& theTitles)
68      throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
69 {
70   SALOMEDS::Locker lock;
71   Unexpect aCatch (ATI_IncorrectArgumentLength);
72   CheckLocked();
73   SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
74   if (theTitles.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
75   for (int i = 0; i < theTitles.length(); i++) {
76     SetRowTitle(i + 1, theTitles[i]);
77   }
78 }
79
80 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfInteger_i::GetRowTitles() 
81 {
82   SALOMEDS::Locker lock;
83   SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
84   SALOMEDS::StringSeq_var aTitles = new SALOMEDS::StringSeq;
85   aTitles->length(aTable->GetNbRows());
86   for(int i = 0; i < aTitles->length(); i++)
87     aTitles[i] = CORBA::string_dup(aTable->GetRowTitle(i + 1).c_str());
88   return aTitles._retn();
89 }
90
91 void SALOMEDS_AttributeTableOfInteger_i::SetColumnTitle(CORBA::Long theIndex, const char* theTitle)
92      throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
93 {
94   SALOMEDS::Locker lock;
95   Unexpect aCatch (ATI_IncorrectIndex);
96   CheckLocked();
97   SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
98   if (theIndex <= 0 || theIndex > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
99   CORBA::String_var aStr = CORBA::string_dup(theTitle);
100   aTable->SetColumnTitle(theIndex, string(aStr));
101 }
102
103 void SALOMEDS_AttributeTableOfInteger_i::SetColumnTitles(const SALOMEDS::StringSeq& theTitles)
104      throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
105 {
106   SALOMEDS::Locker lock;
107   Unexpect aCatch(ATI_IncorrectArgumentLength);
108   CheckLocked();
109   SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
110   if (theTitles.length() != aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
111   for (int i = 0; i < theTitles.length(); i++) {
112     aTable->SetColumnTitle(i + 1, (char*)theTitles[i].in());
113   }
114 }
115
116 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfInteger_i::GetColumnTitles() 
117 {
118   SALOMEDS::Locker lock;
119   SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_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_AttributeTableOfInteger_i::SetRowUnit(CORBA::Long theIndex, const char* theUnit)
129      throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
130 {
131   SALOMEDS::Locker lock;
132   Unexpect aCatch (ATI_IncorrectIndex);
133   CheckLocked();
134   SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
135   if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
136   aTable->SetRowUnit(theIndex, string(theUnit));
137 }
138
139 void SALOMEDS_AttributeTableOfInteger_i::SetRowUnits(const SALOMEDS::StringSeq& theUnits)
140      throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
141 {
142   SALOMEDS::Locker lock;
143   Unexpect aCatch (ATI_IncorrectArgumentLength);
144   CheckLocked();
145   SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
146   if (theUnits.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
147   for (int i = 0; i < theUnits.length(); i++) {
148     aTable->SetRowUnit(i + 1, (char*)theUnits[i].in());
149   }
150 }
151
152 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfInteger_i::GetRowUnits() 
153 {
154   SALOMEDS::Locker lock;
155   SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_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 CORBA::Long SALOMEDS_AttributeTableOfInteger_i::GetNbRows() 
164 {
165   SALOMEDS::Locker lock;
166   return dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl)->GetNbRows();
167 }
168
169 CORBA::Long SALOMEDS_AttributeTableOfInteger_i::GetNbColumns() 
170 {
171   SALOMEDS::Locker lock;
172   return dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl)->GetNbColumns();
173 }
174
175 void SALOMEDS_AttributeTableOfInteger_i::AddRow(const SALOMEDS::LongSeq& theData)
176      throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
177 {
178   SALOMEDS::Locker lock;
179   Unexpect aCatch(ATI_IncorrectArgumentLength);
180   CheckLocked();
181   SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
182   
183   vector<int> aRow;
184   for (int i = 0; i < theData.length(); i++) aRow.push_back(theData[i]);
185   try {
186     aTable->SetRowData(aTable->GetNbRows() + 1, aRow);
187   }
188   catch(...) {
189     throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
190   }
191 }
192
193 void SALOMEDS_AttributeTableOfInteger_i::SetRow(CORBA::Long theRow, const SALOMEDS::LongSeq& theData)
194      throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength, SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
195 {
196   SALOMEDS::Locker lock;
197   Unexpect aCatch(ATI_IncorrectArgumentLength);
198   CheckLocked();
199   SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
200   
201   vector<int> aRow;
202   for (int i = 0; i < theData.length(); i++) aRow.push_back(theData[i]);
203   try {
204     aTable->SetRowData(theRow, aRow);
205   }
206   catch(...) {
207     throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
208   }  
209 }
210
211 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfInteger_i::GetRow(CORBA::Long theRow)
212      throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
213 {
214   SALOMEDS::Locker lock;
215   Unexpect aCatch(ATI_IncorrectIndex);
216   SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
217   if (theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
218
219   SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
220   vector<int> aRow = aTable->GetRowData(theRow);
221   CorbaSeq->length(aRow.size());
222   for (int i = 0; i < aRow.size(); i++) {
223     CorbaSeq[i] = aRow[i];
224   }
225   return CorbaSeq._retn();
226 }
227
228 void SALOMEDS_AttributeTableOfInteger_i::AddColumn(const SALOMEDS::LongSeq& theData)
229      throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
230 {
231   SALOMEDS::Locker lock;
232   Unexpect aCatch(ATI_IncorrectArgumentLength);
233   CheckLocked();
234   SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
235   
236   vector<int> aColumn;
237   for (int i = 0; i < theData.length(); i++) aColumn.push_back(theData[i]);
238   try {
239     aTable->SetColumnData(aTable->GetNbColumns() + 1, aColumn);
240   }
241   catch(...) {
242     throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
243   }  
244 }
245
246 void SALOMEDS_AttributeTableOfInteger_i::SetColumn(CORBA::Long theColumn, const SALOMEDS::LongSeq& theData)
247      throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength, SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
248 {
249   SALOMEDS::Locker lock;
250   Unexpect aCatch(ATI_IncorrectArgumentLength);
251   CheckLocked();
252   SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
253
254   vector<int> aColumn; 
255   for (int i = 0; i < theData.length(); i++) aColumn.push_back(theData[i]);
256   try {
257     aTable->SetColumnData(theColumn, aColumn);
258   }
259   catch(...) {
260     throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
261   }
262 }
263
264 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfInteger_i::GetColumn(CORBA::Long theColumn)
265      throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
266 {
267   SALOMEDS::Locker lock;
268   Unexpect aCatch(ATI_IncorrectIndex);
269   SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
270   if (theColumn <= 0 || theColumn > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
271
272   SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
273   vector<int> aColumn = aTable->GetColumnData(theColumn);
274   CorbaSeq->length(aColumn.size());
275   for (int i = 0; i < aColumn.size(); i++) {
276     CorbaSeq[i] = aColumn[i];
277   }
278   return CorbaSeq._retn();
279 }
280
281 void SALOMEDS_AttributeTableOfInteger_i::PutValue(CORBA::Long theValue, CORBA::Long theRow, CORBA::Long theColumn)
282      throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
283 {
284   SALOMEDS::Locker lock;
285   Unexpect aCatch(ATI_IncorrectIndex);
286   CheckLocked();
287   SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
288
289   try {
290     aTable->PutValue(theValue, theRow, theColumn);
291   }
292   catch(...) {
293     throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
294   }
295 }
296
297 CORBA::Boolean SALOMEDS_AttributeTableOfInteger_i::HasValue(CORBA::Long theRow, CORBA::Long theColumn) 
298 {
299   SALOMEDS::Locker lock;
300   return dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl)->HasValue(theRow, theColumn);
301 }
302
303 CORBA::Long SALOMEDS_AttributeTableOfInteger_i::GetValue(CORBA::Long theRow, CORBA::Long theColumn)
304      throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
305 {
306   SALOMEDS::Locker lock;
307   Unexpect aCatch(ATI_IncorrectIndex);
308   SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
309   if (theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
310
311   CORBA::Long aValue;
312   try {
313     aValue = aTable->GetValue(theRow, theColumn);
314   }
315   catch(...) {
316     throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
317   }
318   return aValue;
319 }
320
321 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfInteger_i::GetRowSetIndices(CORBA::Long theRow) 
322 {
323   SALOMEDS::Locker lock;
324   SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
325
326   if(theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
327
328   SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
329   vector<int> aSeq = aTable->GetSetRowIndices(theRow);
330   CorbaSeq->length(aSeq.size());
331   for (int i = 0; i < aSeq.size(); i++) {
332     CorbaSeq[i] = aSeq[i];
333   }
334   return CorbaSeq._retn(); 
335 }
336
337
338 void SALOMEDS_AttributeTableOfInteger_i::SetNbColumns(CORBA::Long theNbColumns)
339 {
340   SALOMEDS::Locker lock;
341   SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
342   aTable->SetNbColumns(theNbColumns);
343 }
344
345 bool SALOMEDS_AttributeTableOfInteger_i::ReadFromFile(const SALOMEDS::TMPFile& theStream) 
346 {
347   SALOMEDS::Locker lock;
348   SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
349
350   string aStream((char*)&theStream[0], theStream.length());
351   aTable->Load(aStream);
352   return true;
353 }
354
355 SALOMEDS::TMPFile*  SALOMEDS_AttributeTableOfInteger_i::SaveToFile()
356 {
357   SALOMEDS::Locker lock;
358   SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfInteger*>(_impl);
359
360   string aString = aTable->Save();
361
362   char* aBuffer = (char*)CORBA::string_dup(aString.c_str());
363   int aBufferSize = strlen((char*)aBuffer);
364
365   CORBA::Octet* anOctetBuf =  (CORBA::Octet*)aBuffer;
366
367   SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1);
368
369   return aStreamFile._retn();
370 }
371
372