RAVE
pyfileobject.h
Go to the documentation of this file.
1/* --------------------------------------------------------------------
2Copyright (C) 2025 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 PYFILEOBJECT_H
26#define PYFILEOBJECT_H
27#include "Python.h"
28#include "file_object.h"
29
33typedef struct {
34 PyObject_HEAD /*Always has to be on top*/
37
38#define PyFileObject_Type_NUM 0
39
40#define PyFileObject_GetNative_NUM 1
41#define PyFileObject_GetNative_RETURN FileObject_t*
42#define PyFileObject_GetNative_PROTO (PyFileObject*)
43
44#define PyFileObject_New_NUM 2
45#define PyFileObject_New_RETURN PyFileObject*
46#define PyFileObject_New_PROTO (FileObject_t*)
47
48#define PyFileObject_API_pointers 3
49
50#define PyFileObject_CAPSULE_NAME "_fileobject._C_API"
51
52
53#ifdef PYFILEOBJECT_MODULE
55extern PyTypeObject PyFileObject_Type;
56
58#define PyFileObject_Check(op) ((op)->ob_type == &PyFileObject_Type)
59
62
65
66#else
68static void **PyFileObject_API;
69
74#define PyFileObject_GetNative \
75 (*(PyFileObject_GetNative_RETURN (*)PyFileObject_GetNative_PROTO) PyFileObject_API[PyFileObject_GetNative_NUM])
76
84#define PyFileObject_New \
85 (*(PyFileObject_New_RETURN (*)PyFileObject_New_PROTO) PyFileObject_API[PyFileObject_New_NUM])
86
90#define PyFileObject_Check(op) \
91 (Py_TYPE(op) == &PyFileObject_Type)
92
93#define PyFileObject_Type (*(PyTypeObject*)PyFileObject_API[PyFileObject_Type_NUM])
94
98#define import_fileobject() \
99 PyFileObject_API = (void **)PyCapsule_Import(PyFileObject_CAPSULE_NAME, 1);
100
101#endif
102
103#endif /* PYFILEOBJECT_H */
This is a general file object.
struct _FileObject_t FileObject_t
Defines a general file object.
Definition file_object.h:44
#define PyFileObject_New
Creates a new file object instance.
Definition pyfileobject.h:84
#define PyFileObject_GetNative_RETURN
return type for GetNative
Definition pyfileobject.h:41
#define PyFileObject_New_RETURN
return type for New
Definition pyfileobject.h:45
#define PyFileObject_New_PROTO
arguments for New
Definition pyfileobject.h:46
#define PyFileObject_GetNative
Returns a pointer to the internal file object, remember to release the reference when done with the o...
Definition pyfileobject.h:74
#define PyFileObject_GetNative_PROTO
arguments for GetNative
Definition pyfileobject.h:42
A pia.
Definition pyfileobject.h:33
PyObject_HEAD FileObject_t * fobj
the file object
Definition pyfileobject.h:35