00001 // @(#)root/pyroot:$Id: MemoryRegulator.h 36609 2010-11-11 18:49:41Z wlav $ 00002 // Author: Wim Lavrijsen, Apr 2004 00003 00004 #ifndef PYROOT_TMEMORYREGULATOR_H 00005 #define PYROOT_TMEMORYREGULATOR_H 00006 00007 // ROOT 00008 #include "TObject.h" 00009 00010 // Standard 00011 #include <map> 00012 00013 00014 namespace PyROOT { 00015 00016 /** Communicate object destruction across ROOT/CINT/PyROOT/ 00017 @author WLAV 00018 @date 11/23/2004 00019 @version 2.2 00020 */ 00021 00022 class ObjectProxy; 00023 00024 class TMemoryRegulator : public TObject { 00025 public: 00026 TMemoryRegulator(); 00027 ~TMemoryRegulator(); 00028 00029 // callback for ROOT/CINT 00030 virtual void RecursiveRemove( TObject* object ); 00031 00032 // add a python object to the table of managed objects 00033 static Bool_t RegisterObject( ObjectProxy* pyobj, TObject* object ); 00034 00035 // remove a python object from the table of managed objects, w/o notification 00036 static Bool_t UnregisterObject( TObject* object ); 00037 00038 // new reference to python object corresponding to object, or 0 on failure 00039 static PyObject* RetrieveObject( TObject* object ); 00040 00041 // callback when weak refs to managed objects are destroyed 00042 static PyObject* ObjectEraseCallback( PyObject*, PyObject* pyref ); 00043 00044 private: 00045 typedef std::map< TObject*, PyObject* > ObjectMap_t; 00046 typedef std::map< PyObject*, ObjectMap_t::iterator > WeakRefMap_t; 00047 00048 static ObjectMap_t* fgObjectTable; 00049 static WeakRefMap_t* fgWeakRefTable; 00050 }; 00051 00052 } // namespace PyROOT 00053 00054 #endif // !PYROOT_TMEMORYREGULATOR_H