-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathJSObjectValuesProxy.hh
More file actions
141 lines (121 loc) · 4.25 KB
/
JSObjectValuesProxy.hh
File metadata and controls
141 lines (121 loc) · 4.25 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/**
* @file JSObjectValuesProxy.hh
* @author Philippe Laporte (philippe@distributive.network)
* @brief JSObjectValuesProxy is a custom C-implemented python type that derives from dict values
* @date 2024-01-17
*
* @copyright Copyright (c) 2023 Distributive Corp.
*
*/
#ifndef PythonMonkey_JSObjectValuesProxy_
#define PythonMonkey_JSObjectValuesProxy_
#include <jsapi.h>
#include <Python.h>
#include "include/pyshim.hh"
/**
* @brief The typedef for the backing store that will be used by JSObjectValuesProxy objects
*
*/
typedef struct {
_PyDictViewObject dv;
} JSObjectValuesProxy;
/**
* @brief This struct is a bundle of methods used by the JSObjectValuesProxy type
*
*/
struct JSObjectValuesProxyMethodDefinitions {
public:
/**
* @brief Deallocation method (.tp_dealloc), removes the reference to the underlying JSObject before freeing the JSObjectValuesProxy
*
* @param self - The JSObjectValuesProxy to be free'd
*/
static void JSObjectValuesProxy_dealloc(JSObjectValuesProxy *self);
/**
* @brief .tp_traverse method
*
* @param self - The JSObjectValuesProxy
* @param visit - The function to be applied on each element of the list
* @param arg - The argument to the visit function
* @return 0 on success
*/
static int JSObjectValuesProxy_traverse(JSObjectValuesProxy *self, visitproc visit, void *arg);
/**
* @brief .tp_clear method
*
* @param self - The JSObjectValuesProxy
* @return 0 on success
*/
static int JSObjectValuesProxy_clear(JSObjectValuesProxy *self);
/**
* @brief Length method (.sq_length), returns the number of key-value pairs in the JSObject, used by the python len() method
*
* @param self - The JSObjectProxy
* @return Py_ssize_t The length of the JSObjectProxy
*/
static Py_ssize_t JSObjectValuesProxy_length(JSObjectValuesProxy *self);
/**
* @brief Test method (.sq_contains), returns whether a key exists, used by the in operator
*
* @param self - The JSObjectValuesProxy
* @param key - The key for the value in the JSObjectValuesProxy
* @return int 1 if `key` is in dict, 0 if not, and -1 on error
*/
static int JSObjectValuesProxy_contains(JSObjectValuesProxy *self, PyObject *key);
/**
* @brief Return an iterator object to make JSObjectValuesProxy iterable, emitting (key, value) tuples
*
* @param self - The JSObjectValuesProxy
* @return PyObject* - iterator object
*/
static PyObject *JSObjectValuesProxy_iter(JSObjectValuesProxy *self);
/**
* @brief Compute a string representation of the JSObjectValuesProxy
*
* @param self - The JSObjectValuesProxy
* @return the string representation (a PyUnicodeObject) on success, NULL on failure
*/
static PyObject *JSObjectValuesProxy_repr(JSObjectValuesProxy *self);
/**
* @brief reverse iterator method
*
* @param self - The JSObjectValuesProxy
* @return PyObject* The resulting new dict
*/
static PyObject *JSObjectValuesProxy_iter_reverse(JSObjectValuesProxy *self);
/**
* @brief mapping method
*
* @param self - The JSObjectValuesProxy
* @param Py_UNUSED
* @return PyObject* The resulting new dict
*/
static PyObject *JSObjectValuesProxy_mapping(PyObject *self, void *Py_UNUSED(ignored));
};
/**
* @brief Struct for the methods that define the Sequence protocol
*
*/
static PySequenceMethods JSObjectValuesProxy_sequence_methods = {
.sq_length = (lenfunc)JSObjectValuesProxyMethodDefinitions::JSObjectValuesProxy_length,
.sq_contains = (objobjproc)JSObjectValuesProxyMethodDefinitions::JSObjectValuesProxy_contains
};
PyDoc_STRVAR(reversed_values_doc,
"Return a reverse iterator over the dict values.");
/**
* @brief Struct for the other methods
*
*/
static PyMethodDef JSObjectValuesProxy_methods[] = {
{"__reversed__", (PyCFunction)JSObjectValuesProxyMethodDefinitions::JSObjectValuesProxy_iter_reverse, METH_NOARGS, reversed_values_doc},
{NULL, NULL} /* sentinel */
};
static PyGetSetDef JSObjectValuesProxy_getset[] = {
{"mapping", JSObjectValuesProxyMethodDefinitions::JSObjectValuesProxy_mapping, (setter)NULL, "dictionary that this view refers to", NULL},
{0}
};
/**
* @brief Struct for the JSObjectValuesProxyType, used by all JSObjectValuesProxy objects
*/
extern PyTypeObject JSObjectValuesProxyType;
#endif