-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQorePythonClass.h
More file actions
115 lines (83 loc) · 3.65 KB
/
Copy pathQorePythonClass.h
File metadata and controls
115 lines (83 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/* -*- mode: c++; indent-tabs-mode: nil -*- */
/*
QorePythonClass.h
Qore Programming Language python Module
Copyright (C) 2020 - 2021 Qore Technologies, s.r.o.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _QORE_PYTHON_QOREPYTHONCLASS_H
#define _QORE_PYTHON_QOREPYTHONCLASS_H
#include "python-module.h"
#include "QorePythonPrivateData.h"
#include <string>
#include <vector>
#include <memory>
#include <map>
// forward references
class QorePythonProgram;
//! Represents a Python class in Qore
class QorePythonClass : public QoreBuiltinClass {
public:
//! only for the base python class
DLLLOCAL QorePythonClass(const char* name, const char* path);
DLLLOCAL QorePythonClass(QorePythonProgram* pypgm, const char* name, const char* path);
DLLLOCAL QorePythonClass(const QorePythonClass& old);
DLLLOCAL virtual ~QorePythonClass();
//! Called when a class is copied for import
DLLLOCAL virtual QoreClass* copyImport() {
return new QorePythonClass;
}
//! Called when a class is copied
DLLLOCAL virtual QoreClass* copy() {
return new QorePythonClass(*this);
}
DLLLOCAL void addObj(PyObject* obj);
DLLLOCAL void addPythonMember(std::string member, PyMemberDef* memdef) {
assert(mem_map.find(member) == mem_map.end());
mem_map[member] = memdef;
}
DLLLOCAL PyMemberDef* getPythonMember(std::string member) const {
mem_map_t::const_iterator i = mem_map.find(member);
/*
if (i == mem_map.end()) {
for (auto& ix : mem_map) {
printd(0, "MEM %s\n", ix.first.c_str());
}
}
*/
return i == mem_map.end() ? nullptr : i->second;
}
DLLLOCAL QorePythonProgram* getPythonProgram() const {
return pypgm;
}
DLLLOCAL PyObject* getPyObject(QoreObject* self, ExceptionSink* xsink) const;
DLLLOCAL int setPyObject(QoreObject* self, PyObject* pyself, ExceptionSink* xsink) const;
DLLLOCAL QoreValue getPythonMember(QorePythonProgram* pypgm, const char* mname, QorePythonPrivateData* pd,
ExceptionSink* xsink) const;
DLLLOCAL QoreValue callPythonMethod(ExceptionSink* xsink, QorePythonProgram* pypgm, const char* mname, const QoreListNode* args,
QorePythonPrivateData* pd, size_t arg_offset = 0) const;
DLLLOCAL static QoreValue memberGate(const QoreMethod& meth, void* m, QoreObject* self, QorePythonPrivateData* pd,
const QoreListNode* args, q_rt_flags_t rtflags, ExceptionSink* xsink);
DLLLOCAL static QoreValue methodGate(const QoreMethod& meth, void* m, QoreObject* self, QorePythonPrivateData* pd,
const QoreListNode* args, q_rt_flags_t rtflags, ExceptionSink* xsink);
private:
QorePythonProgram* pypgm = nullptr;
// map of builtin members: name -> member
typedef std::map<std::string, PyMemberDef*> mem_map_t;
mem_map_t mem_map;
std::string pname;
static type_vec_t gateParamTypeInfo;
DLLLOCAL QorePythonClass() {
}
};
#endif