Skip to content
Snippets Groups Projects
Commit 4562d981 authored by Nicolas Mansard's avatar Nicolas Mansard Committed by Nicolas Mansard
Browse files

Changed the call to create_entity: when the required creation names already...

Changed the call to create_entity: when the required creation names already exists, check is the existing object is of the same class. If it is, returns the existing object instead of creating a new oine.
parent cd72626d
No related branches found
No related tags found
No related merge requests found
......@@ -20,8 +20,9 @@
#include <dynamic-graph/factory.h>
#include <../src/convert-dg-to-py.hh>
#include "dynamic-graph/command.h"
#include "dynamic-graph/value.h"
#include <dynamic-graph/command.h>
#include <dynamic-graph/value.h>
#include <dynamic-graph/pool.h>
using dynamicgraph::Entity;
using dynamicgraph::SignalBase;
......@@ -51,13 +52,23 @@ namespace dynamicgraph {
return NULL;
Entity* obj = NULL;
try {
obj = dynamicgraph::g_factory.newEntity(std::string(className),
std::string(instanceName));
} catch (std::exception& exc) {
PyErr_SetString(error, exc.what());
return NULL;
}
/* Try to find if the corresponding object already exists. */
if( dynamicgraph::g_pool.existEntity( instanceName,obj ) )
{
if( obj->getClassName()!=className )
throw ExceptionPython( ExceptionPython::CLASS_INCONSISTENT,
"Found an object with the same name but of different class." );
}
else /* If not, create a new object. */
{
try {
obj = dynamicgraph::g_factory.newEntity(std::string(className),
std::string(instanceName));
} catch (std::exception& exc) {
PyErr_SetString(error, exc.what());
return NULL;
}
}
// Return the pointer as a PyCObject
return PyCObject_FromVoidPtr((void*)obj, NULL);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment