Anonymous avatar Anonymous committed 0e24913

use TClass API rather than Reflex one for PyDataBucket

Comments (0)

Files changed (2)

+2007-12-18  Sebastien Binet  <binet@lblbox>
+
+	* tagging StoreGateBindings-00-00-02
+	* use TClass API rather than Reflex one
+	* M src/StoreGatePyExt.cxx
+
 2007-12-14  Sebastien Binet  <binet@lblbox>
 
 	* tagging StoreGateBindings-00-00-01

src/StoreGatePyExt.cxx

   public:
     /**
      * @brief Constructor.
-     * @param rflxType The Reflex dict. for the held object.
      * @param pyObj The (pyroot) object proxy to hold.
      * @param clid The class ID of the wrapped object.
      */
-    PyDataBucket( const ROOT::Reflex::Type& rflxType, 
-		  PyROOT::ObjectProxy* pyObj,
+    PyDataBucket( PyROOT::ObjectProxy* pyObj,
 		  CLID clid );
 
 
     /// The class ID of the wrapped object.
     CLID m_clid;
 
-    /// The Reflex dictionary of the held object.
-    ROOT::Reflex::Type m_type;
-
     /// Pointer to the @ IClassIDSvc to be able to cast objects based
     /// the @a clid.
     static IClassIDSvc* s_clidSvc;
   }
   
   PyROOT::ObjectProxy* pyRootObj = (PyROOT::ObjectProxy*)obj;
-  DataObject* dataObj = new SG::PyDataBucket( ROOT::Reflex::Type::ByName(name),
-					      pyRootObj,
-					      id );
+  DataObject* dataObj = new SG::PyDataBucket( pyRootObj, id );
   static bool allowMods = true;
   if ( !store->typeless_record( dataObj, PyString_AS_STRING(key),
 				pyRootObj->GetObject(),
     return s_clidSvc;
   }
 
-  PyDataBucket::PyDataBucket( const ROOT::Reflex::Type& rflxType,
-			      PyROOT::ObjectProxy* pyObj,
+  PyDataBucket::PyDataBucket( PyROOT::ObjectProxy* pyObj,
 			      CLID clid ) :
     DataBucketBase(),
     m_pyObj( pyObj ),
-    m_clid ( clid  ),
-    m_type ( rflxType )
+    m_clid ( clid  )
   {
     // prevent Python from sweeping the rug under our feet
     Py_INCREF( pyObj );
 		    (long unsigned int)clid );
       return 0;
     }
-    ROOT::Reflex::Type toType = ROOT::Reflex::Type::ByName( clidTypeName );
-    if ( !(bool)toType ) {
-      PyErr_Format( PyExc_TypeError, 
-		    "Reflex Type of %s is unknown", clidTypeName.c_str() );
-      return 0;
+
+    // Create a converter for that type
+    PyROOT::TConverter* pcnv = PyROOT::CreateConverter( clidTypeName );
+    void* address = m_pyObj->GetObject();
+    PyObject* value = pcnv->FromMemory(&address);
+    delete pcnv;
+
+    if ( PyROOT::ObjectProxy_Check(value) ) {
+      return ((PyROOT::ObjectProxy*)value)->GetObject();
     }
-
-    ROOT::Reflex::Object self( m_type, m_pyObj->GetObject() );
-    const ROOT::Reflex::Object& obj = m_type.CastObject( toType, self );
-    return (void*)obj.Address();
+    Py_XDECREF(value);
+    PyErr_Format( PyExc_TypeError, 
+		  "Could not convert to %s", clidTypeName.c_str() );
+    return 0;
   }
 
   void* PyDataBucket::cast( const std::type_info& tinfo ) const
   {
     // if requested type is same than myself ==> no conversion needed
-    if ( tinfo == m_type.TypeInfo() ) {
+    if ( tinfo == *(m_pyObj->fClass->GetTypeInfo()) ) {
       return m_pyObj->GetObject();
     }
 
-    ROOT::Reflex::Type toType = ROOT::Reflex::Type::ByTypeInfo( tinfo );
-    if ( !(bool)toType ) {
-      PyErr_Format( PyExc_TypeError, 
-		    "Reflex Type of %s is unknown", tinfo.name() );
-      return 0;
+    // Create a converter for that type
+    PyROOT::TConverter* pcnv = PyROOT::CreateConverter( tinfo.name() );
+    void* address = m_pyObj->GetObject();
+    PyObject* value = pcnv->FromMemory(&address);
+    delete pcnv;
+
+    if ( PyROOT::ObjectProxy_Check(value) ) {
+      return ((PyROOT::ObjectProxy*)value)->GetObject();
     }
-
-    ROOT::Reflex::Object self( m_type, m_pyObj->GetObject() );
-    const ROOT::Reflex::Object& obj = m_type.CastObject( toType, self );
-    return (void*)obj.Address();
+    Py_XDECREF(value);
+    PyErr_Format( PyExc_TypeError, 
+		  "Could not convert to %s", tinfo.name() );
+    return 0;
   }
 
   PyDataBucket* PyDataBucket::clone() const
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.