Salome HOME
[EDF15946] bug with playground when nb of cores is small
[modules/yacs.git] / src / engine_swig / engtypemaps.i
index 08f92a8564d13b8d784396359b11d61a8c6ae555..d31e8870f6b3027d607f89bf15d92fd4d62e080b 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2006-2012  CEA/DEN, EDF R&D
+// Copyright (C) 2006-2016  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.
+// 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
@@ -80,6 +80,9 @@ catch (const CORBA::SystemException& ex) { \
 #include "InputDataStreamPort.hxx"
 #include "OutputDataStreamPort.hxx"
 #include "OptimizerLoop.hxx"
+#include "HomogeneousPoolContainer.hxx"
+
+#include <sstream>
 
 class InterpreterUnlocker
 {
@@ -205,6 +208,66 @@ static PyObject* convertPort(YACS::ENGINE::Port* port,int owner=0)
   return ob;
 }
 
+static PyObject *convertContainer(YACS::ENGINE::Container *cont, int owner=0)
+{
+  if(!cont)
+    return SWIG_NewPointerObj((void*)cont,SWIGTYPE_p_YACS__ENGINE__Container, owner);
+  if(dynamic_cast<YACS::ENGINE::HomogeneousPoolContainer *>(cont))
+    {
+      return SWIG_NewPointerObj((void*)dynamic_cast<YACS::ENGINE::HomogeneousPoolContainer *>(cont),SWIGTYPE_p_YACS__ENGINE__HomogeneousPoolContainer, owner);
+    }
+  return SWIG_NewPointerObj((void*)cont,SWIGTYPE_p_YACS__ENGINE__Container, owner);
+}
+
+//convertFromPyObjVectorOfObj<YACS::ENGINE::SequenceAny *>(pyLi,SWIGTYPE_p_YACS__ENGINE__SequenceAny,"SequenceAny")
+template<class T>
+static void convertFromPyObjVectorOfObj(PyObject *pyLi, swig_type_info *ty, const char *typeStr, typename std::vector<T>& ret)
+{
+  void *argp=0;
+  if(PyList_Check(pyLi))
+    {
+      int size=PyList_Size(pyLi);
+      ret.resize(size);
+      for(int i=0;i<size;i++)
+        {
+          PyObject *obj=PyList_GetItem(pyLi,i);
+          int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
+          if(!SWIG_IsOK(status))
+            {
+              std::ostringstream oss; oss << "convertFromPyObjVectorOfObj : list is excepted to contain only " << typeStr << " instances !";
+              throw YACS::Exception(oss.str());
+            }
+          T arg=reinterpret_cast< T >(argp);
+          ret[i]=arg;
+        }
+    }
+  else if(PyTuple_Check(pyLi))
+    {
+      int size=PyTuple_Size(pyLi);
+      ret.resize(size);
+      for(int i=0;i<size;i++)
+        {
+          PyObject *obj=PyTuple_GetItem(pyLi,i);
+          int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
+          if(!SWIG_IsOK(status))
+            {
+              std::ostringstream oss; oss << "convertFromPyObjVectorOfObj : tuple is excepted to contain only " << typeStr << " instances !";
+              throw YACS::Exception(oss.str());
+            }
+          T arg=reinterpret_cast< T >(argp);
+          ret[i]=arg;
+        }
+    }
+  else if(SWIG_IsOK(SWIG_ConvertPtr(pyLi,&argp,ty,0|0)))
+    {
+      ret.resize(1);
+      T arg=reinterpret_cast< T >(argp);
+      ret[0]=arg;
+    }
+  else
+    throw YACS::Exception("convertFromPyObjVectorOfObj : not a list nor a tuple");
+}
+
 %}
 
 #if SWIG_VERSION >= 0x010329