Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:10:07

0001 #ifndef CPYCPPYY_PYRESULT_H
0002 #define CPYCPPYY_PYRESULT_H
0003 
0004 //////////////////////////////////////////////////////////////////////////////
0005 //                                                                          //
0006 // TPyResult                                                                //
0007 //                                                                          //
0008 // Morphing return type from evaluating python expressions.                 //
0009 //                                                                          //
0010 //////////////////////////////////////////////////////////////////////////////
0011 
0012 // Python
0013 struct _object;
0014 typedef _object PyObject;
0015 
0016 // Bindings
0017 #include "CPyCppyy/CommonDefs.h"
0018 
0019 
0020 namespace CPyCppyy {
0021 
0022 class CPYCPPYY_CLASS_EXTERN PyResult {
0023 public:
0024     PyResult();
0025     PyResult(PyObject* pyobject);
0026     PyResult(const PyResult&);
0027     PyResult& operator=(const PyResult&);
0028     virtual ~PyResult();
0029 
0030 // conversions to standard types, may fail if unconvertible
0031     operator char*() const;
0032     operator const char*() const;
0033     operator char() const;
0034 
0035     operator long() const;
0036     operator int() const { return (int)operator long(); }
0037     operator short() const { return (short)operator long(); }
0038 
0039     operator unsigned long() const;
0040     operator unsigned int() const {
0041         return (unsigned int)operator unsigned long();
0042     }
0043     operator unsigned short() const {
0044         return (unsigned short)operator unsigned long();
0045     }
0046 
0047     operator double() const;
0048     operator float() const { return (float)operator double(); }
0049 
0050 // used for both general object type and PyObject conversions
0051     operator void*() const;
0052 
0053     template<class T>
0054     operator T*() const { return (T*)(void*)*this; }
0055 
0056 // used strictly for PyObject conversions
0057     operator PyObject*() const;
0058 
0059 private:
0060     PyObject* fPyObject;            //! actual python object
0061 };
0062 
0063 } // namespace CPyCppyy
0064 
0065 #endif // !CPYCPPYY_PYRESULT_H