Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
PropertyProxy.h
Go to the documentation of this file.
1 // @(#)root/pyroot:$Id$
2 // Author: Wim Lavrijsen, Jan 2005
3 
4 #ifndef PYROOT_PROPERTYPROXY_H
5 #define PYROOT_PROPERTYPROXY_H
6 
7 // Bindings
8 #include "Converters.h"
9 
10 // ROOT
11 #include "DllImport.h"
12 #include "TClassRef.h"
13 class TDataMember;
14 class TEnumConstant;
15 class TGlobal;
16 
17 // Standard
18 #include <string>
19 
20 
21 namespace PyROOT {
22 
23  class ObjectProxy;
24 
25  class PropertyProxy {
26  public:
27  void Set( Cppyy::TCppScope_t scope, Cppyy::TCppIndex_t idata );
28  void Set( Cppyy::TCppScope_t scope, const std::string& name, void* address, TEnum* en );
29 
30  std::string GetName() { return fName; }
31  void* GetAddress( ObjectProxy* pyobj /* owner */ );
32 
33  public: // public, as the python C-API works with C structs
34  PyObject_HEAD
35  ptrdiff_t fOffset;
36  Long_t fProperty;
37  TConverter* fConverter;
38  Cppyy::TCppScope_t fEnclosingScope;
39  std::string fName;
40 
41  private: // private, as the python C-API will handle creation
42  PropertyProxy() {}
43  };
44 
45 
46 //- property proxy type and type verification --------------------------------
47  R__EXTERN PyTypeObject PropertyProxy_Type;
48 
49  template< typename T >
50  inline Bool_t PropertyProxy_Check( T* object )
51  {
52  return object && PyObject_TypeCheck( object, &PropertyProxy_Type );
53  }
54 
55  template< typename T >
56  inline Bool_t PropertyProxy_CheckExact( T* object )
57  {
58  return object && Py_TYPE(object) == &PropertyProxy_Type;
59  }
60 
61 //- creation -----------------------------------------------------------------
62  inline PropertyProxy* PropertyProxy_New(
63  Cppyy::TCppScope_t scope, Cppyy::TCppIndex_t idata )
64  {
65  // Create an initialize a new property descriptor, given the C++ datum.
66  PropertyProxy* pyprop =
67  (PropertyProxy*)PropertyProxy_Type.tp_new( &PropertyProxy_Type, 0, 0 );
68  pyprop->Set( scope, idata );
69  return pyprop;
70  }
71 
72  inline PropertyProxy* PropertyProxy_NewConstant(
73  Cppyy::TCppScope_t scope, const std::string& name, void* address, TEnum* en )
74  {
75  // Create an initialize a new property descriptor, given the C++ datum.
76  PropertyProxy* pyprop =
77  (PropertyProxy*)PropertyProxy_Type.tp_new( &PropertyProxy_Type, 0, 0 );
78  pyprop->Set( scope, name, address, en );
79  return pyprop;
80  }
81 
82 } // namespace PyROOT
83 
84 #endif // !PYROOT_PROPERTYPROXY_H