Skip to content
Snippets Groups Projects
Commit 73796538 authored by florent's avatar florent
Browse files

Use factory to create entities.

    * src/dynamic_graph/entity.py,
    * src/entity-py.cc: the name of the entity class to be created is now given
      as input to the constructor of Entity python class.
parent 9a3f57de
No related branches found
No related tags found
No related merge requests found
...@@ -12,13 +12,12 @@ class Entity (object) : ...@@ -12,13 +12,12 @@ class Entity (object) :
object = None object = None
def __init__(self, name): def __init__(self, className, instanceName):
""" """
Constructor: if not called by a child class, create and store a pointer Constructor: if not called by a child class, create and store a pointer
to a C++ Entity object. to a C++ Entity object.
""" """
if not self.object : self.object = wrap.create_entity(className, instanceName)
self.object = wrap.create_entity(self, name)
@property @property
def name(self) : def name(self) :
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
//#include <string> //#include <string>
#include <dynamic-graph/entity.h> #include <dynamic-graph/entity.h>
#include <dynamic-graph/factory.h>
using dynamicgraph::Entity; using dynamicgraph::Entity;
using dynamicgraph::SignalBase; using dynamicgraph::SignalBase;
...@@ -27,14 +28,16 @@ namespace dynamicgraph { ...@@ -27,14 +28,16 @@ namespace dynamicgraph {
*/ */
PyObject* create(PyObject* self, PyObject* args) PyObject* create(PyObject* self, PyObject* args)
{ {
char *name = NULL; char *className = NULL;
char *instanceName = NULL;
if (!PyArg_ParseTuple(args, "s", &name)) if (!PyArg_ParseTuple(args, "ss", &className, &instanceName))
return NULL; return NULL;
Entity* obj = NULL; Entity* obj = NULL;
try { try {
obj = new Entity(name); obj = dynamicgraph::g_factory.newEntity(std::string(className),
std::string(instanceName));
} catch (dynamicgraph::ExceptionFactory& exc) { } catch (dynamicgraph::ExceptionFactory& exc) {
PyErr_SetString(error, exc.getStringMessage().c_str()); PyErr_SetString(error, exc.getStringMessage().c_str());
return NULL; return NULL;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment