Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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