diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 13ebdb31e8e4c51fa7694b3b9fb48535843714d8..62fdc65b894795e18e4640583796c240f97eaad8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -77,6 +77,7 @@ ADD_LIBRARY(${PYTHON_MODULE} signal-base-py.cc entity-py.cc factory-py.cc + pool-py.cc signal-caster-py.cc ) diff --git a/src/dynamic-graph-py.cc b/src/dynamic-graph-py.cc index 0303fa72528fa7b92847d91651dfdb49be34bed2..e49f5ed01efba3703498731a924dfd5e3fbdefe5 100644 --- a/src/dynamic-graph-py.cc +++ b/src/dynamic-graph-py.cc @@ -51,10 +51,13 @@ namespace dynamicgraph { } namespace factory { - PyObject* getEntityClassList(PyObject* self, PyObject* args); + extern PyObject* getEntityClassList(PyObject* self, PyObject* args); } namespace signalCaster { - PyObject* getSignalTypeList(PyObject* self, PyObject* args); + extern PyObject* getSignalTypeList(PyObject* self, PyObject* args); + } + namespace pool { + extern PyObject* writeGraph (PyObject* self, PyObject* args); } PyObject* dgpyError; @@ -198,6 +201,10 @@ static PyMethodDef dynamicGraphMethods[] = { dynamicgraph::python::signalCaster::getSignalTypeList, METH_VARARGS, "return the list of signal type names"}, + {"writeGraph", + dynamicgraph::python::pool::writeGraph, + METH_VARARGS, + "Write the graph of entities in a filename."}, {NULL, NULL, 0, NULL} /* Sentinel */ }; diff --git a/src/pool-py.cc b/src/pool-py.cc new file mode 100644 index 0000000000000000000000000000000000000000..a879f9626a9bb727076ecbd94137049ea1a43f27 --- /dev/null +++ b/src/pool-py.cc @@ -0,0 +1,39 @@ +// Copyright 2011, 2012, Florent Lamiraux, LAAS-CNRS. +// +// This file is part of dynamic-graph-python. +// dynamic-graph-python 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 3 of the License, or (at your option) any later version. +// +// dynamic-graph-python 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 General Lesser Public License for more details. You should +// have received a copy of the GNU Lesser General Public License along +// with dynamic-graph. If not, see <http://www.gnu.org/licenses/>. + +#include <Python.h> +#include <dynamic-graph/pool.h> + +namespace dynamicgraph { + namespace python { + + extern PyObject* dgpyError; + namespace pool { + PyObject* writeGraph (PyObject* /*self*/, PyObject* args) + { + char* filename; + if (!PyArg_ParseTuple(args, "s", &filename)) + return NULL; + try { + PoolStorage::getInstance()->writeGraph (filename); + } catch (const std::exception& exc) { + PyErr_SetString(dgpyError, exc.what()); + return NULL; + } + return Py_BuildValue (""); + } + } // python + } // dynamicgraph +} // namespace pool