1 /* Simple D-Bus types: Double and (with appropriate #defines) Float
3 * Copyright (C) 2006 Collabora Ltd. <http://www.collabora.co.uk/>
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without
8 * restriction, including without limitation the rights to use, copy,
9 * modify, merge, publish, distribute, sublicense, and/or sell copies
10 * of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
27 #include <structmember.h>
31 #include "dbus_bindings-internal.h"
32 #include "types-internal.h"
34 PyDoc_STRVAR(Double_tp_doc,
35 "A double-precision floating point number (a subtype of float).");
37 #ifdef WITH_DBUS_FLOAT32
38 PyDoc_STRVAR(Float_tp_doc,
39 "A single-precision floating point number (a subtype of float).");
42 PyTypeObject DBusPyDouble_Type = {
43 PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type))
55 0, /* tp_as_sequence */
56 0, /* tp_as_mapping */
63 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
64 Double_tp_doc, /* tp_doc */
67 0, /* tp_richcompare */
68 0, /* tp_weaklistoffset */
74 DEFERRED_ADDRESS(&DBusPythonFloatType), /* tp_base */
78 0, /* tp_dictoffset */
84 #ifdef WITH_DBUS_FLOAT32
86 PyTypeObject DBusPyFloat_Type = {
87 PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type))
99 0, /* tp_as_sequence */
100 0, /* tp_as_mapping */
106 0, /* tp_as_buffer */
107 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
108 Float_tp_doc, /* tp_doc */
111 0, /* tp_richcompare */
112 0, /* tp_weaklistoffset */
118 DEFERRED_ADDRESS(&DBusPythonFloatType), /* tp_base */
120 0, /* tp_descr_get */
121 0, /* tp_descr_set */
122 0, /* tp_dictoffset */
127 #endif /* defined(WITH_DBUS_FLOAT32) */
130 dbus_py_init_float_types(void)
132 DBusPyDouble_Type.tp_base = &DBusPyFloatBase_Type;
133 if (PyType_Ready(&DBusPyDouble_Type) < 0) return 0;
134 DBusPyDouble_Type.tp_print = NULL;
136 #ifdef WITH_DBUS_FLOAT32
137 DBusPyFloat_Type.tp_base = &DBusPyFloatBase_Type;
138 if (PyType_Ready(&DBusPyFloat_Type) < 0) return 0;
139 DBusPyFloat_Type.tp_print = NULL;
146 dbus_py_insert_float_types(PyObject *this_module)
148 Py_INCREF(&DBusPyDouble_Type);
149 if (PyModule_AddObject(this_module, "Double",
150 (PyObject *)&DBusPyDouble_Type) < 0) return 0;
151 #ifdef WITH_DBUS_FLOAT32
152 Py_INCREF(&DBusPyFloat_Type);
153 if (PyModule_AddObject(this_module, "Float",
154 (PyObject *)&DBusPyFloat_Type) < 0) return 0;