Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TPyReturn.h
Go to the documentation of this file.
1// Author: Enric Tejedor CERN 08/2019
2// Original PyROOT code by Wim Lavrijsen, LBL
3//
4// /*************************************************************************
5// * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
6// * All rights reserved. *
7// * *
8// * For the licensing terms see $ROOTSYS/LICENSE. *
9// * For the list of contributors see $ROOTSYS/README/CREDITS. *
10// *************************************************************************/
11
12#ifndef ROOT_TPyReturn
13#define ROOT_TPyReturn
14
15//////////////////////////////////////////////////////////////////////////////
16// //
17// TPyReturn //
18// //
19// Morphing return type from evaluating python expressions. //
20// //
21//////////////////////////////////////////////////////////////////////////////
22
23// ROOT
24#include "Rtypes.h"
25
26// Python
27struct _object;
28typedef _object PyObject;
29
30class TPyReturn {
31public:
32 TPyReturn();
33 TPyReturn(PyObject *pyobject);
34 TPyReturn(const TPyReturn &);
36 virtual ~TPyReturn();
37
38 // conversions to standard types, may fail if unconvertible
39 operator char *() const;
40 operator const char *() const;
41 operator Char_t() const;
42
43 operator Long_t() const;
44 operator Int_t() const { return (Int_t) operator Long_t(); }
45 operator Short_t() const { return (Short_t) operator Long_t(); }
46
47 operator ULong_t() const;
48 operator UInt_t() const { return (UInt_t) operator ULong_t(); }
49 operator UShort_t() const { return (UShort_t) operator ULong_t(); }
50
51 operator Double_t() const;
52 operator Float_t() const { return (Float_t) operator Double_t(); }
53
54 // used for both TObject and PyObject conversions
55 operator void *() const;
56
57 template <class T>
58 operator T *() const
59 {
60 return (T *)(void *)*this;
61 }
62
63 // used strictly for PyObject conversions
64 operator PyObject *() const;
65
66 ClassDef(TPyReturn, 1) // Python morphing return object
67
68private:
69 PyObject *fPyObject; //! actual python object
70};
71
72#endif
_object PyObject
unsigned short UShort_t
Definition RtypesCore.h:40
int Int_t
Definition RtypesCore.h:45
char Char_t
Definition RtypesCore.h:37
unsigned long ULong_t
Definition RtypesCore.h:55
long Long_t
Definition RtypesCore.h:54
unsigned int UInt_t
Definition RtypesCore.h:46
float Float_t
Definition RtypesCore.h:57
short Short_t
Definition RtypesCore.h:39
double Double_t
Definition RtypesCore.h:59
#define ClassDef(name, id)
Definition Rtypes.h:342
_object PyObject
Definition TPyReturn.h:28
TPyReturn & operator=(const TPyReturn &)
Assignment operator. Applies python object reference counting.
Definition TPyReturn.cxx:93
virtual ~TPyReturn()
Destructor. Reference counting for the held python object is in effect.
PyObject * fPyObject
Definition TPyReturn.h:69