factory-py.cc 1002 Bytes
Newer Older
Thomas Moulard's avatar
Thomas Moulard committed
1
// Copyright 2010, Florent Lamiraux, Thomas Moulard, LAAS-CNRS.
florent's avatar
florent committed
2
3
4
5
6
7
8
9
10

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

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

namespace dynamicgraph {
Guilhem Saurel's avatar
format    
Guilhem Saurel committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
namespace python {

namespace factory {

/**
   \brief Get name of entity
*/
PyObject* getEntityClassList(PyObject* /*self*/, PyObject* args) {
  if (!PyArg_ParseTuple(args, "")) return NULL;

  std::vector<std::string> classNames;
  dynamicgraph::FactoryStorage::getInstance()->listEntities(classNames);

  Py_ssize_t classNumber = classNames.size();
  // Build a tuple object
  PyObject* classTuple = PyTuple_New(classNumber);

  for (Py_ssize_t iEntity = 0; iEntity < (Py_ssize_t)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