1 // Copyright (C) 2012-2021 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (EDF R&D)
21 #include "YACSEvalSeqAny.hxx"
22 #include "YACSEvalPort.hxx"
23 #include "Exception.hxx"
25 #include "PythonPorts.hxx"
27 YACSEvalSeqAny *YACSEvalSeqAny::BuildEmptyFromType(const std::string& dataType)
29 if(dataType==YACSEvalAnyDouble::TYPE_REPR)
30 return new YACSEvalSeqAnyDouble;
31 else if(dataType==YACSEvalAnyInt::TYPE_REPR)
32 return new YACSEvalSeqAnyInt;
34 throw YACS::Exception("YACSEvalSeqAny::BuildEmptyFromType : Only int and double are actualy managed !");
37 YACSEvalSeqAnyDouble::YACSEvalSeqAnyDouble(const std::vector<double>& arr):_arr(0)
39 std::vector<double> *zeArr(new std::vector<double>(arr));
40 _arr=YACSEvalSeqAnyInternal<double>::New(zeArr);
43 YACSEvalSeqAnyDouble::YACSEvalSeqAnyDouble(const YACSEvalSeqAnyDouble& other):_arr(other._arr)
49 YACSEvalSeqAnyDouble::YACSEvalSeqAnyDouble():_arr(YACSEvalSeqAnyInternal<double>::New(new std::vector<double>(0)))
53 std::string YACSEvalSeqAnyDouble::getTypeOfConstitutingElements() const
55 return std::string(YACSEvalAnyDouble::TYPE_REPR);
58 YACSEvalSeqAnyDouble *YACSEvalSeqAnyDouble::copy() const
60 return new YACSEvalSeqAnyDouble(*this);
63 void YACSEvalSeqAnyDouble::initialize(YACS::ENGINE::InputPyPort *p) const
65 std::size_t sz(size());
66 PyObject *ob(PyList_New(sz));
67 for(std::size_t i=0;i<sz;i++)
69 PyList_SetItem(ob,i,PyFloat_FromDouble((*_arr)[i]));
76 std::vector<double> *YACSEvalSeqAnyDouble::getInternal() const
79 throw YACS::Exception("YACSEvalSeqAnyDouble::getInternal : null internal ref !");
80 return _arr->getInternal();
83 YACSEvalSeqAnyInt::YACSEvalSeqAnyInt(const std::vector<int>& arr):_arr(0)
85 std::vector<int> *zeArr(new std::vector<int>(arr));
86 _arr=YACSEvalSeqAnyInternal<int>::New(zeArr);
89 YACSEvalSeqAnyInt::YACSEvalSeqAnyInt(const YACSEvalSeqAnyInt& other):_arr(other._arr)
95 YACSEvalSeqAnyInt::YACSEvalSeqAnyInt():_arr(YACSEvalSeqAnyInternal<int>::New(new std::vector<int>(0)))
99 std::string YACSEvalSeqAnyInt::getTypeOfConstitutingElements() const
101 return std::string(YACSEvalAnyInt::TYPE_REPR);
104 YACSEvalSeqAnyInt *YACSEvalSeqAnyInt::copy() const
106 return new YACSEvalSeqAnyInt(*this);
109 void YACSEvalSeqAnyInt::initialize(YACS::ENGINE::InputPyPort *p) const
111 std::size_t sz(size());
112 PyObject *ob(PyList_New(sz));
113 for(std::size_t i=0;i<sz;i++)
115 PyList_SetItem(ob,i,PyLong_FromLong((*_arr)[i]));
122 std::vector<int> *YACSEvalSeqAnyInt::getInternal() const
125 throw YACS::Exception("YACSEvalSeqAnyInt::getInternal : null internal ref !");
126 return _arr->getInternal();