Salome HOME
Issue 0020194: EDF 977 ALL: Get rid of warnings PACKAGE_VERSION already defined
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_AttributeTableOfReal.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  File   : SALOMEDS_AttributeTableOfReal.cxx
23 //  Author : Sergey RUIN
24 //  Module : SALOME
25 //
26 #include "SALOMEDS_AttributeTableOfReal.hxx"
27 #include "SALOMEDS.hxx"
28
29 using namespace std;
30
31 SALOMEDS_AttributeTableOfReal::SALOMEDS_AttributeTableOfReal
32                   (SALOMEDSImpl_AttributeTableOfReal* theAttr)
33 :SALOMEDS_GenericAttribute(theAttr)
34 {}
35
36 SALOMEDS_AttributeTableOfReal::SALOMEDS_AttributeTableOfReal(SALOMEDS::AttributeTableOfReal_ptr theAttr)
37 :SALOMEDS_GenericAttribute(theAttr)
38 {}
39
40 SALOMEDS_AttributeTableOfReal::~SALOMEDS_AttributeTableOfReal()
41 {}
42
43
44 void SALOMEDS_AttributeTableOfReal::SetTitle(const std::string& theTitle)
45 {
46   if (_isLocal) {
47     CheckLocked();
48     SALOMEDS::Locker lock;     
49     dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_local_impl)->SetTitle(theTitle);
50   }
51   else SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->SetTitle(theTitle.c_str());
52 }
53
54 std::string SALOMEDS_AttributeTableOfReal::GetTitle()
55 {
56   std::string aStr;
57   if (_isLocal) {
58     SALOMEDS::Locker lock; 
59     aStr = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_local_impl)->GetTitle();
60   }
61   else aStr = SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->GetTitle();
62   return aStr;
63 }
64
65 void SALOMEDS_AttributeTableOfReal::SetRowTitle(int theIndex, const std::string& theTitle)
66 {
67   if (_isLocal) {
68     CheckLocked();
69     SALOMEDS::Locker lock;     
70     dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_local_impl)->SetRowTitle(theIndex, theTitle);
71   }
72   else SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->SetRowTitle(theIndex, theTitle.c_str());
73 }
74
75 void SALOMEDS_AttributeTableOfReal::SetRowTitles(const std::vector<std::string>& theTitles)
76 {
77   CheckLocked();
78   int aLength = theTitles.size(), i;
79   if (_isLocal) {
80     CheckLocked();
81     SALOMEDS::Locker lock;     
82     dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_local_impl)->SetRowTitles(theTitles);
83   }
84   else {
85     SALOMEDS::StringSeq_var aSeq = new SALOMEDS::StringSeq();
86     aSeq->length(aLength);
87     for (i = 0; i < aLength; i++) aSeq[i] = (char*)theTitles[i].c_str();
88     SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->SetRowTitles(aSeq);
89   }
90 }
91
92 std::vector<std::string> SALOMEDS_AttributeTableOfReal::GetRowTitles()
93 {
94   std::vector<std::string> aVector;
95   int aLength, i;
96   if (_isLocal) {
97     SALOMEDS::Locker lock; 
98     aVector = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_local_impl)->GetRowTitles();
99   }
100   else {
101     SALOMEDS::StringSeq_var aSeq = SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->GetRowTitles();
102     aLength = aSeq->length();
103     for (i = 0; i < aLength; i++) aVector.push_back((char*)aSeq[i].in());
104   }
105   return aVector;
106 }
107
108 void SALOMEDS_AttributeTableOfReal::SetColumnTitle(int theIndex, const std::string& theTitle)
109 {
110   if (_isLocal) {
111     CheckLocked();
112     SALOMEDS::Locker lock; 
113     dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_local_impl)->SetColumnTitle(theIndex, theTitle);
114   }
115   else SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->SetColumnTitle(theIndex, theTitle.c_str());
116 }
117
118 void SALOMEDS_AttributeTableOfReal::SetColumnTitles(const std::vector<std::string>& theTitles)
119 {
120   int aLength = theTitles.size(), i;
121   if (_isLocal) {
122     CheckLocked();
123     SALOMEDS::Locker lock; 
124     dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_local_impl)->SetColumnTitles(theTitles);
125   }
126   else {
127     SALOMEDS::StringSeq_var aSeq = new SALOMEDS::StringSeq();
128     aSeq->length(aLength);
129     for (i = 0; i < aLength; i++) aSeq[i] = (char*)theTitles[i].c_str();
130     SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->SetColumnTitles(aSeq);
131   }
132 }
133
134 std::vector<std::string> SALOMEDS_AttributeTableOfReal::GetColumnTitles()
135 {
136   std::vector<std::string> aVector;
137   int aLength, i;
138   if (_isLocal) {
139     SALOMEDS::Locker lock; 
140     aVector = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_local_impl)->GetColumnTitles();
141   }
142   else {
143     SALOMEDS::StringSeq_var aSeq = SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->GetColumnTitles();
144     aLength = aSeq->length();
145     for (i = 0; i < aLength; i++) aVector.push_back((char*)aSeq[i].in());
146   }
147   return aVector;
148 }
149
150 void SALOMEDS_AttributeTableOfReal::SetRowUnit(int theIndex, const std::string& theUnit)
151 {
152   if (_isLocal) {
153     CheckLocked();
154     SALOMEDS::Locker lock; 
155     dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_local_impl)->SetRowUnit(theIndex, theUnit);
156   }
157   else SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->SetRowUnit(theIndex, theUnit.c_str());
158 }
159
160 void SALOMEDS_AttributeTableOfReal::SetRowUnits(const std::vector<std::string>& theUnits)
161 {
162   int aLength = theUnits.size(), i;
163   if (_isLocal) {
164     CheckLocked();
165     SALOMEDS::Locker lock; 
166     dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_local_impl)->SetRowUnits(theUnits);
167   }
168   else {
169     SALOMEDS::StringSeq_var aSeq = new SALOMEDS::StringSeq();
170     aSeq->length(aLength);
171     for (i = 0; i < aLength; i++) aSeq[i] = (char*)theUnits[i].c_str();
172     SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->SetRowUnits(aSeq);
173   }
174 }
175
176 std::vector<std::string> SALOMEDS_AttributeTableOfReal::GetRowUnits()
177 {
178   std::vector<std::string> aVector;
179   int aLength, i;
180   if (_isLocal) {
181     SALOMEDS::Locker lock; 
182     aVector = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_local_impl)->GetRowUnits();
183   }
184   else {
185     SALOMEDS::StringSeq_var aSeq = SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->GetRowUnits();
186     aLength = aSeq->length();
187     for (i = 0; i < aLength; i++) aVector.push_back(string(aSeq[i].in()));
188   }
189   return aVector;
190 }
191
192 int SALOMEDS_AttributeTableOfReal::GetNbRows()
193 {
194   int aNb;
195   if (_isLocal) {
196     SALOMEDS::Locker lock; 
197     aNb = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_local_impl)->GetNbRows();
198   }
199   else aNb = SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->GetNbRows();
200   return aNb;
201 }
202
203 int SALOMEDS_AttributeTableOfReal::GetNbColumns()
204 {  
205   int aNb;
206   if (_isLocal) {
207     SALOMEDS::Locker lock; 
208     aNb = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_local_impl)->GetNbColumns();
209   }
210   else aNb = SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->GetNbColumns();
211   return aNb;
212 }
213
214 void SALOMEDS_AttributeTableOfReal::AddRow(const std::vector<double>& theData)
215 {
216   int aLength = theData.size(), i;
217   if (_isLocal) {
218     CheckLocked();
219     SALOMEDS::Locker lock; 
220     SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_local_impl);
221     try {
222       aTable->SetRowData(aTable->GetNbRows() + 1, theData);
223     }   
224     catch(...) {
225       throw SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength();
226     }
227   }
228   else {
229     SALOMEDS::DoubleSeq_var aSeq = new SALOMEDS::DoubleSeq();
230     aSeq->length(aLength);
231     for (i = 0; i < aLength; i++) aSeq[i] = theData[i];
232     SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->AddRow(aSeq);
233   }
234 }
235
236 void SALOMEDS_AttributeTableOfReal::SetRow(int theRow, const std::vector<double>& theData)
237 {
238   int aLength = theData.size(), i;
239   if (_isLocal) {
240     CheckLocked();
241     SALOMEDS::Locker lock; 
242     SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_local_impl);
243     try {
244       aTable->SetRowData(theRow, theData);
245     }   
246     catch(...) {
247       throw SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength();
248     }
249   }
250   else {
251     SALOMEDS::DoubleSeq_var aSeq = new SALOMEDS::DoubleSeq();
252     aSeq->length(aLength);
253     for (i = 0; i < aLength; i++) aSeq[i] = theData[i];
254     SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->SetRow(theRow, aSeq);
255   }
256 }
257
258 std::vector<double> SALOMEDS_AttributeTableOfReal::GetRow(int theRow)
259 {
260   std::vector<double> aVector;
261   int aLength, i;
262   if (_isLocal) {
263     SALOMEDS::Locker lock; 
264     aVector = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_local_impl)->GetRowData(theRow);
265   }
266   else {
267     SALOMEDS::DoubleSeq_var aRow = SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->GetRow(theRow);
268     aLength = aRow->length();
269     for (i = 0; i < aLength; i++) aVector.push_back(aRow[i]);
270   }
271
272   return aVector;
273 }
274
275 void SALOMEDS_AttributeTableOfReal::AddColumn(const std::vector<double>& theData)
276 {
277   int aLength = theData.size(), i;
278   if (_isLocal) {
279     CheckLocked();
280     SALOMEDS::Locker lock; 
281     SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_local_impl);
282     try {
283       aTable->SetColumnData(aTable->GetNbColumns() + 1, theData);
284     }   
285     catch(...) {
286       throw SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength();
287     }
288   }
289   else {
290     SALOMEDS::DoubleSeq_var aColumn = new SALOMEDS::DoubleSeq();
291     aColumn->length(aLength);
292     for (i = 0; i < aLength; i++) aColumn[i] = theData[i];
293     SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->AddColumn(aColumn);
294   }
295 }
296
297 void SALOMEDS_AttributeTableOfReal::SetColumn(int theColumn, const std::vector<double>& theData)
298 {
299   int aLength = theData.size(), i;
300   if (_isLocal) {
301     CheckLocked();
302     SALOMEDS::Locker lock; 
303     SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_local_impl);
304     try {
305       aTable->SetColumnData(theColumn, theData);
306     }   
307     catch(...) {
308       throw SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength();
309     }
310   }
311   else {
312     SALOMEDS::DoubleSeq_var aColumn = new SALOMEDS::DoubleSeq();
313     aColumn->length(aLength);
314     for (i = 0; i < aLength; i++) aColumn[i] = theData[i];
315     SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->SetColumn(theColumn, aColumn);
316   }
317 }
318
319 std::vector<double> SALOMEDS_AttributeTableOfReal::GetColumn(int theColumn)
320 {
321   std::vector<double> aVector;
322   int aLength, i;
323   if (_isLocal) {
324     SALOMEDS::Locker lock; 
325     aVector = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_local_impl)->GetColumnData(theColumn);
326   }
327   else {
328     SALOMEDS::DoubleSeq_var aColumn = SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->GetColumn(theColumn);
329     aLength = aColumn->length();
330     for (i = 0; i < aLength; i++) aVector.push_back(aColumn[i]);
331   }
332   return aVector;
333 }
334
335 void SALOMEDS_AttributeTableOfReal::PutValue(double theValue, int theRow, int theColumn)
336 {
337   if (_isLocal) {
338     CheckLocked();
339     SALOMEDS::Locker lock; 
340     try {
341       dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_local_impl)->PutValue(theValue, theRow, theColumn);
342     }   
343     catch(...) {
344       throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
345     }
346   }
347   else {
348     SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->PutValue(theValue, theRow, theColumn);
349   }
350 }
351
352 bool SALOMEDS_AttributeTableOfReal::HasValue(int theRow, int theColumn)
353 {
354   bool ret;
355   if (_isLocal) {
356     SALOMEDS::Locker lock; 
357     ret = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_local_impl)->HasValue(theRow, theColumn);
358   }
359   else ret = SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->HasValue(theRow, theColumn);
360   return ret;
361 }
362
363 double SALOMEDS_AttributeTableOfReal::GetValue(int theRow, int theColumn)
364 {
365   double aValue;
366   if (_isLocal) {
367     SALOMEDS::Locker lock; 
368     try {
369       aValue = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_local_impl)->GetValue(theRow, theColumn);
370     }   
371     catch(...) {
372       throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
373     }
374   }
375   else {
376     aValue = SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->GetValue(theRow, theColumn);
377   }
378   return aValue;
379 }
380
381 std::vector<int> SALOMEDS_AttributeTableOfReal::GetRowSetIndices(int theRow)
382 {
383   std::vector<int> aVector;
384   int aLength, i;
385   if (_isLocal) {
386     SALOMEDS::Locker lock; 
387     aVector = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_local_impl)->GetSetRowIndices(theRow);
388   }
389   else {
390     SALOMEDS::LongSeq_var aSet = SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->GetRowSetIndices(theRow);
391     aLength = aSet->length();
392     for (i = 0; i < aLength; i++) aVector.push_back(aSet[i]);
393   }
394   return aVector;
395 }
396
397 void SALOMEDS_AttributeTableOfReal::SetNbColumns(int theNbColumns)
398 {
399   if (_isLocal) {
400     SALOMEDS::Locker lock; 
401     dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_local_impl)->SetNbColumns(theNbColumns);
402   }
403   else SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->SetNbColumns(theNbColumns);
404 }