RAVE
pycartesian.h
Go to the documentation of this file.
1/* --------------------------------------------------------------------
2Copyright (C) 2009 Swedish Meteorological and Hydrological Institute, SMHI,
3
4This file is part of RAVE.
5
6RAVE is free software: you can redistribute it and/or modify
7it under the terms of the GNU Lesser General Public License as published by
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
10
11RAVE is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU Lesser General Public License for more details.
15
16You should have received a copy of the GNU Lesser General Public License
17along with RAVE. If not, see <http://www.gnu.org/licenses/>.
18------------------------------------------------------------------------*/
25#ifndef PYCARTESIAN_H
26#define PYCARTESIAN_H
27#include "cartesian.h"
28
32typedef struct {
33 PyObject_HEAD /*Always has to be on top*/
36
37#define PyCartesian_Type_NUM 0
39#define PyCartesian_GetNative_NUM 1
40#define PyCartesian_GetNative_RETURN Cartesian_t*
41#define PyCartesian_GetNative_PROTO (PyCartesian*)
43#define PyCartesian_New_NUM 2
44#define PyCartesian_New_RETURN PyCartesian*
45#define PyCartesian_New_PROTO (Cartesian_t*)
47#define PyCartesian_API_pointers 3
49#define PyCartesian_CAPSULE_NAME "_cartesian._C_API"
50
51#ifdef PYCARTESIAN_MODULE
53extern PyTypeObject PyCartesian_Type;
54
56#define PyCartesian_Check(op) ((op)->ob_type == &PyCartesian_Type)
57
60
63
64#else
66static void **PyCartesian_API;
67
72#define PyCartesian_GetNative \
73 (*(PyCartesian_GetNative_RETURN (*)PyCartesian_GetNative_PROTO) PyCartesian_API[PyCartesian_GetNative_NUM])
74
82#define PyCartesian_New \
83 (*(PyCartesian_New_RETURN (*)PyCartesian_New_PROTO) PyCartesian_API[PyCartesian_New_NUM])
84
88#define PyCartesian_Check(op) \
89 (Py_TYPE(op) == &PyCartesian_Type)
90
91#define PyCartesian_Type (*(PyTypeObject*)PyCartesian_API[PyCartesian_Type_NUM])
92
96#define import_pycartesian() \
97 PyCartesian_API = (void **)PyCapsule_Import(PyCartesian_CAPSULE_NAME, 1);
98
99#ifdef KALLE
100
104#define PyCartesian_Check(op) \
105 ((op)->ob_type == (PyTypeObject *)PyCartesian_API[PyCartesian_Type_NUM])
106
110static int
112{
113 PyObject *module;
114 PyObject *c_api_object;
115
116 module = PyImport_ImportModule("_cartesian");
117 if (module == NULL) {
118 return -1;
119 }
120
121 c_api_object = PyObject_GetAttrString(module, "_C_API");
122 if (c_api_object == NULL) {
123 Py_DECREF(module);
124 return -1;
125 }
126#if PY_MAJOR_VERSION < 3
127 PyCartesian_API = (void **)PyCObject_AsVoidPtr(c_api_object);
128#else
129 PyCartesian_API = (void **)PyCapsule_New((void *)c_api_object, NULL, NULL);
130#endif
131/*
132 if (PyCObject_Check(c_api_object)) {
133 PyCartesian_API = (void **)PyCObject_AsVoidPtr(c_api_object);
134 }
135*/
136 Py_DECREF(c_api_object);
137 Py_DECREF(module);
138 return 0;
139}
140#endif
141
142
143#endif
144
145#endif /* PYCARTESIAN_H */
Defines the functions available when working with cartesian products.
#define PyCartesian_GetNative
Returns a pointer to the internal cartesian, remember to release the reference when done with the obj...
Definition pycartesian.h:72
#define PyCartesian_New_RETURN
return type for New
Definition pycartesian.h:44
#define import_pycartesian()
Imports the PyArea module (like import _area in python).
Definition pycartesian.h:96
#define PyCartesian_New_PROTO
arguments for New
Definition pycartesian.h:45
#define PyCartesian_GetNative_PROTO
arguments for GetNative
Definition pycartesian.h:41
#define PyCartesian_GetNative_RETURN
return type for GetNative
Definition pycartesian.h:40
#define PyCartesian_New
Creates a new cartesian instance.
Definition pycartesian.h:82
A cartesian product.
Definition pycartesian.h:32
PyObject_HEAD Cartesian_t * cartesian
the cartesian product
Definition pycartesian.h:34
Represents the cartesian product.
Definition cartesian.c:41