forked from ChunelFeng/CGraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPyWrapperMacro.h
More file actions
89 lines (76 loc) · 5.61 KB
/
Copy pathPyWrapperMacro.h
File metadata and controls
89 lines (76 loc) · 5.61 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
/***************************
@Author: Chunel
@Contact: chunel@foxmail.com
@File: PyWrapperDefine.h
@Time: 2025/4/6 14:48
@Desc:
***************************/
#ifndef CGRAPH_PYWRAPPERDEFINE_H
#define CGRAPH_PYWRAPPERDEFINE_H
#include <pybind11/pybind11.h>
#include "CGraph.h"
#define PYCGRAPH_DECLARE_GELEMENT_COMMON_FUNCTIONS(PCGE) \
CBool isHold() override { \
PYBIND11_OVERLOAD(CBool, PCGE, isHold); \
} \
\
CBool isMatch() override { \
PYBIND11_OVERLOAD(CBool, PCGE, isMatch); \
} \
\
CStatus prepareRun() override { \
PYBIND11_OVERLOAD(CStatus, PCGE, prepareRun); \
} \
\
CStatus checkRunResult() override { \
PYBIND11_OVERLOAD(CStatus, PCGE, checkRunResult); \
} \
\
#define PYCGRAPH_DECLARE_GGROUP_INTERFACE_CLASS(PCGG, PVFunc) \
class PCGG##Interface : public PCGG { \
public: \
explicit PCGG##Interface(const CGraph::GElementPtrArr& elements = CGraph::GElementPtrArr{}) : PCGG(elements) {}; \
~PCGG##Interface() override = default; \
protected: \
PYCGRAPH_DECLARE_GELEMENT_COMMON_FUNCTIONS(PCGG) \
PVFunc \
}; \
\
#define PYCGRAPH_DECLARE_GGROUP_PYBIND11_FUNCTIONS(PCGG) \
py::class_<Pyw##PCGG, GElement, Pyw##PCGG##Interface, std::unique_ptr<Pyw##PCGG, py::nodelete> >(cg, #PCGG) \
.def(py::init<const GElementPtrArr&>(), \
py::arg("elements") = GElementPtrArr{}, \
py::keep_alive<1, 2>()) \
.def("addGElements", &Pyw##PCGG::__addGElements_4py, \
py::arg("elements"), \
py::keep_alive<1, 2>()) \
\
#define PYCGRAPH_DEF_GPARAM_PYBIND11_FUNCTIONS(PCGO) \
def("createGParam", &PCGO::__createGParam_4py, \
py::arg("param"), \
py::arg("key"), \
py::keep_alive<1, 2>(), \
py::call_guard<py::gil_scoped_release>()) \
.def("getGParam", &PCGO::__getGParam_4py, \
py::arg("key")) \
.def("getGParamWithNoEmpty", &PCGO::__getGParamWithNoEmpty_4py, \
py::arg("key")) \
.def("removeGParam", &PCGO::__removeGParam_4py, \
py::arg("key"), \
py::call_guard<py::gil_scoped_release>()) \
.def("hasGParam", &PCGO::__hasGParam_4py, \
py::arg("key"), \
py::call_guard<py::gil_scoped_release>()) \
\
#define PYCGRAPH_DEF_GEVENT_PYBIND11_FUNCTIONS(PCGO) \
def("notify", &PCGO::__notify_4py, \
py::arg("key"), \
py::arg("type"), \
py::arg("strategy") = GEventAsyncStrategy::PIPELINE_RUN_FINISH, \
py::call_guard<py::gil_scoped_release>()) \
.def("asyncNotify", &PCGO::__asyncNotify_4py, \
py::arg("key"), \
py::arg("strategy") = GEventAsyncStrategy::PIPELINE_RUN_FINISH, \
py::call_guard<py::gil_scoped_release>()) \
\
#endif //CGRAPH_PYWRAPPERDEFINE_H