ROOT
Version v6.32
master
v6.34
v6.30
v6.28
v6.26
v6.24
v6.22
v6.20
v6.18
v6.16
v6.14
v6.12
v6.10
v6.08
v6.06
Reference Guide
▼
ROOT
ROOT Reference Documentation
Tutorials
►
Functional Parts
►
Namespaces
►
All Classes
▼
Files
▼
File List
▼
bindings
▼
pyroot
▼
cppyy
►
cppyy
►
cppyy-backend
▼
CPyCppyy
▼
include
▼
CPyCppyy
►
API.h
►
CommonDefs.h
►
DispatchPtr.h
►
PyException.h
►
PyResult.h
►
Reflex.h
►
TPyArg.h
►
src
►
pythonizations
►
r
►
tpython
►
core
►
documentation
►
geom
►
graf2d
►
graf3d
►
gui
►
hist
►
html
►
io
►
main
►
math
►
montecarlo
►
net
►
proof
►
roofit
►
sql
►
tmva
►
tree
►
tutorials
►
v6-32-00-patches
►
File Members
Release Notes
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Modules
Pages
Loading...
Searching...
No Matches
DispatchPtr.h
Go to the documentation of this file.
1
#ifndef CPYCPPYY_DISPATCHPTR_H
2
#define CPYCPPYY_DISPATCHPTR_H
3
4
//////////////////////////////////////////////////////////////////////////////
5
// //
6
// DispatchPtr //
7
// //
8
// Smart pointer for reference management and C++ instance tracking when //
9
// cross-inheriting. The carried pointer is always expected to be derived //
10
// from CPPInstance, and the DispatchPtr to be embedded in the C++ instance //
11
// derived dispatcher to which it points (ownership is two-way; life-times //
12
// are equal). The C++ dispatcher then uses the DispatchPtr to call Python //
13
// functions for virtual methods. //
14
// //
15
//////////////////////////////////////////////////////////////////////////////
16
17
// Bindings
18
#include "
CPyCppyy/CommonDefs.h
"
19
20
21
namespace
CPyCppyy
{
22
23
class
CPYCPPYY_CLASS_EXTERN
DispatchPtr
{
24
public
:
25
// Default constructor: only ever created from C++, as by definition, creation
26
// from the Python side makes the relevant Python instance available. Calls to
27
// the default ctor happen eg. in STL containers. It is expected that the
28
// pointer to the Python object is filled in later, eg. through assign().
29
DispatchPtr
() : fPyHardRef(nullptr), fPyWeakRef(nullptr) {}
30
31
// Conversion constructor: called with C++ object construction when the PyObject
32
// is known (eg. when instantiating from Python), with pyobj the Python-side
33
// representation of the C++ object.
34
explicit
DispatchPtr
(
PyObject
*
pyobj
,
bool
strong
=
false
);
35
36
// Copy constructor: only ever called from C++. The Python object needs to be
37
// copied, in case it has added state, and rebound to the new C++ instance.
38
DispatchPtr
(
const
DispatchPtr
&
other
,
void
*
cppinst
);
39
40
// Assignment: only ever called from C++. Similarly to the copy constructor, the
41
// Pythonb object needs to be copied and rebound.
42
DispatchPtr
& assign(
const
DispatchPtr
&
other
,
void
*
cppinst
);
43
44
// Do not otherwise allow straight copies/assignment.
45
DispatchPtr
(
DispatchPtr
&) =
delete
;
46
DispatchPtr
(
DispatchPtr
&&) =
delete
;
47
DispatchPtr
&
operator=
(
const
DispatchPtr
&
other
) =
delete
;
48
49
// lifetime is directly bound to the lifetime of the dispatcher object
50
~DispatchPtr
();
51
52
// either C++ owns the Python object through a reference count (on fPyHardRef) or
53
// Python owns the C++ object and we only have a weak reference (through fPyWeakRef)
54
void
PythonOwns();
55
void
CppOwns();
56
57
// access to underlying object: cast and dereferencing
58
operator
PyObject
*()
const
{
59
return
Get();
60
}
61
62
PyObject
*
operator->
()
const
{
63
return
Get();
64
}
65
66
private
:
67
PyObject
* Get()
const
;
68
69
private
:
70
PyObject
*
fPyHardRef
;
71
PyObject
*
fPyWeakRef
;
72
};
73
74
}
// namespace CPyCppyy
75
76
#endif
// !CPYCPPYY_DISPATCHPTR_H
PyObject
_object PyObject
Definition
PyMethodBase.h:43
CommonDefs.h
CPYCPPYY_CLASS_EXTERN
#define CPYCPPYY_CLASS_EXTERN
Definition
CommonDefs.h:29
CPyCppyy::DispatchPtr
Definition
DispatchPtr.h:23
CPyCppyy::DispatchPtr::DispatchPtr
DispatchPtr()
Definition
DispatchPtr.h:29
CPyCppyy::DispatchPtr::fPyWeakRef
PyObject * fPyWeakRef
Definition
DispatchPtr.h:71
CPyCppyy::DispatchPtr::operator->
PyObject * operator->() const
Definition
DispatchPtr.h:62
CPyCppyy::DispatchPtr::DispatchPtr
DispatchPtr(DispatchPtr &)=delete
CPyCppyy::DispatchPtr::fPyHardRef
PyObject * fPyHardRef
Definition
DispatchPtr.h:70
CPyCppyy::DispatchPtr::DispatchPtr
DispatchPtr(DispatchPtr &&)=delete
CPyCppyy::DispatchPtr::operator=
DispatchPtr & operator=(const DispatchPtr &other)=delete
ROOT::Detail::TRangeCast
Definition
TCollection.h:311
CPyCppyy
Definition
callcontext.h:10
bindings
pyroot
cppyy
CPyCppyy
include
CPyCppyy
DispatchPtr.h
ROOT v6-32 - Reference Guide Generated on Wed Apr 2 2025 08:24:18 (GVA Time) using Doxygen 1.10.0