Loading [MathJax]/extensions/tex2jax.js
Free Electron
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
pyfe.h
Go to the documentation of this file.
1 /* Copyright (C) 2003-2021 Free Electron Organization
2  Any use of this software requires a license. If a valid license
3  was not distributed with this file, visit freeelectron.org. */
4 
5 /** @file */
6 
7 #ifndef __fe_pyfe_h__
8 #define __fe_pyfe_h__
9 
10 #include "fe/data.h"
11 
12 #if FE_CODEGEN<=FE_DEBUG && (FE_OS==FE_WIN32 || FE_OS==FE_WIN64)
13 #include <boost/python/detail/wrap_python.hpp>
14 //#include <Python.h>
15 #else
16 #include <Python.h>
17 #endif
18 
19 #if FE_CODEGEN<=FE_DEBUG && (FE_OS==FE_WIN32 || FE_OS==FE_WIN64)
20 #define FE_PYTHON_MODULE(mod) BOOST_PYTHON_MODULE(mod)
21 #else
22 #define FE_PYTHON_MODULE(mod) BOOST_PYTHON_MODULE(mod)
23 #endif
24 
25 namespace pyfe
26 {
27 
28 //extern PyInterpreterState *ms_pInterp;
29 //extern boost::thread_specific_sp<PyThreadState *> tss_tstate;
30 
31 class BaseConvertor : public fe::Counted
32 {
33  public:
34 virtual ~BaseConvertor(void) {}
35 virtual PyObject *instanceToPyObject(fe::sp<fe::BaseType> spBT,
36  fe::Instance &instance) = 0;
37 virtual bool PyObjectToInstance(fe::sp<fe::BaseType> spBT,
38  PyObject *pObject, fe::Instance &instance) = 0;
39 };
40 
41 FE_DL_EXPORT void addConvertor(fe::sp<fe::BaseType> spBT, fe::sp<BaseConvertor> spCnvrtr);
42 FE_DL_EXPORT PyObject *bindRecord(const fe::Record &record);
43 FE_DL_EXPORT PyObject *bindRecordArray(const fe::sp<fe::RecordArray> spRA);
44 FE_DL_EXPORT fe::Record extractRecord(PyObject *pRecord);
45 FE_DL_EXPORT fe::sp<fe::RecordArray> extractRecordArray(PyObject *pRecord);
46 FE_DL_EXPORT fe::Instance extractInstance(PyObject *pInstance);
47 FE_DL_EXPORT PyObject *bindInstance(fe::Instance &instance);
48 FE_DL_EXPORT PyObject *lookupPyObject(char *module_name, char *object_name);
49 FE_DL_EXPORT fe::Master &feMaster(void);
50 FE_DL_EXPORT PyObject *bindComponent(const fe::sp<fe::Component> spComponent);
51 FE_DL_EXPORT fe::sp<fe::Component> extractComponent(PyObject *pComponent);
52 
53 } /* namespace */
54 
55 class BaseFunctionSet
56 {
57  public:
58 virtual ~BaseFunctionSet(void) {}
59 virtual PyObject *object(void) = 0;
60 };
61 
62 template<class T>
63 class FunctionSet
64 {
65  public:
66 #if 0
67  FunctionSet(ComponentPtr cptr)
68  {
69  m_sp = cptr.ptr();
70  }
71 #endif
72  FunctionSet(PyObject *pPyObject)
73  {
74  m_sp = pyfe::extractComponent(pPyObject);
75  }
76  FunctionSet(fe::sp<fe::Component> spComponent)
77  {
78  m_sp = spComponent;
79  }
80 virtual ~FunctionSet(void) {}
81 
82  fe::sp<T> ptr(void)
83  {
84  assertValid();
85  return m_sp;
86  }
87  fe::sp<T> *rawptr(void)
88  {
89  assertValid();
90  return &m_sp;
91  }
92  void assign(fe::sp<T> tptr)
93  {
94  m_sp = tptr;
95  }
96 virtual PyObject *object(void)
97  {
98  return pyfe::bindComponent(m_sp);
99  }
100 
101  protected:
102  void assertValid(void)
103  {
104  if(!m_sp.isValid())
105  {
106  throw fe::Exception("invalid function set");
107  }
108  }
109  private:
110  fe::sp<T> m_sp;
111 };
112 
113 
114 
115 #endif /* __fe_pyfe_h__ */
Heap-based support for classes participating in fe::ptr <>
Definition: Counted.h:35
Smart pointer used with types represented by BaseType.
Definition: Instance.h:28
python binding
Definition: namespace.dox:7
Generic exception carrying a fe::String payload.
Definition: Exception.h:34
Reference to an instance of a Layout.
Definition: RecordSB.h:35
Central access point for key pseudo-global objects.
Definition: Master.h:21