/[thuban]/branches/WIP-pyshapelib-bramz/libraries/pyshapelib/pyshapelib_common.h
ViewVC logotype

Annotation of /branches/WIP-pyshapelib-bramz/libraries/pyshapelib/pyshapelib_common.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2741 - (hide annotations)
Tue Mar 13 23:30:41 2007 UTC (17 years, 11 months ago) by bramz
File MIME type: text/plain
File size: 2262 byte(s)
Added part_types() to SHPObject to return tuple of part types. Added __repr__ operators to return a string that can reconstruct the object using eval()
1 bramz 2735 #ifndef PYSHAPELIB_H
2     #define PYSHAPELIB_H
3    
4     #include <Python.h>
5     #include <structmember.h>
6    
7 bramz 2741 /* helper to export constants (macros) to Python.
8     * The constant in Python will have the same name as in C
9     */
10 bramz 2735 #define PYSHAPELIB_ADD_CONSTANT(constant) PyModule_AddIntConstant(module, #constant, constant)
11    
12 bramz 2741 /* helper to define the type object.
13     *
14     * This assumes quite a few things about different things being available and their name.
15     * For example, if type = Foo, then there should be a deallocation function called Foo_dealloc.
16     * See the macro itself for other examples.
17     */
18 bramz 2735 #define PYSHAPELIB_DEFINE_TYPE(type, name, doc) \
19     { \
20     PyObject_HEAD_INIT(NULL) \
21     0, /*ob_size*/ \
22     name, /*tp_name*/ \
23     sizeof(type), /*tp_basicsize*/ \
24     0, /*tp_itemsize*/ \
25     (destructor) type ## _dealloc, /*tp_dealloc*/ \
26     0, /*tp_print*/ \
27     0, /*tp_getattr*/ \
28     0, /*tp_setattr*/ \
29     0, /*tp_compare*/ \
30 bramz 2741 (reprfunc) type ## _repr, /*tp_repr*/ \
31 bramz 2735 0, /*tp_as_number*/ \
32     0, /*tp_as_sequence*/ \
33     0, /*tp_as_mapping*/ \
34     0, /*tp_hash */ \
35     0, /*tp_call*/ \
36     0, /*tp_str*/ \
37     0, /*tp_getattro*/ \
38     0, /*tp_setattro*/ \
39     0, /*tp_as_buffer*/ \
40     Py_TPFLAGS_DEFAULT, /*tp_flags*/ \
41     doc, /* tp_doc */ \
42     0, /* tp_traverse */ \
43     0, /* tp_clear */ \
44     0, /* tp_richcompare */ \
45     0, /* tp_weaklistoffset */ \
46     0, /* tp_iter */ \
47     0, /* tp_iternext */ \
48     type ## _methods, /* tp_methods */ \
49     0, /* tp_members */ \
50     type ## _getsetters, /* tp_getset */ \
51     0, /* tp_base */ \
52     0, /* tp_dict */ \
53     0, /* tp_descr_get */ \
54     0, /* tp_descr_set */ \
55     0, /* tp_dictoffset */ \
56     (initproc) type ## _init, /* tp_init */ \
57     0, /* tp_alloc */ \
58     type ## _new, /* tp_new */ \
59     } \
60     /**/
61    
62 bramz 2741 /* helper to add type to module.
63     * Does a bit of the tedious bookkeeping for us
64     */
65 bramz 2735 #define PYSHAPELIB_ADD_TYPE(type, name) \
66     type.ob_type = &PyType_Type; \
67     if (PyType_Ready(&type) >= 0) \
68     { \
69     Py_INCREF(&type); \
70     PyModule_AddObject(module, name, (PyObject*)&type); \
71     }
72    
73     #endif

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26