PythonMonkey   v1.0.1 (dev)
Loading...
Searching...
No Matches
JSArrayProxy.hh
Go to the documentation of this file.
1
12#ifndef PythonMonkey_JSArrayProxy_
13#define PythonMonkey_JSArrayProxy_
14
15
16#include <jsapi.h>
17
18#include <Python.h>
19
20
25typedef struct {
26 PyListObject list;
27 JS::PersistentRootedObject *jsArray;
29
35public:
41 static void JSArrayProxy_dealloc(JSArrayProxy *self);
42
49 static Py_ssize_t JSArrayProxy_length(JSArrayProxy *self);
50
58 static PyObject *JSArrayProxy_get(JSArrayProxy *self, PyObject *key);
59
60
68 static PyObject *JSArrayProxy_get_subscript(JSArrayProxy *self, PyObject *key);
69
78 static int JSArrayProxy_assign_key(JSArrayProxy *self, PyObject *key, PyObject *value);
79
88 static PyObject *JSArrayProxy_richcompare(JSArrayProxy *self, PyObject *other, int op);
89
96 static PyObject *JSArrayProxy_iter(JSArrayProxy *self);
97
104 static PyObject *JSArrayProxy_iter_reverse(JSArrayProxy *self);
105
112 static PyObject *JSArrayProxy_repr(JSArrayProxy *self);
113
121 static PyObject *JSArrayProxy_concat(JSArrayProxy *self, PyObject *value);
122
130 static PyObject *JSArrayProxy_repeat(JSArrayProxy *self, Py_ssize_t n);
131
139 static int JSArrayProxy_contains(JSArrayProxy *self, PyObject *element);
140
148 static PyObject *JSArrayProxy_inplace_concat(JSArrayProxy *self, PyObject *value);
149
157 static PyObject *JSArrayProxy_inplace_repeat(JSArrayProxy *self, Py_ssize_t n);
158
165 static PyObject *JSArrayProxy_clear_method(JSArrayProxy *self);
166
173 static PyObject *JSArrayProxy_copy(JSArrayProxy *self);
174
182 static PyObject *JSArrayProxy_append(JSArrayProxy *self, PyObject *value);
183
192 static PyObject *JSArrayProxy_insert(JSArrayProxy *self, PyObject *const *args, Py_ssize_t nargs);
193
201 static PyObject *JSArrayProxy_extend(JSArrayProxy *self, PyObject *iterable);
202
211 static PyObject *JSArrayProxy_pop(JSArrayProxy *self, PyObject *const *args, Py_ssize_t nargs);
212
220 static PyObject *JSArrayProxy_remove(JSArrayProxy *self, PyObject *value);
221
230 static PyObject *JSArrayProxy_index(JSArrayProxy *self, PyObject *const *args, Py_ssize_t nargs);
231
239 static PyObject *JSArrayProxy_count(JSArrayProxy *self, PyObject *value);
240
247 static PyObject *JSArrayProxy_reverse(JSArrayProxy *self);
248
257 static PyObject *JSArrayProxy_sort(JSArrayProxy *self, PyObject *args, PyObject *kwargs);
258
267 static int JSArrayProxy_traverse(JSArrayProxy *self, visitproc visit, void *arg);
268
275 static int JSArrayProxy_clear(JSArrayProxy *self);
276};
277
278
283static PyMappingMethods JSArrayProxy_mapping_methods = {
286 .mp_ass_subscript = (objobjargproc)JSArrayProxyMethodDefinitions::JSArrayProxy_assign_key
287};
288
293static PySequenceMethods JSArrayProxy_sequence_methods = {
298 .sq_inplace_concat = (binaryfunc)JSArrayProxyMethodDefinitions::JSArrayProxy_inplace_concat,
299 .sq_inplace_repeat = (ssizeargfunc)JSArrayProxyMethodDefinitions::JSArrayProxy_inplace_repeat
300};
301
302
303PyDoc_STRVAR(py_list_clear__doc__,
304 "clear($self, /)\n"
305 "--\n"
306 "\n"
307 "Remove all items from list.");
308
309PyDoc_STRVAR(list_copy__doc__,
310 "copy($self, /)\n"
311 "--\n"
312 "\n"
313 "Return a shallow copy of the list.");
314
315PyDoc_STRVAR(list_append__doc__,
316 "append($self, object, /)\n"
317 "--\n"
318 "\n"
319 "Append object to the end of the list.");
320
321PyDoc_STRVAR(list_insert__doc__,
322 "insert($self, index, object, /)\n"
323 "--\n"
324 "\n"
325 "Insert object before index.");
326
327PyDoc_STRVAR(py_list_extend__doc__,
328 "extend($self, iterable, /)\n"
329 "--\n"
330 "\n"
331 "Extend list by appending elements from the iterable.");
332
333PyDoc_STRVAR(list_pop__doc__,
334 "pop($self, index=-1, /)\n"
335 "--\n"
336 "\n"
337 "Remove and return item at index (default last).\n"
338 "\n"
339 "Raises IndexError if list is empty or index is out of range.");
340
341PyDoc_STRVAR(list_remove__doc__,
342 "remove($self, value, /)\n"
343 "--\n"
344 "\n"
345 "Remove first occurrence of value.\n"
346 "\n"
347 "Raises ValueError if the value is not present.");
348
349PyDoc_STRVAR(list_index__doc__,
350 "index($self, value, start=0, stop=sys.maxsize, /)\n"
351 "--\n"
352 "\n"
353 "Return first index of value.\n"
354 "\n"
355 "Raises ValueError if the value is not present.");
356
357
358PyDoc_STRVAR(list_count__doc__,
359 "count($self, value, /)\n"
360 "--\n"
361 "\n"
362 "Return number of occurrences of value.");
363
364PyDoc_STRVAR(list_reverse__doc__,
365 "reverse($self, /)\n"
366 "--\n"
367 "\n"
368 "Reverse *IN PLACE*.");
369
370PyDoc_STRVAR(list_sort__doc__,
371 "sort($self, /, *, key=None, reverse=False)\n"
372 "--\n"
373 "\n"
374 "Sort the list in ascending order and return None.\n"
375 "\n"
376 "The sort is in-place (i.e. the list itself is modified) and stable (i.e. the\n"
377 "order of two equal elements is maintained).\n"
378 "\n"
379 "If a key function is given, apply it once to each list item and sort them,\n"
380 "ascending or descending, according to their function values.\n"
381 "\n"
382 "The reverse flag can be set to sort in descending order.");
383
384PyDoc_STRVAR(list___reversed____doc__,
385 "__reversed__($self, /)\n"
386 "--\n"
387 "\n"
388 "Return a reverse iterator over the list.");
389
394static PyMethodDef JSArrayProxy_methods[] = {
395 {"__reversed__", (PyCFunction)JSArrayProxyMethodDefinitions::JSArrayProxy_iter_reverse, METH_NOARGS, list___reversed____doc__},
396 {"clear", (PyCFunction)JSArrayProxyMethodDefinitions::JSArrayProxy_clear_method, METH_NOARGS, py_list_clear__doc__},
397 {"copy", (PyCFunction)JSArrayProxyMethodDefinitions::JSArrayProxy_copy, METH_NOARGS, list_copy__doc__},
398 {"append", (PyCFunction)JSArrayProxyMethodDefinitions::JSArrayProxy_append, METH_O, list_append__doc__},
399 {"insert", (PyCFunction)JSArrayProxyMethodDefinitions::JSArrayProxy_insert, METH_FASTCALL, list_insert__doc__},
400 {"extend", (PyCFunction)JSArrayProxyMethodDefinitions::JSArrayProxy_extend, METH_O, py_list_extend__doc__},
401 {"pop", (PyCFunction)JSArrayProxyMethodDefinitions::JSArrayProxy_pop, METH_FASTCALL, list_pop__doc__},
402 {"remove", (PyCFunction)JSArrayProxyMethodDefinitions::JSArrayProxy_remove, METH_O, list_remove__doc__},
403 {"index", (PyCFunction)JSArrayProxyMethodDefinitions::JSArrayProxy_index, METH_FASTCALL, list_index__doc__},
404 {"count", (PyCFunction)JSArrayProxyMethodDefinitions::JSArrayProxy_count, METH_O, list_count__doc__},
405 {"reverse", (PyCFunction)JSArrayProxyMethodDefinitions::JSArrayProxy_reverse, METH_NOARGS, list_reverse__doc__},
406 {"sort", (PyCFunction)JSArrayProxyMethodDefinitions::JSArrayProxy_sort, METH_VARARGS|METH_KEYWORDS, list_sort__doc__},
407 {NULL, NULL} /* sentinel */
408};
409
413extern PyTypeObject JSArrayProxyType;
414
415#endif
PyDoc_STRVAR(py_list_clear__doc__, "clear($self, /)\n" "--\n" "\n" "Remove all items from list.")
PyTypeObject JSArrayProxyType
Struct for the JSArrayProxyType, used by all JSArrayProxy objects.
Definition pythonmonkey.cc:190
This struct is a bundle of methods used by the JSArrayProxy type.
Definition JSArrayProxy.hh:34
static PyObject * JSArrayProxy_count(JSArrayProxy *self, PyObject *value)
count method
Definition JSArrayProxy.cc:1044
static Py_ssize_t JSArrayProxy_length(JSArrayProxy *self)
Length method (.mp_length and .sq_length), returns the number of keys in the JSObject,...
Definition JSArrayProxy.cc:49
static PyObject * JSArrayProxy_get(JSArrayProxy *self, PyObject *key)
returns a value from the JSArrayProxy given a key, or dispatches to the given key method if such meth...
Definition JSArrayProxy.cc:56
static PyObject * JSArrayProxy_sort(JSArrayProxy *self, PyObject *args, PyObject *kwargs)
sort method sort in place
Definition JSArrayProxy.cc:1183
static PyObject * JSArrayProxy_get_subscript(JSArrayProxy *self, PyObject *key)
Getter method (.mp_subscript), returns a value from the JSArrayProxy given a key which can be a slice...
Definition JSArrayProxy.cc:99
static PyObject * JSArrayProxy_copy(JSArrayProxy *self)
copy method
Definition JSArrayProxy.cc:766
static PyObject * JSArrayProxy_repr(JSArrayProxy *self)
Compute a string representation of the JSArrayProxy.
Definition JSArrayProxy.cc:514
static PyObject * JSArrayProxy_remove(JSArrayProxy *self, PyObject *value)
remove method Remove first occurrence of value
Definition JSArrayProxy.cc:955
static int JSArrayProxy_contains(JSArrayProxy *self, PyObject *element)
Test contains method (.sq_contains)
Definition JSArrayProxy.cc:690
static PyObject * JSArrayProxy_inplace_repeat(JSArrayProxy *self, Py_ssize_t n)
inplace_repeat method (.sq_inplace_repeat), repeats in_place
Definition JSArrayProxy.cc:728
static PyObject * JSArrayProxy_pop(JSArrayProxy *self, PyObject *const *args, Py_ssize_t nargs)
pop method
Definition JSArrayProxy.cc:900
static PyObject * JSArrayProxy_index(JSArrayProxy *self, PyObject *const *args, Py_ssize_t nargs)
index method
Definition JSArrayProxy.cc:986
static PyObject * JSArrayProxy_richcompare(JSArrayProxy *self, PyObject *other, int op)
Comparison method (.tp_richcompare), returns appropriate boolean given a comparison operator and othe...
Definition JSArrayProxy.cc:417
static PyObject * JSArrayProxy_append(JSArrayProxy *self, PyObject *value)
append method
Definition JSArrayProxy.cc:778
static int JSArrayProxy_assign_key(JSArrayProxy *self, PyObject *key, PyObject *value)
Assign method (.mp_ass_subscript), assigns a key-value pair if value is non-NULL, or deletes a key-va...
Definition JSArrayProxy.cc:266
static void JSArrayProxy_dealloc(JSArrayProxy *self)
Deallocation method (.tp_dealloc), removes the reference to the underlying JSObject before freeing th...
Definition JSArrayProxy.cc:29
static PyObject * JSArrayProxy_iter(JSArrayProxy *self)
Return an iterator object to make JSArrayProxy iterable.
Definition JSArrayProxy.cc:582
static PyObject * JSArrayProxy_reverse(JSArrayProxy *self)
reverse method Reverse list in place
Definition JSArrayProxy.cc:1066
static PyObject * JSArrayProxy_clear_method(JSArrayProxy *self)
clear method, empties the array
Definition JSArrayProxy.cc:761
static int JSArrayProxy_clear(JSArrayProxy *self)
tp_clear
Definition JSArrayProxy.cc:43
static PyObject * JSArrayProxy_extend(JSArrayProxy *self, PyObject *iterable)
extend method
Definition JSArrayProxy.cc:837
static int JSArrayProxy_traverse(JSArrayProxy *self, visitproc visit, void *arg)
tp_traverse
Definition JSArrayProxy.cc:37
static PyObject * JSArrayProxy_repeat(JSArrayProxy *self, Py_ssize_t n)
repeat method (.sq_repeat), repeat self n number of time
Definition JSArrayProxy.cc:663
static PyObject * JSArrayProxy_inplace_concat(JSArrayProxy *self, PyObject *value)
inplace_concat method (.sq_inplace_concat), concatenates in_place
Definition JSArrayProxy.cc:708
static PyObject * JSArrayProxy_insert(JSArrayProxy *self, PyObject *const *args, Py_ssize_t nargs)
insert method
Definition JSArrayProxy.cc:788
static PyObject * JSArrayProxy_concat(JSArrayProxy *self, PyObject *value)
concat method (.sq_concat), concatenates
Definition JSArrayProxy.cc:608
static PyObject * JSArrayProxy_iter_reverse(JSArrayProxy *self)
Return a reverse iterator object to make JSArrayProxy backwards iterable.
Definition JSArrayProxy.cc:595
The typedef for the backing store that will be used by JSArrayProxy objects. All it contains is a poi...
Definition JSArrayProxy.hh:25
JS::PersistentRootedObject * jsArray
Definition JSArrayProxy.hh:27
PyListObject list
Definition JSArrayProxy.hh:26