Mercurial > hg > orthanc-python
annotate CodeAnalysis/Enumeration.mustache @ 204:65ad095c25d8
report statistics in GenerateOrthancSDK.py
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 03 Jul 2024 12:21:32 +0200 |
parents | 55473de7694f |
children | 3678a028f1f6 |
rev | line source |
---|---|
0 | 1 /** |
2 * Python plugin for Orthanc | |
166
6fada29b6759
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
3 * Copyright (C) 2020-2023 Osimis S.A., Belgium |
6fada29b6759
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
4 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium |
155
71d305c29cfa
updated year to 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
5 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
0 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
186
55473de7694f
added warning about auto-generated files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
171
diff
changeset
|
22 // WARNING: Auto-generated file. Do not modify it by hand. |
55473de7694f
added warning about auto-generated files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
171
diff
changeset
|
23 |
55473de7694f
added warning about auto-generated files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
171
diff
changeset
|
24 |
0 | 25 typedef struct |
26 { | |
27 PyObject_HEAD | |
28 } sdk_{{name}}_Object; | |
29 | |
30 | |
31 /** | |
32 * Static global structure => the fields that are beyond the last | |
33 * initialized field are set to zero. | |
34 * https://stackoverflow.com/a/11152199/881731 | |
35 **/ | |
36 static PyTypeObject sdk_{{name}}_Type = { | |
37 PyVarObject_HEAD_INIT(NULL, 0) | |
38 "orthanc.{{short_name}}", /* tp_name */ | |
39 sizeof(sdk_{{name}}_Object), /* tp_basicsize */ | |
40 }; | |
41 | |
42 | |
43 void Register{{name}}Enumeration(PyObject* module) | |
44 { | |
45 sdk_{{name}}_Type.tp_new = PyType_GenericNew; | |
46 sdk_{{name}}_Type.tp_flags = Py_TPFLAGS_DEFAULT; | |
47 sdk_{{name}}_Type.tp_doc = "Generated from C enumeration OrthancPlugin{{name}}"; | |
48 | |
49 sdk_{{name}}_Type.tp_dict = PyDict_New(); | |
50 | |
51 if (PyType_Ready(&sdk_{{name}}_Type) < 0) | |
52 { | |
171
c8de83fe7faa
removed deprecation warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
166
diff
changeset
|
53 ORTHANC_PLUGINS_LOG_ERROR("Cannot register Python enumeration: {{name}}"); |
0 | 54 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); |
55 } | |
56 | |
57 /** | |
58 * Declare constants here (static members = class attributes) | |
59 * https://stackoverflow.com/a/8017906/881731 | |
60 * | |
61 * "Static and class methods can be defined in tp_methods by adding | |
62 * METH_STATIC or METH_CLASS to the ml_flags field of the | |
63 * PyMethodDef structure. This is equivalent to @staticmethod and | |
64 * @classmethod decorators." | |
65 * | |
66 * "Class attributes can be added by setting the tp_dict to a | |
67 * dictionary with these attributes before calling PyType_Ready() | |
68 * (in your module initialization function)." | |
69 **/ | |
70 | |
71 {{#values}} | |
128
5b59ebc267e1
fixed leaks in the initialization of the enums
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
72 { |
5b59ebc267e1
fixed leaks in the initialization of the enums
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
73 PyObject* tmp = PyLong_FromLong({{value}}); |
5b59ebc267e1
fixed leaks in the initialization of the enums
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
74 PyDict_SetItemString(sdk_{{name}}_Type.tp_dict, "{{key}}", tmp); |
5b59ebc267e1
fixed leaks in the initialization of the enums
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
75 Py_DECREF(tmp); |
5b59ebc267e1
fixed leaks in the initialization of the enums
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
76 } |
5b59ebc267e1
fixed leaks in the initialization of the enums
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
77 |
0 | 78 {{/values}} |
79 | |
80 Py_INCREF(&sdk_{{name}}_Type); | |
81 if (PyModule_AddObject(module, "{{short_name}}", (PyObject *)&sdk_{{name}}_Type) < 0) | |
82 { | |
171
c8de83fe7faa
removed deprecation warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
166
diff
changeset
|
83 ORTHANC_PLUGINS_LOG_ERROR("Cannot register Python enumeration: {{name}}"); |
0 | 84 Py_DECREF(&sdk_{{name}}_Type); |
85 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | |
86 } | |
87 } |