Merge git+ssh://people.freedesktop.org/home/smcv/public_html/git/dbus-python/
[dbus-python-phuang.git] / _dbus_bindings / float.c
blob0250a75655d8d0c48c97f97fe885b383a9000cdf
1 /* Simple D-Bus types: Double and (with appropriate #defines) Float
3 * Copyright (C) 2006 Collabora Ltd.
5 * Licensed under the Academic Free License version 2.1
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <Python.h>
24 #include <structmember.h>
26 #include <stdint.h>
28 #include "dbus_bindings-internal.h"
29 #include "types-internal.h"
31 PyDoc_STRVAR(Double_tp_doc,
32 "A double-precision floating point number (a subtype of float).");
34 #ifdef WITH_DBUS_FLOAT32
35 PyDoc_STRVAR(Float_tp_doc,
36 "A single-precision floating point number (a subtype of float).");
37 #endif
39 PyTypeObject DBusPyDouble_Type = {
40 PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type))
42 "dbus.Double",
45 0, /* tp_dealloc */
46 0, /* tp_print */
47 0, /* tp_getattr */
48 0, /* tp_setattr */
49 0, /* tp_compare */
50 0, /* tp_repr */
51 0, /* tp_as_number */
52 0, /* tp_as_sequence */
53 0, /* tp_as_mapping */
54 0, /* tp_hash */
55 0, /* tp_call */
56 0, /* tp_str */
57 0, /* tp_getattro */
58 0, /* tp_setattro */
59 0, /* tp_as_buffer */
60 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
61 Double_tp_doc, /* tp_doc */
62 0, /* tp_traverse */
63 0, /* tp_clear */
64 0, /* tp_richcompare */
65 0, /* tp_weaklistoffset */
66 0, /* tp_iter */
67 0, /* tp_iternext */
68 0, /* tp_methods */
69 0, /* tp_members */
70 0, /* tp_getset */
71 DEFERRED_ADDRESS(&DBusPythonFloatType), /* tp_base */
72 0, /* tp_dict */
73 0, /* tp_descr_get */
74 0, /* tp_descr_set */
75 0, /* tp_dictoffset */
76 0, /* tp_init */
77 0, /* tp_alloc */
78 0, /* tp_new */
81 #ifdef WITH_DBUS_FLOAT32
83 PyTypeObject DBusPyFloat_Type = {
84 PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type))
86 "dbus.Float",
89 0, /* tp_dealloc */
90 0, /* tp_print */
91 0, /* tp_getattr */
92 0, /* tp_setattr */
93 0, /* tp_compare */
94 0, /* tp_repr */
95 0, /* tp_as_number */
96 0, /* tp_as_sequence */
97 0, /* tp_as_mapping */
98 0, /* tp_hash */
99 0, /* tp_call */
100 0, /* tp_str */
101 0, /* tp_getattro */
102 0, /* tp_setattro */
103 0, /* tp_as_buffer */
104 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
105 Float_tp_doc, /* tp_doc */
106 0, /* tp_traverse */
107 0, /* tp_clear */
108 0, /* tp_richcompare */
109 0, /* tp_weaklistoffset */
110 0, /* tp_iter */
111 0, /* tp_iternext */
112 0, /* tp_methods */
113 0, /* tp_members */
114 0, /* tp_getset */
115 DEFERRED_ADDRESS(&DBusPythonFloatType), /* tp_base */
116 0, /* tp_dict */
117 0, /* tp_descr_get */
118 0, /* tp_descr_set */
119 0, /* tp_dictoffset */
120 0, /* tp_init */
121 0, /* tp_alloc */
122 0, /* tp_new */
124 #endif /* defined(WITH_DBUS_FLOAT32) */
126 dbus_bool_t
127 dbus_py_init_float_types(void)
129 DBusPyDouble_Type.tp_base = &DBusPyFloatBase_Type;
130 if (PyType_Ready(&DBusPyDouble_Type) < 0) return 0;
131 DBusPyDouble_Type.tp_print = NULL;
133 #ifdef WITH_DBUS_FLOAT32
134 DBusPyFloat_Type.tp_base = &DBusPyFloatBase_Type;
135 if (PyType_Ready(&DBusPyFloat_Type) < 0) return 0;
136 DBusPyFloat_Type.tp_print = NULL;
137 #endif
139 return 1;
142 dbus_bool_t
143 dbus_py_insert_float_types(PyObject *this_module)
145 Py_INCREF(&DBusPyDouble_Type);
146 if (PyModule_AddObject(this_module, "Double",
147 (PyObject *)&DBusPyDouble_Type) < 0) return 0;
148 #ifdef WITH_DBUS_FLOAT32
149 Py_INCREF(&DBusPyFloat_Type);
150 if (PyModule_AddObject(this_module, "Float",
151 (PyObject *)&DBusPyFloat_Type) < 0) return 0;
152 #endif
154 return 1;