-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathJSObjectItemsProxy.hh
133 lines (114 loc) · 3.83 KB
/
JSObjectItemsProxy.hh
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
/**
* @file JSObjectItemsProxy.hh
* @author Philippe Laporte (philippe@distributive.network)
* @brief JSObjectItemsProxy is a custom C-implemented python type that derives from dict items
* @date 2024-01-19
*
* @copyright Copyright (c) 2024 Distributive Corp.
*
*/
#ifndef PythonMonkey_JSObjectItemsProxy_
#define PythonMonkey_JSObjectItemsProxy_
#include <jsapi.h>
#include <Python.h>
#include "include/pyshim.hh"
/**
* @brief The typedef for the backing store that will be used by JSObjectItemsProxy objects
*
*/
typedef struct {
_PyDictViewObject dv;
} JSObjectItemsProxy;
/**
* @brief This struct is a bundle of methods used by the JSObjectItemsProxy type
*
*/
struct JSObjectItemsProxyMethodDefinitions {
public:
/**
* @brief Deallocation method (.tp_dealloc), removes the reference to the underlying JSObject before freeing the JSObjectItemsProxy
*
* @param self - The JSObjectItemsProxy to be free'd
*/
static void JSObjectItemsProxy_dealloc(JSObjectItemsProxy *self);
/**
* @brief .tp_traverse method
*
* @param self - The JSObjectItemsProxy
* @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 JSObjectItemsProxy_traverse(JSObjectItemsProxy *self, visitproc visit, void *arg);
/**
* @brief .tp_clear method
*
* @param self - The JSObjectItemsProxy
* @return 0 on success
*/
static int JSObjectItemsProxy_clear(JSObjectItemsProxy *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 JSObjectItemsProxy_length(JSObjectItemsProxy *self);
/**
* @brief Return an iterator object to make JSObjectItemsProxy iterable, emitting (key, value) tuples
*
* @param self - The JSObjectItemsProxy
* @return PyObject* - iterator object
*/
static PyObject *JSObjectItemsProxy_iter(JSObjectItemsProxy *self);
/**
* @brief Compute a string representation of the JSObjectItemsProxy
*
* @param self - The JSObjectItemsProxy
* @return the string representation (a PyUnicodeObject) on success, NULL on failure
*/
static PyObject *JSObjectItemsProxy_repr(JSObjectItemsProxy *self);
/**
* @brief reverse iterator method
*
* @param self - The JSObjectItemsProxy
* @return PyObject* The resulting new dict
*/
static PyObject *JSObjectItemsProxy_iter_reverse(JSObjectItemsProxy *self);
/**
* @brief mapping method
*
* @param self - The JSObjectItemsProxy
* @param Py_UNUSED
* @return PyObject* The resulting new dict
*/
static PyObject *JSObjectItemsProxy_mapping(PyObject *self, void *Py_UNUSED(ignored));
};
/**
* @brief Struct for the methods that define the Sequence protocol
*
*/
static PySequenceMethods JSObjectItemsProxy_sequence_methods = {
.sq_length = (lenfunc)JSObjectItemsProxyMethodDefinitions::JSObjectItemsProxy_length,
// .sq_contains = TODO tuple support
};
PyDoc_STRVAR(items_reversed_keys_doc,
"Return a reverse iterator over the dict keys.");
/**
* @brief Struct for the other methods
*
*/
static PyMethodDef JSObjectItemsProxy_methods[] = {
// {"isdisjoint"}, // TODO tuple support
{"__reversed__", (PyCFunction)JSObjectItemsProxyMethodDefinitions::JSObjectItemsProxy_iter_reverse, METH_NOARGS, items_reversed_keys_doc},
{NULL, NULL} /* sentinel */
};
static PyGetSetDef JSObjectItemsProxy_getset[] = {
{"mapping", JSObjectItemsProxyMethodDefinitions::JSObjectItemsProxy_mapping, (setter)NULL, "dictionary that this view refers to", NULL},
{0}
};
/**
* @brief Struct for the JSObjectItemsProxyType, used by all JSObjectItemsProxy objects
*/
extern PyTypeObject JSObjectItemsProxyType;
#endif