From 2d00fff920f11254713e5c93f2c6fb7cd76efc08 Mon Sep 17 00:00:00 2001 From: Mansard <nmansard@laas.fr> Date: Wed, 22 Jun 2011 18:13:23 +0200 Subject: [PATCH] Modify SignalBase.value. If a signal contains a data deriving from Vector or Matrix, cast content into Matrix or Vector using plug machinery. --- src/signal-base-py.cc | 54 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 9 deletions(-) diff --git a/src/signal-base-py.cc b/src/signal-base-py.cc index fc3eddf..b400896 100644 --- a/src/signal-base-py.cc +++ b/src/signal-base-py.cc @@ -152,21 +152,57 @@ namespace dynamicgraph { SignalBase<int>* signal = (SignalBase<int>*)pointer; try { - /* Temptative for specific signal type. */ - Signal<dynamicgraph::Vector,int> * sigvec - = dynamic_cast< Signal<dynamicgraph::Vector,int>* >( signal ); - if( NULL!= sigvec ) - { + { // --- VECTOR SIGNALS ----------------- + // Two cases: the signal embeds directly a vector, or embeds + // an object deriving from vector.In the first case, + // the signal is directly cast into sig<vector>. + // In the second case, the derived object can be access as a vector + // using the signal-ptr<vector> type. + Signal<dynamicgraph::Vector,int> * sigvec + = dynamic_cast< Signal<dynamicgraph::Vector,int>* >( signal ); + if( NULL!= sigvec ) { return vectorToPython( sigvec->accessCopy() ); } - Signal<dynamicgraph::Matrix,int> * sigmat - = dynamic_cast< Signal<dynamicgraph::Matrix,int>* >( signal ); - if( NULL!= sigmat ) - { + // Extraction of object derinving from vector: plug signal into + // a vector signal and get the value from the signal-ptr instead + // of the original vector. + SignalPtr<dynamicgraph::Vector,int> sigptr(NULL,"vector-caster"); + try { + sigptr.plug(signal); + return vectorToPython( sigptr.accessCopy() ); + } + catch( dynamicgraph::ExceptionSignal& ex ) { + if( ex.getCode() != + dynamicgraph::ExceptionSignal::PLUG_IMPOSSIBLE ) + throw; + } + } + + { // --- MATRIX SIGNALS -------------------- + // Two cases: the signal embeds directly a matrix, or embeds + // an object deriving from matrix.In the first case, + // the signal is directly cast into sig<matrix>. + // In the second case, the derived object can be access as a matrix + // using the signal-ptr<matrix> type. + Signal<dynamicgraph::Matrix,int> * sigmat + = dynamic_cast< Signal<dynamicgraph::Matrix,int>* >( signal ); + if( NULL!= sigmat ) { return matrixToPython( sigmat->accessCopy() ); } + SignalPtr<dynamicgraph::Matrix,int> sigptr(NULL,"matrix-caster"); + try { + sigptr.plug(signal); + return matrixToPython( sigptr.accessCopy() ); + } + catch( dynamicgraph::ExceptionSignal& ex ) { + if( ex.getCode() != + dynamicgraph::ExceptionSignal::PLUG_IMPOSSIBLE ) + throw; + } + } + Signal<double,int> * sigdouble = dynamic_cast< Signal<double,int>* >( signal ); if( NULL!= sigdouble ) -- GitLab