Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TMemoryRegulator.h
Go to the documentation of this file.
1 // @(#)root/pyroot:$Id$
2 // Author: Wim Lavrijsen, Apr 2004
3 
4 #ifndef PYROOT_TMEMORYREGULATOR_H
5 #define PYROOT_TMEMORYREGULATOR_H
6 
7 // ROOT
8 #include "TObject.h"
9 
10 // Standard
11 #include <unordered_map>
12 
13 
14 namespace PyROOT {
15 
16 /** Communicate object destruction across ROOT/CINT/PyROOT/
17  @author WLAV
18  @date 11/23/2004
19  @version 2.2
20  */
21 
22  class ObjectProxy;
23 
24  class TMemoryRegulator : public TObject {
25  public:
26  TMemoryRegulator();
27  ~TMemoryRegulator();
28 
29  // callback for ROOT/CINT
30  virtual void RecursiveRemove( TObject* object );
31 
32  // cleanup of all tracked objects
33  void ClearProxiedObjects();
34 
35  // add a python object to the table of managed objects
36  static Bool_t RegisterObject( ObjectProxy* pyobj, TObject* object );
37 
38  // remove a python object from the table of managed objects, w/o notification
39  static Bool_t UnregisterObject( TObject* object );
40 
41  // new reference to python object corresponding to object, or 0 on failure
42  static PyObject* RetrieveObject( TObject* object, Cppyy::TCppType_t klass );
43 
44  // callback when weak refs to managed objects are destroyed
45  static PyObject* ObjectEraseCallback( PyObject*, PyObject* pyref );
46 
47  private:
48  typedef std::unordered_map< TObject*, PyObject* > ObjectMap_t;
49  typedef std::unordered_map< PyObject*, ObjectMap_t::iterator > WeakRefMap_t;
50 
51  static ObjectMap_t* fgObjectTable;
52  static WeakRefMap_t* fgWeakRefTable;
53  };
54 
55 } // namespace PyROOT
56 
57 #endif // !PYROOT_TMEMORYREGULATOR_H