Logo ROOT   6.10/09
Reference Guide
TPyReturn.h
Go to the documentation of this file.
1 // @(#)root/pyroot:$Id$
2 // Author: Wim Lavrijsen May 2004
3 
4 #ifndef ROOT_TPyReturn
5 #define ROOT_TPyReturn
6 
7 //////////////////////////////////////////////////////////////////////////////
8 // //
9 // TPyReturn //
10 // //
11 // Morphing return type from evaluating python expressions. //
12 // //
13 //////////////////////////////////////////////////////////////////////////////
14 
15 
16 // ROOT
17 #include "Rtypes.h"
18 
19 // Python
20 struct _object;
21 typedef _object PyObject;
22 
23 
24 class TPyReturn {
25 public:
26  TPyReturn();
27  TPyReturn( PyObject* pyobject );
28  TPyReturn( const TPyReturn& );
29  TPyReturn& operator=( const TPyReturn& );
30  virtual ~TPyReturn();
31 
32 // conversions to standard types, may fail if unconvertible
33  operator char*() const;
34  operator const char*() const;
35  operator Char_t() const;
36 
37  operator Long_t() const;
38  operator Int_t() const { return (Int_t)operator Long_t(); }
39  operator Short_t() const { return (Short_t)operator Long_t(); }
40 
41  operator ULong_t() const;
42  operator UInt_t() const { return (UInt_t)operator ULong_t(); }
43  operator UShort_t() const { return (UShort_t)operator ULong_t(); }
44 
45  operator Double_t() const;
46  operator Float_t() const { return (Float_t)operator Double_t(); }
47 
48 // used for both TObject and PyObject conversions
49  operator void*() const;
50 
51  template<class T>
52  operator T*() const { return (T*)(void*)*this; }
53 
54 // used strictly for PyObject conversions
55  operator PyObject*() const;
56 
57  ClassDef(TPyReturn,1) //Python morphing return object
58 
59 private:
60  PyObject* fPyObject; //! actual python object
61 };
62 
63 #endif
float Float_t
Definition: RtypesCore.h:53
TPyReturn & operator=(const TPyReturn &)
Assignment operator. Applies python object reference counting.
Definition: TPyReturn.cxx:74
double T(double x)
Definition: ChebyshevPol.h:34
unsigned short UShort_t
Definition: RtypesCore.h:36
int Int_t
Definition: RtypesCore.h:41
#define ClassDef(name, id)
Definition: Rtypes.h:297
virtual ~TPyReturn()
Destructor. Reference counting for the held python object is in effect.
Definition: TPyReturn.cxx:88
_object PyObject
Definition: TPyReturn.h:20
unsigned int UInt_t
Definition: RtypesCore.h:42
short Short_t
Definition: RtypesCore.h:35
long Long_t
Definition: RtypesCore.h:50
double Double_t
Definition: RtypesCore.h:55
unsigned long ULong_t
Definition: RtypesCore.h:51
PyObject * fPyObject
Definition: TPyReturn.h:60
char Char_t
Definition: RtypesCore.h:29
_object PyObject
Definition: TPyArg.h:20