Mercurial > hg > orthanc-python
annotate CodeAnalysis/FunctionBody.mustache @ 215:b124c74e6968
simplification
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 03 Jul 2024 15:33:21 +0200 |
parents | f34f3a149c22 |
children |
rev | line source |
---|---|
0 | 1 {{#args}} |
2 {{python_type}} {{name}}{{initialization}}; | |
3 {{/args}} | |
4 | |
5 {{#has_args}} | |
6 if (!PyArg_ParseTuple(args, {{tuple_format}})) | |
7 { | |
8 PyErr_SetString(PyExc_TypeError, "Bad types for the arguments ({{count_args}} arguments expected)"); | |
9 return NULL; | |
10 } | |
11 {{/has_args}} | |
172
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
12 {{#args}}{{#check_object_type}} |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
13 if ({{name}} != Py_None && Py_TYPE({{name}}) != Get{{check_object_type}}Type()) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
14 { |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
15 PyErr_SetString(PyExc_TypeError, "Invalid orthanc.{{check_object_type}} object"); |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
16 return NULL; |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
17 } |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
77
diff
changeset
|
18 {{/check_object_type}}{{/args}} |
0 | 19 {{#return_long}} |
184
f34f3a149c22
added class PythonThreadsAllower
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
20 long value; |
f34f3a149c22
added class PythonThreadsAllower
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
21 { |
f34f3a149c22
added class PythonThreadsAllower
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
22 PythonThreadsAllower allower; |
f34f3a149c22
added class PythonThreadsAllower
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
23 value = {{c_function}}(OrthancPlugins::GetGlobalContext(){{self}}{{call_args}}); |
f34f3a149c22
added class PythonThreadsAllower
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
24 } |
0 | 25 {{#args}}{{release}}{{/args}} |
26 return PyLong_FromLong(value); | |
27 {{/return_long}} | |
28 {{#return_static_string}} | |
184
f34f3a149c22
added class PythonThreadsAllower
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
29 const char* s; |
f34f3a149c22
added class PythonThreadsAllower
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
30 { |
f34f3a149c22
added class PythonThreadsAllower
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
31 PythonThreadsAllower allower; |
f34f3a149c22
added class PythonThreadsAllower
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
32 s = {{c_function}}(OrthancPlugins::GetGlobalContext(){{self}}{{call_args}}); |
f34f3a149c22
added class PythonThreadsAllower
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
33 } |
0 | 34 {{#args}}{{release}}{{/args}} |
35 if (s == NULL) | |
36 { | |
37 Py_INCREF(Py_None); | |
38 return Py_None; | |
39 } | |
40 else | |
41 { | |
42 return PyUnicode_FromString(s); | |
43 } | |
44 {{/return_static_string}} | |
45 {{#return_dynamic_string}} | |
46 OrthancPlugins::OrthancString s; | |
184
f34f3a149c22
added class PythonThreadsAllower
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
47 { |
f34f3a149c22
added class PythonThreadsAllower
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
48 PythonThreadsAllower allower; |
f34f3a149c22
added class PythonThreadsAllower
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
49 s.Assign({{c_function}}(OrthancPlugins::GetGlobalContext(){{self}}{{call_args}})); |
f34f3a149c22
added class PythonThreadsAllower
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
50 } |
0 | 51 {{#args}}{{release}}{{/args}} |
52 if (s.GetContent() == NULL) | |
53 { | |
75
cbfc72a53970
refactoring calls to PythonLock::RaiseException()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
54 PythonLock::RaiseException(OrthancPluginErrorCode_InternalError); |
0 | 55 return NULL; |
56 } | |
57 else | |
58 { | |
59 return PyUnicode_FromString(s.GetContent()); | |
60 } | |
61 {{/return_dynamic_string}} | |
62 {{#return_void}} | |
184
f34f3a149c22
added class PythonThreadsAllower
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
63 { |
f34f3a149c22
added class PythonThreadsAllower
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
64 PythonThreadsAllower allower; |
f34f3a149c22
added class PythonThreadsAllower
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
65 {{c_function}}(OrthancPlugins::GetGlobalContext(){{self}}{{call_args}}); |
f34f3a149c22
added class PythonThreadsAllower
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
66 } |
0 | 67 {{#args}}{{release}}{{/args}} |
68 | |
69 Py_INCREF(Py_None); | |
70 return Py_None; | |
71 {{/return_void}} | |
72 {{#return_error}} | |
184
f34f3a149c22
added class PythonThreadsAllower
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
73 OrthancPluginErrorCode code; |
f34f3a149c22
added class PythonThreadsAllower
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
74 { |
f34f3a149c22
added class PythonThreadsAllower
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
75 PythonThreadsAllower allower; |
f34f3a149c22
added class PythonThreadsAllower
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
76 code = {{c_function}}(OrthancPlugins::GetGlobalContext(){{self}}{{call_args}}); |
f34f3a149c22
added class PythonThreadsAllower
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
77 } |
0 | 78 {{#args}}{{release}}{{/args}} |
79 | |
80 if (code == OrthancPluginErrorCode_Success) | |
81 { | |
82 Py_INCREF(Py_None); | |
83 return Py_None; | |
84 } | |
85 else | |
86 { | |
75
cbfc72a53970
refactoring calls to PythonLock::RaiseException()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
87 PythonLock::RaiseException(code); |
0 | 88 return NULL; |
89 } | |
90 {{/return_error}} | |
91 {{#return_object}} | |
92 // This is the case of a constructor | |
184
f34f3a149c22
added class PythonThreadsAllower
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
93 {{return_object}}* obj; |
f34f3a149c22
added class PythonThreadsAllower
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
94 { |
f34f3a149c22
added class PythonThreadsAllower
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
95 PythonThreadsAllower allower; |
f34f3a149c22
added class PythonThreadsAllower
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
96 obj = {{c_function}}(OrthancPlugins::GetGlobalContext(){{self}}{{call_args}}); |
f34f3a149c22
added class PythonThreadsAllower
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
97 } |
0 | 98 {{#args}}{{release}}{{/args}} |
99 if (obj == NULL) | |
100 { | |
75
cbfc72a53970
refactoring calls to PythonLock::RaiseException()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
101 PythonLock::RaiseException(OrthancPluginErrorCode_InternalError); |
0 | 102 return NULL; |
103 } | |
104 else | |
105 { | |
106 PyObject *argList = Py_BuildValue("Lb", obj, false /* not borrowed */); | |
107 PyObject *python = PyObject_CallObject((PyObject *) &sdk_{{return_object}}_Type, argList); | |
108 Py_DECREF(argList); | |
109 return python; | |
110 } | |
111 {{/return_object}} | |
112 {{#return_bytes}} | |
113 OrthancPlugins::MemoryBuffer buffer; | |
184
f34f3a149c22
added class PythonThreadsAllower
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
114 OrthancPluginErrorCode code; |
f34f3a149c22
added class PythonThreadsAllower
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
115 { |
f34f3a149c22
added class PythonThreadsAllower
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
116 PythonThreadsAllower allower; |
f34f3a149c22
added class PythonThreadsAllower
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
117 code = {{c_function}}(OrthancPlugins::GetGlobalContext(), *buffer{{self}}{{call_args}}); |
f34f3a149c22
added class PythonThreadsAllower
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
118 } |
0 | 119 {{#args}}{{release}}{{/args}} |
120 if (code == OrthancPluginErrorCode_Success) | |
121 { | |
122 return PyBytes_FromStringAndSize(buffer.GetData(), buffer.GetSize()); | |
123 } | |
124 else | |
125 { | |
77
e7ff5efb100d
Custom exception "orthanc.OrthancException" is raised instead of "ValueError"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
126 PythonLock::RaiseException(code); |
0 | 127 return NULL; |
128 } | |
129 {{/return_bytes}} | |
130 {{#return_enumeration}} | |
184
f34f3a149c22
added class PythonThreadsAllower
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
131 {{return_enumeration}} value; |
f34f3a149c22
added class PythonThreadsAllower
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
132 { |
f34f3a149c22
added class PythonThreadsAllower
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
133 PythonThreadsAllower allower; |
f34f3a149c22
added class PythonThreadsAllower
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
134 value = {{c_function}}(OrthancPlugins::GetGlobalContext(){{self}}{{call_args}}); |
f34f3a149c22
added class PythonThreadsAllower
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
135 } |
0 | 136 {{#args}}{{release}}{{/args}} |
137 return PyLong_FromLong(value); | |
138 {{/return_enumeration}} |