Mercurial > hg > orthanc-python
annotate CodeAnalysis/Class.mustache @ 189:46a81ed6e843
removed pointless function orthanc.CreateMemoryBuffer()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 02 Jul 2024 17:17:24 +0200 |
parents | c8de83fe7faa |
children | 20b004998fc2 |
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 | |
63
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
22 // Forward declaration of the autogenerated methods |
0 | 23 {{#methods}} |
24 static PyObject *sdk_{{class_name}}_{{c_function}}( | |
25 sdk_{{class_name}}_Object* self, PyObject *args); | |
26 {{/methods}} | |
63
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
27 // 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
|
28 |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
29 |
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 custom methods |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
31 {{#custom_methods}} |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
32 extern PyObject *{{implementation}}( |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
33 sdk_{{class_name}}_Object* self, PyObject *args); |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
34 {{/custom_methods}} |
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 |
0 | 36 |
37 | |
38 static PyMethodDef sdk_{{class_name}}_Methods[] = { | |
39 {{#methods}} | |
40 { "{{short_name}}", | |
41 (PyCFunction) sdk_{{class_name}}_{{c_function}}, METH_VARARGS, | |
42 "Generated from C function {{c_function}}()" }, | |
43 {{/methods}} | |
63
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
44 {{#custom_methods}} |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
45 { "{{method_name}}", |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
46 (PyCFunction) {{implementation}}, METH_VARARGS, |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
47 "Generated from C function {{sdk_function}}()" }, |
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
48 {{/custom_methods}} |
0 | 49 { NULL } /* Sentinel */ |
50 }; | |
51 | |
52 | |
53 static int sdk_{{class_name}}_Constructor( | |
54 sdk_{{class_name}}_Object *self, PyObject *args, PyObject *kwds) | |
55 { | |
28
b2bbb516056e
The "Calling Python..." info logs are disabled if "PythonVerbose" is "false"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
56 PythonLock::LogCall("Creating Python object of class {{class_name}}"); |
0 | 57 |
58 self->object_ = NULL; | |
59 self->borrowed_ = false; | |
60 | |
61 long long object = 0; | |
62 unsigned char borrowed = false; | |
63 | |
64 if (PyArg_ParseTuple(args, "Lb", &object, &borrowed)) | |
65 { | |
66 self->object_ = reinterpret_cast<{{class_name}}*>(static_cast<intptr_t>(object)); | |
67 self->borrowed_ = borrowed; | |
68 return 0; | |
69 } | |
70 else | |
71 { | |
72 PyErr_SetString(PyExc_ValueError, "Expected a pair (pointer, borrowed) in the constructor"); | |
73 return -1; | |
74 } | |
75 } | |
76 | |
77 | |
78 /** | |
79 * Static global structure => the fields that are beyond the last | |
80 * initialized field are set to zero. | |
81 * https://stackoverflow.com/a/11152199/881731 | |
82 **/ | |
83 static PyTypeObject sdk_{{class_name}}_Type = { | |
84 PyVarObject_HEAD_INIT(NULL, 0) | |
85 "orthanc.{{short_name}}", /* tp_name */ | |
86 sizeof(sdk_{{class_name}}_Object), /* tp_basicsize */ | |
87 }; | |
88 | |
89 | |
90 {{#destructor}} | |
91 static void sdk_{{class_name}}_Destructor(PyObject *self) | |
92 { | |
28
b2bbb516056e
The "Calling Python..." info logs are disabled if "PythonVerbose" is "false"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
93 PythonLock::LogCall("Destroying Python object of class {{class_name}}"); |
0 | 94 |
95 sdk_{{class_name}}_Object& tmp = *((sdk_{{class_name}}_Object*) self); | |
96 | |
97 if (tmp.object_ != NULL && | |
98 !tmp.borrowed_) | |
99 { | |
100 {{destructor}}(OrthancPlugins::GetGlobalContext(), tmp.object_); | |
101 tmp.object_ = NULL; | |
102 } | |
103 | |
104 Py_TYPE(self)->tp_free((PyObject *)self); | |
105 } | |
106 {{/destructor}} | |
107 | |
108 | |
109 static void Register{{class_name}}Class(PyObject* module) | |
110 { | |
111 sdk_{{class_name}}_Type.tp_new = PyType_GenericNew; | |
112 sdk_{{class_name}}_Type.tp_flags = Py_TPFLAGS_DEFAULT; | |
113 sdk_{{class_name}}_Type.tp_doc = "Generated from Orthanc C class: {{class_name}}"; | |
114 sdk_{{class_name}}_Type.tp_methods = sdk_{{class_name}}_Methods; | |
115 sdk_{{class_name}}_Type.tp_init = (initproc) sdk_{{class_name}}_Constructor; | |
116 | |
117 {{#destructor}} | |
118 /** | |
119 * "tp_dealloc is called when the reference count of the object goes | |
120 * down to zero. This is where you destroy the object and its | |
121 * members. It should then free the memory occupied by the object by | |
122 * calling tp_free." | |
123 * https://stackoverflow.com/a/24863227/881731 | |
124 **/ | |
125 sdk_{{class_name}}_Type.tp_dealloc = sdk_{{class_name}}_Destructor; | |
126 {{/destructor}} | |
127 | |
128 if (PyType_Ready(&sdk_{{class_name}}_Type) < 0) | |
129 { | |
171
c8de83fe7faa
removed deprecation warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
166
diff
changeset
|
130 ORTHANC_PLUGINS_LOG_ERROR("Cannot register Python class: {{class_name}}"); |
0 | 131 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); |
132 } | |
133 | |
134 Py_INCREF(&sdk_{{class_name}}_Type); | |
135 if (PyModule_AddObject(module, "{{short_name}}", (PyObject *)&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 Py_DECREF(&sdk_{{class_name}}_Type); |
139 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | |
140 } | |
141 } | |
142 | |
143 | |
63
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
144 PyTypeObject* Get{{class_name}}Type() |
0 | 145 { |
63
32de70a1e4c7
New functions from the SDK wrapped in Python: CreateDicom, RegisterFindCallback, RegisterMoveCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
146 return &sdk_{{class_name}}_Type; |
0 | 147 } |