PythonMonkey   v0.3.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::RootedObject jsArray;
29
35public:
41 static void JSArrayProxy_dealloc(JSArrayProxy *self);
42
51 static PyObject *JSArrayProxy_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
52
61 static int JSArrayProxy_init(JSArrayProxy *self, PyObject *args, PyObject *kwds);
62
69 static Py_ssize_t JSArrayProxy_length(JSArrayProxy *self);
70
78 static PyObject *JSArrayProxy_get(JSArrayProxy *self, PyObject *key);
79
80
88 static PyObject *JSArrayProxy_get_subscript(JSArrayProxy *self, PyObject *key);
89
98 static int JSArrayProxy_assign_key(JSArrayProxy *self, PyObject *key, PyObject *value);
99
108 static PyObject *JSArrayProxy_richcompare(JSArrayProxy *self, PyObject *other, int op);
109
116 static PyObject *JSArrayProxy_iter(JSArrayProxy *self);
117
124 static PyObject *JSArrayProxy_iter_reverse(JSArrayProxy *self);
125
132 static PyObject *JSArrayProxy_repr(JSArrayProxy *self);
133
141 static PyObject *JSArrayProxy_concat(JSArrayProxy *self, PyObject *value);
142
150 static PyObject *JSArrayProxy_repeat(JSArrayProxy *self, Py_ssize_t n);
151
159 static int JSArrayProxy_contains(JSArrayProxy *self, PyObject *element);
160
168 static PyObject *JSArrayProxy_inplace_concat(JSArrayProxy *self, PyObject *value);
169
177 static PyObject *JSArrayProxy_inplace_repeat(JSArrayProxy *self, Py_ssize_t n);
178
185 static PyObject *JSArrayProxy_clear(JSArrayProxy *self);
186
193 static int JSArrayProxy_clear_slot(JSArrayProxy *self);
194
203 static int JSArrayProxy_traverse(JSArrayProxy *self, visitproc visit, void *arg);
204
211 static PyObject *JSArrayProxy_copy(JSArrayProxy *self);
212
220 static PyObject *JSArrayProxy_append(JSArrayProxy *self, PyObject *value);
221
230 static PyObject *JSArrayProxy_insert(JSArrayProxy *self, PyObject *const *args, Py_ssize_t nargs);
231
239 static PyObject *JSArrayProxy_extend(JSArrayProxy *self, PyObject *iterable);
240
249 static PyObject *JSArrayProxy_pop(JSArrayProxy *self, PyObject *const *args, Py_ssize_t nargs);
250
258 static PyObject *JSArrayProxy_remove(JSArrayProxy *self, PyObject *value);
259
268 static PyObject *JSArrayProxy_index(JSArrayProxy *self, PyObject *const *args, Py_ssize_t nargs);
269
277 static PyObject *JSArrayProxy_count(JSArrayProxy *self, PyObject *value);
278
285 static PyObject *JSArrayProxy_reverse(JSArrayProxy *self);
286
295 static PyObject *JSArrayProxy_sort(JSArrayProxy *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames);
296};
297
298
303static PyMappingMethods JSArrayProxy_mapping_methods = {
306 .mp_ass_subscript = (objobjargproc)JSArrayProxyMethodDefinitions::JSArrayProxy_assign_key
307};
308
313static PySequenceMethods JSArrayProxy_sequence_methods = {
318 .sq_inplace_concat = (binaryfunc)JSArrayProxyMethodDefinitions::JSArrayProxy_inplace_concat,
319 .sq_inplace_repeat = (ssizeargfunc)JSArrayProxyMethodDefinitions::JSArrayProxy_inplace_repeat
320};
321
322
323PyDoc_STRVAR(py_list_clear__doc__,
324 "clear($self, /)\n"
325 "--\n"
326 "\n"
327 "Remove all items from list.");
328
329PyDoc_STRVAR(list_copy__doc__,
330 "copy($self, /)\n"
331 "--\n"
332 "\n"
333 "Return a shallow copy of the list.");
334
335PyDoc_STRVAR(list_append__doc__,
336 "append($self, object, /)\n"
337 "--\n"
338 "\n"
339 "Append object to the end of the list.");
340
341PyDoc_STRVAR(list_insert__doc__,
342 "insert($self, index, object, /)\n"
343 "--\n"
344 "\n"
345 "Insert object before index.");
346
347PyDoc_STRVAR(py_list_extend__doc__,
348 "extend($self, iterable, /)\n"
349 "--\n"
350 "\n"
351 "Extend list by appending elements from the iterable.");
352
353PyDoc_STRVAR(list_pop__doc__,
354 "pop($self, index=-1, /)\n"
355 "--\n"
356 "\n"
357 "Remove and return item at index (default last).\n"
358 "\n"
359 "Raises IndexError if list is empty or index is out of range.");
360
361PyDoc_STRVAR(list_remove__doc__,
362 "remove($self, value, /)\n"
363 "--\n"
364 "\n"
365 "Remove first occurrence of value.\n"
366 "\n"
367 "Raises ValueError if the value is not present.");
368
369PyDoc_STRVAR(list_index__doc__,
370 "index($self, value, start=0, stop=sys.maxsize, /)\n"
371 "--\n"
372 "\n"
373 "Return first index of value.\n"
374 "\n"
375 "Raises ValueError if the value is not present.");
376
377
378PyDoc_STRVAR(list_count__doc__,
379 "count($self, value, /)\n"
380 "--\n"
381 "\n"
382 "Return number of occurrences of value.");
383
384PyDoc_STRVAR(list_reverse__doc__,
385 "reverse($self, /)\n"
386 "--\n"
387 "\n"
388 "Reverse *IN PLACE*.");
389
390PyDoc_STRVAR(list_sort__doc__,
391 "sort($self, /, *, key=None, reverse=False)\n"
392 "--\n"
393 "\n"
394 "Sort the list in ascending order and return None.\n"
395 "\n"
396 "The sort is in-place (i.e. the list itself is modified) and stable (i.e. the\n"
397 "order of two equal elements is maintained).\n"
398 "\n"
399 "If a key function is given, apply it once to each list item and sort them,\n"
400 "ascending or descending, according to their function values.\n"
401 "\n"
402 "The reverse flag can be set to sort in descending order.");
403
404PyDoc_STRVAR(list___reversed____doc__,
405 "__reversed__($self, /)\n"
406 "--\n"
407 "\n"
408 "Return a reverse iterator over the list.");
409
414static PyMethodDef JSArrayProxy_methods[] = {
415 {"__reversed__", (PyCFunction)JSArrayProxyMethodDefinitions::JSArrayProxy_iter_reverse, METH_NOARGS, list___reversed____doc__},
416 {"clear", (PyCFunction)JSArrayProxyMethodDefinitions::JSArrayProxy_clear, METH_NOARGS, py_list_clear__doc__},
417 {"copy", (PyCFunction)JSArrayProxyMethodDefinitions::JSArrayProxy_copy, METH_NOARGS, list_copy__doc__},
418 {"append", (PyCFunction)JSArrayProxyMethodDefinitions::JSArrayProxy_append, METH_O, list_append__doc__},
419 {"insert", (PyCFunction)JSArrayProxyMethodDefinitions::JSArrayProxy_insert, METH_FASTCALL, list_insert__doc__},
420 {"extend", (PyCFunction)JSArrayProxyMethodDefinitions::JSArrayProxy_extend, METH_O, py_list_extend__doc__},
421 {"pop", (PyCFunction)JSArrayProxyMethodDefinitions::JSArrayProxy_pop, METH_FASTCALL, list_pop__doc__},
422 {"remove", (PyCFunction)JSArrayProxyMethodDefinitions::JSArrayProxy_remove, METH_O, list_remove__doc__},
423 {"index", (PyCFunction)JSArrayProxyMethodDefinitions::JSArrayProxy_index, METH_FASTCALL, list_index__doc__},
424 {"count", (PyCFunction)JSArrayProxyMethodDefinitions::JSArrayProxy_count, METH_O, list_count__doc__},
425 {"reverse", (PyCFunction)JSArrayProxyMethodDefinitions::JSArrayProxy_reverse, METH_NOARGS, list_reverse__doc__},
426 {"sort", (PyCFunction)JSArrayProxyMethodDefinitions::JSArrayProxy_sort, METH_FASTCALL|METH_KEYWORDS, list_sort__doc__},
427 {NULL, NULL} /* sentinel */
428};
429
433extern PyTypeObject JSArrayProxyType;
434
435#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:100
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:1041
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:45
static int JSArrayProxy_init(JSArrayProxy *self, PyObject *args, PyObject *kwds)
Initialization method (.tp_init), initializes a newly created instance of JSArrayProxy....
Definition JSArrayProxy.cc:39
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:52
static int JSArrayProxy_clear_slot(JSArrayProxy *self)
.tp_clear method
Definition JSArrayProxy.cc:748
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:91
static PyObject * JSArrayProxy_copy(JSArrayProxy *self)
copy method
Definition JSArrayProxy.cc:763
static PyObject * JSArrayProxy_repr(JSArrayProxy *self)
Compute a string representation of the JSArrayProxy.
Definition JSArrayProxy.cc:498
static PyObject * JSArrayProxy_remove(JSArrayProxy *self, PyObject *value)
remove method Remove first occurrence of value
Definition JSArrayProxy.cc:952
static int JSArrayProxy_contains(JSArrayProxy *self, PyObject *element)
Test contains method (.sq_contains)
Definition JSArrayProxy.cc:673
static PyObject * JSArrayProxy_sort(JSArrayProxy *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
sort method sort in place
Definition JSArrayProxy.cc:1177
static PyObject * JSArrayProxy_inplace_repeat(JSArrayProxy *self, Py_ssize_t n)
inplace_repeat method (.sq_inplace_repeat), repeats in_place
Definition JSArrayProxy.cc:710
static PyObject * JSArrayProxy_pop(JSArrayProxy *self, PyObject *const *args, Py_ssize_t nargs)
pop method
Definition JSArrayProxy.cc:897
static PyObject * JSArrayProxy_index(JSArrayProxy *self, PyObject *const *args, Py_ssize_t nargs)
index method
Definition JSArrayProxy.cc:983
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:410
static PyObject * JSArrayProxy_append(JSArrayProxy *self, PyObject *value)
append method
Definition JSArrayProxy.cc:775
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:259
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_clear(JSArrayProxy *self)
clear method, empties the array
Definition JSArrayProxy.cc:743
static PyObject * JSArrayProxy_iter(JSArrayProxy *self)
Return an iterator object to make JSArrayProxy iterable.
Definition JSArrayProxy.cc:565
static PyObject * JSArrayProxy_reverse(JSArrayProxy *self)
reverse method Reverse list in place
Definition JSArrayProxy.cc:1063
static PyObject * JSArrayProxy_extend(JSArrayProxy *self, PyObject *iterable)
extend method
Definition JSArrayProxy.cc:834
static int JSArrayProxy_traverse(JSArrayProxy *self, visitproc visit, void *arg)
.tp_traverse method
Definition JSArrayProxy.cc:753
static PyObject * JSArrayProxy_repeat(JSArrayProxy *self, Py_ssize_t n)
repeat method (.sq_repeat), repeat self n number of time
Definition JSArrayProxy.cc:646
static PyObject * JSArrayProxy_inplace_concat(JSArrayProxy *self, PyObject *value)
inplace_concat method (.sq_inplace_concat), concatenates in_place
Definition JSArrayProxy.cc:690
static PyObject * JSArrayProxy_insert(JSArrayProxy *self, PyObject *const *args, Py_ssize_t nargs)
insert method
Definition JSArrayProxy.cc:785
static PyObject * JSArrayProxy_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
New method (.tp_new), creates a new instance of the JSArrayProxy type, exposed as the new() method in...
Definition JSArrayProxy.cc:34
static PyObject * JSArrayProxy_concat(JSArrayProxy *self, PyObject *value)
concat method (.sq_concat), concatenates
Definition JSArrayProxy.cc:591
static PyObject * JSArrayProxy_iter_reverse(JSArrayProxy *self)
Return a reverse iterator object to make JSArrayProxy backwards iterable.
Definition JSArrayProxy.cc:578
The typedef for the backing store that will be used by JSArrayProxy objects. All it contains is a poi...
Definition JSArrayProxy.hh:25
PyListObject list
Definition JSArrayProxy.hh:26
JS::RootedObject jsArray
Definition JSArrayProxy.hh:27