PythonMonkey   v0.8.2 (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
258 static PyObject *JSArrayProxy_sort(JSArrayProxy *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames);
259
268 static int JSArrayProxy_traverse(JSArrayProxy *self, visitproc visit, void *arg);
269
276 static int JSArrayProxy_clear(JSArrayProxy *self);
277};
278
279
284static PyMappingMethods JSArrayProxy_mapping_methods = {
287 .mp_ass_subscript = (objobjargproc)JSArrayProxyMethodDefinitions::JSArrayProxy_assign_key
288};
289
294static PySequenceMethods JSArrayProxy_sequence_methods = {
299 .sq_inplace_concat = (binaryfunc)JSArrayProxyMethodDefinitions::JSArrayProxy_inplace_concat,
300 .sq_inplace_repeat = (ssizeargfunc)JSArrayProxyMethodDefinitions::JSArrayProxy_inplace_repeat
301};
302
303
304PyDoc_STRVAR(py_list_clear__doc__,
305 "clear($self, /)\n"
306 "--\n"
307 "\n"
308 "Remove all items from list.");
309
310PyDoc_STRVAR(list_copy__doc__,
311 "copy($self, /)\n"
312 "--\n"
313 "\n"
314 "Return a shallow copy of the list.");
315
316PyDoc_STRVAR(list_append__doc__,
317 "append($self, object, /)\n"
318 "--\n"
319 "\n"
320 "Append object to the end of the list.");
321
322PyDoc_STRVAR(list_insert__doc__,
323 "insert($self, index, object, /)\n"
324 "--\n"
325 "\n"
326 "Insert object before index.");
327
328PyDoc_STRVAR(py_list_extend__doc__,
329 "extend($self, iterable, /)\n"
330 "--\n"
331 "\n"
332 "Extend list by appending elements from the iterable.");
333
334PyDoc_STRVAR(list_pop__doc__,
335 "pop($self, index=-1, /)\n"
336 "--\n"
337 "\n"
338 "Remove and return item at index (default last).\n"
339 "\n"
340 "Raises IndexError if list is empty or index is out of range.");
341
342PyDoc_STRVAR(list_remove__doc__,
343 "remove($self, value, /)\n"
344 "--\n"
345 "\n"
346 "Remove first occurrence of value.\n"
347 "\n"
348 "Raises ValueError if the value is not present.");
349
350PyDoc_STRVAR(list_index__doc__,
351 "index($self, value, start=0, stop=sys.maxsize, /)\n"
352 "--\n"
353 "\n"
354 "Return first index of value.\n"
355 "\n"
356 "Raises ValueError if the value is not present.");
357
358
359PyDoc_STRVAR(list_count__doc__,
360 "count($self, value, /)\n"
361 "--\n"
362 "\n"
363 "Return number of occurrences of value.");
364
365PyDoc_STRVAR(list_reverse__doc__,
366 "reverse($self, /)\n"
367 "--\n"
368 "\n"
369 "Reverse *IN PLACE*.");
370
371PyDoc_STRVAR(list_sort__doc__,
372 "sort($self, /, *, key=None, reverse=False)\n"
373 "--\n"
374 "\n"
375 "Sort the list in ascending order and return None.\n"
376 "\n"
377 "The sort is in-place (i.e. the list itself is modified) and stable (i.e. the\n"
378 "order of two equal elements is maintained).\n"
379 "\n"
380 "If a key function is given, apply it once to each list item and sort them,\n"
381 "ascending or descending, according to their function values.\n"
382 "\n"
383 "The reverse flag can be set to sort in descending order.");
384
385PyDoc_STRVAR(list___reversed____doc__,
386 "__reversed__($self, /)\n"
387 "--\n"
388 "\n"
389 "Return a reverse iterator over the list.");
390
395static PyMethodDef JSArrayProxy_methods[] = {
396 {"__reversed__", (PyCFunction)JSArrayProxyMethodDefinitions::JSArrayProxy_iter_reverse, METH_NOARGS, list___reversed____doc__},
397 {"clear", (PyCFunction)JSArrayProxyMethodDefinitions::JSArrayProxy_clear_method, METH_NOARGS, py_list_clear__doc__},
398 {"copy", (PyCFunction)JSArrayProxyMethodDefinitions::JSArrayProxy_copy, METH_NOARGS, list_copy__doc__},
399 {"append", (PyCFunction)JSArrayProxyMethodDefinitions::JSArrayProxy_append, METH_O, list_append__doc__},
400 {"insert", (PyCFunction)JSArrayProxyMethodDefinitions::JSArrayProxy_insert, METH_FASTCALL, list_insert__doc__},
401 {"extend", (PyCFunction)JSArrayProxyMethodDefinitions::JSArrayProxy_extend, METH_O, py_list_extend__doc__},
402 {"pop", (PyCFunction)JSArrayProxyMethodDefinitions::JSArrayProxy_pop, METH_FASTCALL, list_pop__doc__},
403 {"remove", (PyCFunction)JSArrayProxyMethodDefinitions::JSArrayProxy_remove, METH_O, list_remove__doc__},
404 {"index", (PyCFunction)JSArrayProxyMethodDefinitions::JSArrayProxy_index, METH_FASTCALL, list_index__doc__},
405 {"count", (PyCFunction)JSArrayProxyMethodDefinitions::JSArrayProxy_count, METH_O, list_count__doc__},
406 {"reverse", (PyCFunction)JSArrayProxyMethodDefinitions::JSArrayProxy_reverse, METH_NOARGS, list_reverse__doc__},
407 {"sort", (PyCFunction)JSArrayProxyMethodDefinitions::JSArrayProxy_sort, METH_FASTCALL|METH_KEYWORDS, list_sort__doc__},
408 {NULL, NULL} /* sentinel */
409};
410
414extern PyTypeObject JSArrayProxyType;
415
416#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:189
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:1043
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:48
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:55
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:98
static PyObject * JSArrayProxy_copy(JSArrayProxy *self)
copy method
Definition JSArrayProxy.cc:765
static PyObject * JSArrayProxy_repr(JSArrayProxy *self)
Compute a string representation of the JSArrayProxy.
Definition JSArrayProxy.cc:513
static PyObject * JSArrayProxy_remove(JSArrayProxy *self, PyObject *value)
remove method Remove first occurrence of value
Definition JSArrayProxy.cc:954
static int JSArrayProxy_contains(JSArrayProxy *self, PyObject *element)
Test contains method (.sq_contains)
Definition JSArrayProxy.cc:689
static PyObject * JSArrayProxy_sort(JSArrayProxy *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
sort method sort in place
Definition JSArrayProxy.cc:1182
static PyObject * JSArrayProxy_inplace_repeat(JSArrayProxy *self, Py_ssize_t n)
inplace_repeat method (.sq_inplace_repeat), repeats in_place
Definition JSArrayProxy.cc:727
static PyObject * JSArrayProxy_pop(JSArrayProxy *self, PyObject *const *args, Py_ssize_t nargs)
pop method
Definition JSArrayProxy.cc:899
static PyObject * JSArrayProxy_index(JSArrayProxy *self, PyObject *const *args, Py_ssize_t nargs)
index method
Definition JSArrayProxy.cc:985
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:416
static PyObject * JSArrayProxy_append(JSArrayProxy *self, PyObject *value)
append method
Definition JSArrayProxy.cc:777
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:265
static void JSArrayProxy_dealloc(JSArrayProxy *self)
Deallocation method (.tp_dealloc), removes the reference to the underlying JSObject before freeing th...
Definition JSArrayProxy.cc:28
static PyObject * JSArrayProxy_iter(JSArrayProxy *self)
Return an iterator object to make JSArrayProxy iterable.
Definition JSArrayProxy.cc:581
static PyObject * JSArrayProxy_reverse(JSArrayProxy *self)
reverse method Reverse list in place
Definition JSArrayProxy.cc:1065
static PyObject * JSArrayProxy_clear_method(JSArrayProxy *self)
clear method, empties the array
Definition JSArrayProxy.cc:760
static int JSArrayProxy_clear(JSArrayProxy *self)
tp_clear
Definition JSArrayProxy.cc:42
static PyObject * JSArrayProxy_extend(JSArrayProxy *self, PyObject *iterable)
extend method
Definition JSArrayProxy.cc:836
static int JSArrayProxy_traverse(JSArrayProxy *self, visitproc visit, void *arg)
tp_traverse
Definition JSArrayProxy.cc:36
static PyObject * JSArrayProxy_repeat(JSArrayProxy *self, Py_ssize_t n)
repeat method (.sq_repeat), repeat self n number of time
Definition JSArrayProxy.cc:662
static PyObject * JSArrayProxy_inplace_concat(JSArrayProxy *self, PyObject *value)
inplace_concat method (.sq_inplace_concat), concatenates in_place
Definition JSArrayProxy.cc:707
static PyObject * JSArrayProxy_insert(JSArrayProxy *self, PyObject *const *args, Py_ssize_t nargs)
insert method
Definition JSArrayProxy.cc:787
static PyObject * JSArrayProxy_concat(JSArrayProxy *self, PyObject *value)
concat method (.sq_concat), concatenates
Definition JSArrayProxy.cc:607
static PyObject * JSArrayProxy_iter_reverse(JSArrayProxy *self)
Return a reverse iterator object to make JSArrayProxy backwards iterable.
Definition JSArrayProxy.cc:594
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