From 98d9c16365d7bcabac0613c5174079fe51123287 Mon Sep 17 00:00:00 2001 From: Florent Lamiraux <florent@laas.fr> Date: Sun, 11 Dec 2011 13:52:39 +0100 Subject: [PATCH] Add python binding for writing graph. --- src/CMakeLists.txt | 1 + src/dynamic-graph-py.cc | 11 +++++++++-- src/pool-py.cc | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 src/pool-py.cc diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 13ebdb3..62fdc65 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 0303fa7..e49f5ed 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 0000000..a879f96 --- /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 -- GitLab