Mercurial > hg > orthanc-python
annotate CodeAnalysis/Class.mustache @ 227:9574f06d8588 default tip
todo
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Tue, 24 Sep 2024 08:54:11 +0200 |
parents | 3678a028f1f6 |
children |
rev | line source |
---|---|
219
3678a028f1f6
making the project REUSE-compliant
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
1 /** |
3678a028f1f6
making the project REUSE-compliant
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
2 * SPDX-FileCopyrightText: 2020-2023 Osimis S.A., 2024-2024 Orthanc Team SRL, 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain |
3678a028f1f6
making the project REUSE-compliant
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
3 * SPDX-License-Identifier: AGPL-3.0-or-later |
3678a028f1f6
making the project REUSE-compliant
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
4 */ |
3678a028f1f6
making the project REUSE-compliant
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
5 |
0 | 6 /** |
7 * Python plugin for Orthanc | |
166
6fada29b6759
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
8 * 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
|
9 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium |
155
71d305c29cfa
updated year to 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
10 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
0 | 11 * |
12 * This program is free software: you can redistribute it and/or | |
13 * modify it under the terms of the GNU Affero General Public License | |
14 * as published by the Free Software Foundation, either version 3 of | |
15 * the License, or (at your option) any later version. | |
16 * | |
17 * This program is distributed in the hope that it will be useful, but | |
18 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
20 * Affero General Public License for more details. | |
21 * | |
22 * You should have received a copy of the GNU Affero General Public License | |
23 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
24 **/ | |
25 | |
26 | |
186
55473de7694f
added warning about auto-generated files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
182
diff
changeset
|
27 // WARNING: Auto-generated file. Do not modify it by hand. |
55473de7694f
added warning about auto-generated files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
182
diff
changeset
|
28 |
55473de7694f
added warning about auto-generated files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
182
diff
changeset
|
29 |
63
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
30 // Forward declaration of the autogenerated methods |
0 | 31 {{#methods}} |
32 static PyObject *sdk_{{class_name}}_{{c_function}}( | |
33 sdk_{{class_name}}_Object* self, PyObject *args); | |
34 {{/methods}} | |
63
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
35 // End of forward declarations |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
36 |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
37 |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
38 // Forward declaration of the custom methods |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
39 {{#custom_methods}} |
193
66cd20e970d8
simplification for custom methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
186
diff
changeset
|
40 extern PyObject *{{implementation}}(sdk_{{class_name}}_Object* self, PyObject *args); |
63
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
41 {{/custom_methods}} |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
42 // End of forward declarations |
0 | 43 |
44 | |
45 static PyMethodDef sdk_{{class_name}}_Methods[] = { | |
46 {{#methods}} | |
47 { "{{short_name}}", | |
48 (PyCFunction) sdk_{{class_name}}_{{c_function}}, METH_VARARGS, | |
49 "Generated from C function {{c_function}}()" }, | |
50 {{/methods}} | |
63
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
51 {{#custom_methods}} |
182
20b004998fc2
documentation of custom methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
171
diff
changeset
|
52 { "{{short_name}}", |
63
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
53 (PyCFunction) {{implementation}}, METH_VARARGS, |
193
66cd20e970d8
simplification for custom methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
186
diff
changeset
|
54 "Implemented in C++ function {{implementation}}()" }, |
63
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
55 {{/custom_methods}} |
0 | 56 { NULL } /* Sentinel */ |
57 }; | |
58 | |
59 | |
60 static int sdk_{{class_name}}_Constructor( | |
61 sdk_{{class_name}}_Object *self, PyObject *args, PyObject *kwds) | |
62 { | |
28
b2bbb516056e
The "Calling Python..." info logs are disabled if "PythonVerbose" is "false"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
63 PythonLock::LogCall("Creating Python object of class {{class_name}}"); |
0 | 64 |
65 self->object_ = NULL; | |
66 self->borrowed_ = false; | |
67 | |
68 long long object = 0; | |
69 unsigned char borrowed = false; | |
70 | |
71 if (PyArg_ParseTuple(args, "Lb", &object, &borrowed)) | |
72 { | |
73 self->object_ = reinterpret_cast<{{class_name}}*>(static_cast<intptr_t>(object)); | |
74 self->borrowed_ = borrowed; | |
75 return 0; | |
76 } | |
77 else | |
78 { | |
79 PyErr_SetString(PyExc_ValueError, "Expected a pair (pointer, borrowed) in the constructor"); | |
80 return -1; | |
81 } | |
82 } | |
83 | |
84 | |
85 /** | |
86 * Static global structure => the fields that are beyond the last | |
87 * initialized field are set to zero. | |
88 * https://stackoverflow.com/a/11152199/881731 | |
89 **/ | |
90 static PyTypeObject sdk_{{class_name}}_Type = { | |
91 PyVarObject_HEAD_INIT(NULL, 0) | |
92 "orthanc.{{short_name}}", /* tp_name */ | |
93 sizeof(sdk_{{class_name}}_Object), /* tp_basicsize */ | |
94 }; | |
95 | |
96 | |
97 {{#destructor}} | |
98 static void sdk_{{class_name}}_Destructor(PyObject *self) | |
99 { | |
28
b2bbb516056e
The "Calling Python..." info logs are disabled if "PythonVerbose" is "false"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
100 PythonLock::LogCall("Destroying Python object of class {{class_name}}"); |
0 | 101 |
102 sdk_{{class_name}}_Object& tmp = *((sdk_{{class_name}}_Object*) self); | |
103 | |
104 if (tmp.object_ != NULL && | |
105 !tmp.borrowed_) | |
106 { | |
107 {{destructor}}(OrthancPlugins::GetGlobalContext(), tmp.object_); | |
108 tmp.object_ = NULL; | |
109 } | |
110 | |
111 Py_TYPE(self)->tp_free((PyObject *)self); | |
112 } | |
113 {{/destructor}} | |
114 | |
115 | |
116 static void Register{{class_name}}Class(PyObject* module) | |
117 { | |
118 sdk_{{class_name}}_Type.tp_new = PyType_GenericNew; | |
119 sdk_{{class_name}}_Type.tp_flags = Py_TPFLAGS_DEFAULT; | |
120 sdk_{{class_name}}_Type.tp_doc = "Generated from Orthanc C class: {{class_name}}"; | |
121 sdk_{{class_name}}_Type.tp_methods = sdk_{{class_name}}_Methods; | |
122 sdk_{{class_name}}_Type.tp_init = (initproc) sdk_{{class_name}}_Constructor; | |
123 | |
124 {{#destructor}} | |
125 /** | |
126 * "tp_dealloc is called when the reference count of the object goes | |
127 * down to zero. This is where you destroy the object and its | |
128 * members. It should then free the memory occupied by the object by | |
129 * calling tp_free." | |
130 * https://stackoverflow.com/a/24863227/881731 | |
131 **/ | |
132 sdk_{{class_name}}_Type.tp_dealloc = sdk_{{class_name}}_Destructor; | |
133 {{/destructor}} | |
134 | |
135 if (PyType_Ready(&sdk_{{class_name}}_Type) < 0) | |
136 { | |
171
c8de83fe7faa
removed deprecation warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
166
diff
changeset
|
137 ORTHANC_PLUGINS_LOG_ERROR("Cannot register Python class: {{class_name}}"); |
0 | 138 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); |
139 } | |
140 | |
141 Py_INCREF(&sdk_{{class_name}}_Type); | |
142 if (PyModule_AddObject(module, "{{short_name}}", (PyObject *)&sdk_{{class_name}}_Type) < 0) | |
143 { | |
171
c8de83fe7faa
removed deprecation warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
166
diff
changeset
|
144 ORTHANC_PLUGINS_LOG_ERROR("Cannot register Python class: {{class_name}}"); |
0 | 145 Py_DECREF(&sdk_{{class_name}}_Type); |
146 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | |
147 } | |
148 } | |
149 | |
150 | |
63
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
151 PyTypeObject* Get{{class_name}}Type() |
0 | 152 { |
63
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
153 return &sdk_{{class_name}}_Type; |
0 | 154 } |