factory-py.cc 1.7 KB
Newer Older
Thomas Moulard's avatar
Thomas Moulard committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// Copyright 2010, Florent Lamiraux, Thomas Moulard, 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/>.
florent's avatar
florent committed
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

#include <Python.h>
#include <iostream>
#include <dynamic-graph/factory.h>

using dynamicgraph::Entity;
using dynamicgraph::ExceptionAbstract;

namespace dynamicgraph {
  namespace python {

    namespace factory {

      /**
	 \brief Get name of entity
      */
Thomas Moulard's avatar
Thomas Moulard committed
31
      PyObject* getEntityClassList(PyObject* /*self*/, PyObject* args)
florent's avatar
florent committed
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
      {
	if (!PyArg_ParseTuple(args, ""))
	  return NULL;

	std::vector <std::string> classNames;
	dynamicgraph::g_factory.listEntities(classNames);
	unsigned int classNumber = classNames.size();
	// Build a tuple object
	PyObject* classTuple = PyTuple_New(classNumber);
	
	for (unsigned int iEntity = 0; iEntity < classNames.size(); iEntity++) {
	  PyObject* className = Py_BuildValue("s", classNames[iEntity].c_str());
	  PyTuple_SetItem(classTuple, iEntity, className);
	}

	return Py_BuildValue("O", classTuple);
      }
      
    } // namespace factory
  } // namespace python
} // namespace dynamicgraph