|
1 | 1 | /** |
2 | 2 | * @file BufferType.hh |
3 | | - * @author Tom Tang ([email protected]) |
| 3 | + * @author Tom Tang ([email protected]) and Philippe Laporte ([email protected]) |
4 | 4 | * @brief Struct for representing ArrayBuffers |
5 | 5 | * @date 2023-04-27 |
6 | 6 | * |
7 | | - * @copyright Copyright (c) 2023 Distributive Corp. |
| 7 | + * @copyright Copyright (c) 2023,2024 Distributive Corp. |
8 | 8 | * |
9 | 9 | */ |
10 | 10 |
|
11 | 11 | #ifndef PythonMonkey_BufferType_ |
12 | 12 | #define PythonMonkey_BufferType_ |
13 | 13 |
|
14 | | -#include "PyType.hh" |
15 | | -#include "TypeEnum.hh" |
16 | | - |
17 | 14 | #include <jsapi.h> |
18 | 15 | #include <js/ScalarType.h> |
19 | 16 |
|
20 | 17 | #include <Python.h> |
21 | 18 |
|
22 | | -struct BufferType : public PyType { |
| 19 | +struct BufferType { |
23 | 20 | public: |
24 | | - BufferType(PyObject *object); |
25 | | - |
26 | 21 | /** |
27 | 22 | * @brief Construct a new BufferType object from a JS TypedArray or ArrayBuffer, as a Python [memoryview](https://docs.python.org/3.9/c-api/memoryview.html) object |
28 | 23 | * |
29 | 24 | * @param cx - javascript context pointer |
30 | 25 | * @param bufObj - JS object to be coerced |
| 26 | + * |
| 27 | + * @returns PyObject* pointer to the resulting PyObject |
31 | 28 | */ |
32 | | - BufferType(JSContext *cx, JS::HandleObject bufObj); |
33 | | - |
34 | | - const TYPE returnType = TYPE::BUFFER; |
| 29 | + static PyObject *getPyObject(JSContext *cx, JS::HandleObject bufObj); |
35 | 30 |
|
36 | 31 | /** |
37 | 32 | * @brief Convert a Python object that [provides the buffer interface](https://docs.python.org/3.9/c-api/typeobj.html#buffer-object-structures) to JS TypedArray. |
38 | 33 | * The subtype (Uint8Array, Float64Array, ...) is automatically determined by the Python buffer's [format](https://docs.python.org/3.9/c-api/buffer.html#c.Py_buffer.format) |
39 | 34 | * |
40 | 35 | * @param cx - javascript context pointer |
41 | 36 | */ |
42 | | - JSObject *toJsTypedArray(JSContext *cx); |
| 37 | + static JSObject *toJsTypedArray(JSContext *cx, PyObject *pyObject); |
43 | 38 |
|
44 | 39 | /** |
45 | 40 | * @returns Is the given JS object either a TypedArray or an ArrayBuffer? |
|
0 commit comments