-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathPothosModule.hpp
More file actions
92 lines (74 loc) · 2.83 KB
/
PothosModule.hpp
File metadata and controls
92 lines (74 loc) · 2.83 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
// Copyright (c) 2014-2016 Josh Blum
// SPDX-License-Identifier: BSL-1.0
#include "../PyObjectUtils.hpp"
#include <Pothos/Proxy.hpp>
//! Module utility to convert between forms
Pothos::Proxy PyObjectToProxy(PyObject *obj);
//! Module utility to convert between forms
PyObject *ProxyToPyObject(const Pothos::Proxy &proxy);
//! Access the proxy environment for python
Pothos::ProxyEnvironment::Sptr getPythonProxyEnv(void);
//! Convert a proxy from one env into another
inline Pothos::Proxy proxyEnvTranslate(const Pothos::Proxy &proxy, const Pothos::ProxyEnvironment::Sptr &env)
{
if (proxy.getEnvironment() == env) return proxy;
return env->convertObjectToProxy(proxy.toObject());
}
void registerPothosModuleConverters(void);
/***********************************************************************
* Pothos::ProxyEnvironment support
**********************************************************************/
struct ProxyEnvironmentObject
{
PyObject_HEAD
Pothos::ProxyEnvironment::Sptr *env;
};
//! called by module to register type
void registerProxyEnvironmentType(PyObject *m);
//! utility for c api to construct a proxy env
PyObject *makeProxyEnvironmentObject(const Pothos::ProxyEnvironment::Sptr &env);
//! utility for c api to check if a proxy env
bool isProxyEnvironmentObject(PyObject *obj);
/***********************************************************************
* Pothos::Proxy support
**********************************************************************/
struct ProxyObject
{
PyObject_HEAD
Pothos::Proxy *proxy;
};
//! called by module to register type
void registerProxyType(PyObject *m);
//! utility for c api to construct a proxy
PyObject *makeProxyObject(const Pothos::Proxy &proxy);
//! utility for c api to check if a proxy
bool isProxyObject(PyObject *obj);
/***********************************************************************
* Pothos::ProxyCall support
**********************************************************************/
struct ProxyCallObject
{
PyObject_HEAD
PyObjectRef *proxy;
PyObjectRef *name;
};
//! called by module to register type
void registerProxyCallType(PyObject *m);
//! utility for c api to construct a proxy call object
PyObject *makeProxyCallObject(PyObject *args);
/***********************************************************************
* rich compare support for old-style cmp
**********************************************************************/
inline PyObject *richCompareFromSimple(const int cmp, const int opid)
{
switch(opid)
{
case Py_LT: return PyBool_FromLong(cmp < 0);
case Py_LE: return PyBool_FromLong(cmp <= 0);
case Py_EQ: return PyBool_FromLong(cmp == 0);
case Py_NE: return PyBool_FromLong(cmp != 0);
case Py_GT: return PyBool_FromLong(cmp > 0);
case Py_GE: return PyBool_FromLong(cmp >= 0);
default: return PyBool_FromLong(0);
}
}