From 4657223e544b38ffb03786a71b1ff1e4143ddc2c Mon Sep 17 00:00:00 2001 From: Mansard <nmansard@laas.fr> Date: Thu, 14 Apr 2011 17:59:25 +0200 Subject: [PATCH] Changed the factory to enable heritage for Entity py-classes. --- src/dynamic_graph/entity.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/dynamic_graph/entity.py b/src/dynamic_graph/entity.py index 552ca06..37a0997 100644 --- a/src/dynamic_graph/entity.py +++ b/src/dynamic_graph/entity.py @@ -19,10 +19,19 @@ class PyEntityFactoryClass(type): The class build dynamically a new class type, and return the reference on the class-type object. The class type is not added to any context. """ - def __new__(factory, className ): - EntityClass = type.__new__(factory, className, (Entity,), {}) - EntityClass.className = className - EntityClass.__init__ = Entity.initEntity + def __new__(factory, className,bases=(), dict={} ): + if len(bases)==0: + # Initialize a basic Entity class + EntityClass = type.__new__(factory, className, (Entity,), dict) + EntityClass.className = className + EntityClass.__init__ = Entity.initEntity + else: + # Initialize a heritated class + EntityClass = type.__new__(factory, className, bases, dict) + for c in bases: + if issubclass(c,Entity): + EntityClass.className = c.className + break EntityClass.commandCreated = False return EntityClass -- GitLab