From: Nicolas Geimer Date: Wed, 4 Oct 2017 12:10:26 +0000 (+0200) Subject: SWIG : Looking for a fix of REFCOUNT_TEMPLATE swigging... X-Git-Tag: V9_0_0~9 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=de244d056e0a0a2d7fa0284a16c5a973d73ac620;hp=9cc7ec32c0e279567ed811e3645f6ba4bb012a7e;p=modules%2Fyacs.git SWIG : Looking for a fix of REFCOUNT_TEMPLATE swigging... --- diff --git a/src/engine_swig/IteratorPy3.hxx b/src/engine_swig/IteratorPy3.hxx new file mode 100644 index 000000000..dd480dfda --- /dev/null +++ b/src/engine_swig/IteratorPy3.hxx @@ -0,0 +1,37 @@ +// Copyright (C) 2006-2017 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// Author: Nicolas GEIMER (EDF) + +#ifndef ITERATORPY3_HXX_ +#define ITERATORPY3_HXX_ + +template class StopIterator {}; +template class Iterator { + public: + Iterator( typename std::map::iterator _cur, typename std::map::iterator _end) : cur(_cur), end(_end) {} + Iterator* __iter__() + { + return this; + } + typename std::map::iterator cur; + typename std::map::iterator end; +}; + +#endif /* ITERATORPY3_HXX */ + diff --git a/src/engine_swig/engtypemaps.i b/src/engine_swig/engtypemaps.i index 1ed0ee20f..0d1675b33 100644 --- a/src/engine_swig/engtypemaps.i +++ b/src/engine_swig/engtypemaps.i @@ -841,20 +841,6 @@ static void convertFromPyObjVectorOfObj(PyObject *pyLi, swig_type_info *ty, cons Objects returned by __getitem__ are declared new (%newobject) so that when destroyed they call decrRef (see feature("unref") for RefCounter). */ -/* -%inline %{ -template class StopIterator {}; -template class Iterator { - public: - Iterator(std::map::iterator _cur, std::map::iterator _end) : cur(_cur), end(_end) {} - Iterator* __iter__() - { - return this; - } - template std::map::iterator cur; - template std::map::iterator end; - }; -%} %include "exception.i" %exception Iterator::next { @@ -882,7 +868,7 @@ template class Iterator { throw StopIterator(); } } -*/ + template<> class std::map { @@ -931,12 +917,12 @@ public: } return keyList; } -/* Iterator __iter__() + Iterator __iter__() { // return a constructed Iterator object - return Iterator($self->begin(), $self->end()); + return typename Iterator($self->begin(), $self->end()); } -*/ + int __len__() { int pysize = self->size(); @@ -944,8 +930,9 @@ public: } } }; - +%rename(__next__) Iterator::next; %newobject std::map::__getitem__; +%newobject std::map::__iter__; %template() std::pair; %template(tname) std::map; %pythoncode{ diff --git a/src/engine_swig/pilot.i b/src/engine_swig/pilot.i index d760c97d7..c79d4909c 100644 --- a/src/engine_swig/pilot.i +++ b/src/engine_swig/pilot.i @@ -59,6 +59,7 @@ #include "ComponentInstance.hxx" #include "DataNode.hxx" #include "PlayGround.hxx" +#include "IteratorPy3.hxx" using namespace YACS::ENGINE; @@ -106,12 +107,14 @@ using namespace YACS::ENGINE; %template() std::pair; %template() std::pair; %template() std::pair< std::string, int >; +%template() Iterator; //%template(TCmap) std::map; REFCOUNT_TEMPLATE(TCmap,YACS::ENGINE::TypeCode) %template(NODEmap) std::map; %template(INODEmap) std::map; %template(SNODEmap) std::map; //%template(CONTAINmap) std::map; +%template() Iterator; REFCOUNT_TEMPLATE(CONTAINmap,YACS::ENGINE::Container) %template(strvec) std::vector; %template(uivec) std::vector; @@ -130,7 +133,7 @@ REFCOUNT_TEMPLATE(CONTAINmap,YACS::ENGINE::Container) %template(compomap) std::map; %template() std::pair; %template(propmap) std::map; - +%template() Iterator; REFCOUNT_TEMPLATE(CompoInstmap,YACS::ENGINE::ComponentInstance) /*