-// Copyright (C) 2007-2019 CEA/DEN, EDF R&D
+// Copyright (C) 2007-2024 CEA, EDF
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-// Author : Anthony Geay (CEA/DEN)
+// Author : Anthony Geay (EDF R&D)
-#ifndef __MEDCOUPLINGTYPEMAPS_I__
-#define __MEDCOUPLINGTYPEMAPS_I__
+#pragma once
#include "MEDCouplingDataArrayTypemaps.i"
#include "MEDCouplingUMesh.hxx"
#include "MEDCouplingMappedExtrudedMesh.hxx"
#include "MEDCoupling1GTUMesh.hxx"
#include "MEDCouplingFieldDiscretization.hxx"
+#include "MEDCouplingFieldDiscretizationOnNodesFE.hxx"
#include "MEDCouplingMultiFields.hxx"
#include "MEDCouplingPartDefinition.hxx"
#include "MEDCouplingCartesianAMRMesh.hxx"
+#include <memory>
+
+auto PyDeleter = [](PyObject *ob) { Py_DECREF(ob) ; };
+
+namespace { // Only in this TU, so in an anonymous namespace
+ class AutoPyPtr : std::unique_ptr<PyObject,decltype(PyDeleter)>
+ {
+ public:
+ AutoPyPtr(PyObject *ob):std::unique_ptr<PyObject,decltype(PyDeleter)>(ob,PyDeleter) { }
+ PyObject *retn() { return this->release(); }
+ operator PyObject *() const { return this->get(); }
+ };
+}
+
+AutoPyPtr convertMapStringInt(const std::map<std::string,mcIdType>& cpp)
+{
+ AutoPyPtr ret(PyDict_New());
+ for(auto it : cpp)
+ {
+ AutoPyPtr st(PyString_FromString(it.first.c_str()));
+ AutoPyPtr val(PyInt_FromLong(it.second));
+ PyDict_SetItem(ret,st,val);
+ }
+ return ret;
+}
+
+AutoPyPtr convertMapStringVectString(const std::map<std::string,std::vector<std::string>>& cpp)
+{
+ AutoPyPtr ret(PyDict_New());
+ for(auto it : cpp)
+ {
+ AutoPyPtr st(PyString_FromString(it.first.c_str()));
+ AutoPyPtr vec(PyList_New(it.second.size()));
+ std::size_t itc(0);
+ for(auto it2 : it.second)
+ {
+ AutoPyPtr st2(PyString_FromString(it2.c_str()));
+ PyList_SetItem(vec,itc++,st2.retn());
+ }
+ PyDict_SetItem(ret,st,vec.retn());
+ }
+ return ret;
+}
+
static PyObject *convertMesh(MEDCoupling::MEDCouplingMesh *mesh, int owner)
{
PyObject *ret=0;
ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDiscretizationGaussNE,owner);
if(dynamic_cast<MEDCoupling::MEDCouplingFieldDiscretizationKriging *>(fd))
ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDiscretizationKriging,owner);
+ if(dynamic_cast<MEDCoupling::MEDCouplingFieldDiscretizationOnNodesFE *>(fd))
+ ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDiscretizationOnNodesFE,owner);
if(!ret)
throw INTERP_KERNEL::Exception("Not recognized type of field discretization on downcast !");
return ret;
}
if(dynamic_cast<MEDCoupling::MEDCouplingFieldDouble *>(f))
ret=SWIG_NewPointerObj(reinterpret_cast<void*>(f),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldDouble,owner);
- if(dynamic_cast<MEDCoupling::MEDCouplingFieldInt *>(f))
- ret=SWIG_NewPointerObj(reinterpret_cast<void*>(f),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldInt,owner);
+ if(dynamic_cast<MEDCoupling::MEDCouplingFieldInt32 *>(f))
+ ret=SWIG_NewPointerObj(reinterpret_cast<void*>(f),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldInt32,owner);
+ if(dynamic_cast<MEDCoupling::MEDCouplingFieldInt64 *>(f))
+ ret=SWIG_NewPointerObj(reinterpret_cast<void*>(f),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldInt64,owner);
if(dynamic_cast<MEDCoupling::MEDCouplingFieldFloat *>(f))
ret=SWIG_NewPointerObj(reinterpret_cast<void*>(f),SWIGTYPE_p_MEDCoupling__MEDCouplingFieldFloat,owner);
if(!ret)
PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(eltsIndex.retn()),SWIGTITraits<mcIdType>::TI, SWIG_POINTER_OWN | 0 ));
return ret;
}
-
-#endif