Salome HOME
SWIG : Looking for a fix of REFCOUNT_TEMPLATE swigging...
authorNicolas Geimer <nicolas.geimer@edf.fr>
Wed, 4 Oct 2017 12:10:26 +0000 (14:10 +0200)
committerNicolas Geimer <nicolas.geimer@edf.fr>
Wed, 4 Oct 2017 12:10:26 +0000 (14:10 +0200)
src/engine_swig/IteratorPy3.hxx [new file with mode: 0644]
src/engine_swig/engtypemaps.i
src/engine_swig/pilot.i

diff --git a/src/engine_swig/IteratorPy3.hxx b/src/engine_swig/IteratorPy3.hxx
new file mode 100644 (file)
index 0000000..dd480df
--- /dev/null
@@ -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 <typename U> class StopIterator {};
+template <typename U> class Iterator {
+    public:
+        Iterator( typename std::map<std::string,U*>::iterator _cur, typename std::map<std::string,U*>::iterator _end) : cur(_cur), end(_end) {}
+        Iterator* __iter__()
+        {
+            return this;
+        }
+        typename std::map<std::string,U*>::iterator cur;
+        typename std::map<std::string,U*>::iterator end;
+};
+
+#endif /* ITERATORPY3_HXX */
+
index 1ed0ee20fbd1265038e0e264325d7e58ee9d1a6f..0d1675b333117ca234940b16336963e98d9a002d 100644 (file)
@@ -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 <typename U> class StopIterator {};
-template <typename U> class Iterator {
-  public:
-    Iterator(std::map<std::string,U*>::iterator _cur, std::map<std::string,U*>::iterator _end) : cur(_cur), end(_end) {}
-    Iterator* __iter__()
-    {
-      return this;
-    }
-    template <typename U> std::map<std::string,U*>::iterator cur;
-    template <typename U> std::map<std::string,U*>::iterator end;
-  };
-%}
 
 %include "exception.i"
 %exception Iterator::next {
@@ -882,7 +868,7 @@ template <typename U> class Iterator {
     throw StopIterator();
   }
 }
-*/
+
 template<>
 class std::map<std::string,T*>
 {
@@ -931,12 +917,12 @@ public:
       }
       return keyList;
     }
-/*  Iterator __iter__()
+  Iterator<T> __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<std::string,T* >::__getitem__;
+%newobject std::map<std::string,T* >::__iter__;
 %template()   std::pair<std::string, T* >;
 %template(tname)    std::map<std::string, T* >;
 %pythoncode{
index d760c97d7609b6f63a02a9c44a04c7d42eeb903b..c79d4909c681d4e6f3995fbceee4a822e6e7eb3b 100644 (file)
@@ -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<YACS::ENGINE::OutPort *,YACS::ENGINE::InPort *>;
 %template()              std::pair<YACS::ENGINE::InPort *,YACS::ENGINE::OutPort *>;
 %template()              std::pair< std::string, int >;
+%template()              Iterator<YACS::ENGINE::TypeCode *>;
 //%template(TCmap)         std::map<std::string, YACS::ENGINE::TypeCode *>;
 REFCOUNT_TEMPLATE(TCmap,YACS::ENGINE::TypeCode)
 %template(NODEmap)       std::map<std::string, YACS::ENGINE::Node *>;
 %template(INODEmap)      std::map<std::string, YACS::ENGINE::InlineNode *>;
 %template(SNODEmap)      std::map<std::string, YACS::ENGINE::ServiceNode *>;
 //%template(CONTAINmap)    std::map<std::string, YACS::ENGINE::Container *>;
+%template()              Iterator<YACS::ENGINE::Container * >;
 REFCOUNT_TEMPLATE(CONTAINmap,YACS::ENGINE::Container)
 %template(strvec)        std::vector<std::string>;
 %template(uivec)         std::vector<unsigned int>;
@@ -130,7 +133,7 @@ REFCOUNT_TEMPLATE(CONTAINmap,YACS::ENGINE::Container)
 %template(compomap)      std::map<std::string, YACS::ENGINE::ComponentDefinition *>;
 %template()              std::pair<std::string, std::string>;
 %template(propmap)       std::map<std::string, std::string>;
-
+%template()              Iterator<YACS::ENGINE::ComponentInstance *>;
 REFCOUNT_TEMPLATE(CompoInstmap,YACS::ENGINE::ComponentInstance)
 
 /*