1 // Copyright (C) 2012-2016 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 !");
38 std::size_t YACSEvalSeqAnyInternal<T>::size() const
41 throw YACS::Exception("YACSEvalSeqAnyDouble<T>::size : empty array !");
45 YACSEvalSeqAnyDouble::YACSEvalSeqAnyDouble(const std::vector<double>& arr):_arr(0)
47 std::vector<double> *zeArr(new std::vector<double>(arr));
48 _arr=YACSEvalSeqAnyInternal<double>::New(zeArr);
51 YACSEvalSeqAnyDouble::YACSEvalSeqAnyDouble(const YACSEvalSeqAnyDouble& other):_arr(other._arr)
57 YACSEvalSeqAnyDouble::YACSEvalSeqAnyDouble():_arr(YACSEvalSeqAnyInternal<double>::New(new std::vector<double>(0)))
61 std::string YACSEvalSeqAnyDouble::getTypeOfConstitutingElements() const
63 return std::string(YACSEvalAnyDouble::TYPE_REPR);
66 YACSEvalSeqAnyDouble *YACSEvalSeqAnyDouble::copy() const
68 return new YACSEvalSeqAnyDouble(*this);
71 void YACSEvalSeqAnyDouble::initialize(YACS::ENGINE::InputPyPort *p) const
73 std::size_t sz(size());
74 PyObject *ob(PyList_New(sz));
75 for(std::size_t i=0;i<sz;i++)
77 PyList_SetItem(ob,i,PyFloat_FromDouble((*_arr)[i]));
84 std::vector<double> *YACSEvalSeqAnyDouble::getInternal() const
87 throw YACS::Exception("YACSEvalSeqAnyDouble::getInternal : null internal ref !");
88 return _arr->getInternal();
91 YACSEvalSeqAnyInt::YACSEvalSeqAnyInt(const std::vector<int>& arr):_arr(0)
93 std::vector<int> *zeArr(new std::vector<int>(arr));
94 _arr=YACSEvalSeqAnyInternal<int>::New(zeArr);
97 YACSEvalSeqAnyInt::YACSEvalSeqAnyInt(const YACSEvalSeqAnyInt& other):_arr(other._arr)
103 YACSEvalSeqAnyInt::YACSEvalSeqAnyInt():_arr(YACSEvalSeqAnyInternal<int>::New(new std::vector<int>(0)))
107 std::string YACSEvalSeqAnyInt::getTypeOfConstitutingElements() const
109 return std::string(YACSEvalAnyInt::TYPE_REPR);
112 YACSEvalSeqAnyInt *YACSEvalSeqAnyInt::copy() const
114 return new YACSEvalSeqAnyInt(*this);
117 void YACSEvalSeqAnyInt::initialize(YACS::ENGINE::InputPyPort *p) const
119 std::size_t sz(size());
120 PyObject *ob(PyList_New(sz));
121 for(std::size_t i=0;i<sz;i++)
123 PyList_SetItem(ob,i,PyInt_FromLong((*_arr)[i]));
130 std::vector<int> *YACSEvalSeqAnyInt::getInternal() const
133 throw YACS::Exception("YACSEvalSeqAnyInt::getInternal : null internal ref !");
134 return _arr->getInternal();