forked from APrioriInvestments/typed_python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPyPythonObjectOfTypeInstance.hpp
More file actions
40 lines (30 loc) · 1.23 KB
/
Copy pathPyPythonObjectOfTypeInstance.hpp
File metadata and controls
40 lines (30 loc) · 1.23 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
#pragma once
#include "PyInstance.hpp"
class PyPythonObjectOfTypeInstance : public PyInstance {
public:
typedef PythonObjectOfType modeled_type;
static void copyConstructFromPythonInstanceConcrete(PythonObjectOfType* eltType, instance_ptr tgt, PyObject* pyRepresentation, bool isExplicit) {
int isinst = PyObject_IsInstance(pyRepresentation, (PyObject*)eltType->pyType());
if (isinst == -1) {
isinst = 0;
PyErr_Clear();
}
if (!isinst) {
throw std::logic_error("Object of type " + std::string(pyRepresentation->ob_type->tp_name) +
" is not an instance of " + ((PythonObjectOfType*)eltType)->pyType()->tp_name);
}
((PyObject**)tgt)[0] = incref(pyRepresentation);
return;
}
static bool pyValCouldBeOfTypeConcrete(modeled_type* type, PyObject* pyRepresentation) {
int isinst = PyObject_IsInstance(pyRepresentation, (PyObject*)type->pyType());
if (isinst == -1) {
isinst = 0;
PyErr_Clear();
}
return isinst > 0;
}
static PyObject* extractPythonObjectConcrete(PythonObjectOfType* valueType, instance_ptr data) {
return incref(*(PyObject**)data);
}
};