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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 {{#args}}
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 {{python_type}} {{name}}{{initialization}};
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 {{/args}}
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 {{#has_args}}
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 if (!PyArg_ParseTuple(args, {{tuple_format}}))
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 {
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 PyErr_SetString(PyExc_TypeError, "Bad types for the arguments ({{count_args}} arguments expected)");
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 return NULL;
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 }
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 {{#args}}{{release}}{{/args}}
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 return PyLong_FromLong(value);
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 {{/return_long}}
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 {{#args}}{{release}}{{/args}}
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 if (s == NULL)
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 {
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 Py_INCREF(Py_None);
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 return Py_None;
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 }
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 else
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 {
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 return PyUnicode_FromString(s);
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 }
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 {{/return_static_string}}
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 {{#return_dynamic_string}}
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 {{#args}}{{release}}{{/args}}
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 if (s.GetContent() == NULL)
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 {
75
cbfc72a53970 refactoring calls to PythonLock::RaiseException()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
54 PythonLock::RaiseException(OrthancPluginErrorCode_InternalError);
0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 return NULL;
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 }
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 else
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 {
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 return PyUnicode_FromString(s.GetContent());
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 }
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 {{/return_dynamic_string}}
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 {{#args}}{{release}}{{/args}}
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 Py_INCREF(Py_None);
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 return Py_None;
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 {{/return_void}}
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 {{#args}}{{release}}{{/args}}
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 if (code == OrthancPluginErrorCode_Success)
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 {
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 Py_INCREF(Py_None);
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 return Py_None;
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 }
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 else
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 {
75
cbfc72a53970 refactoring calls to PythonLock::RaiseException()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
87 PythonLock::RaiseException(code);
0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 return NULL;
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 }
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 {{/return_error}}
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 {{#return_object}}
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 {{#args}}{{release}}{{/args}}
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 if (obj == NULL)
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 {
75
cbfc72a53970 refactoring calls to PythonLock::RaiseException()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
101 PythonLock::RaiseException(OrthancPluginErrorCode_InternalError);
0
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 return NULL;
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 }
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 else
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 {
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 PyObject *argList = Py_BuildValue("Lb", obj, false /* not borrowed */);
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 PyObject *python = PyObject_CallObject((PyObject *) &sdk_{{return_object}}_Type, argList);
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 Py_DECREF(argList);
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 return python;
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 }
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 {{/return_object}}
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 {{#return_bytes}}
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 {{#args}}{{release}}{{/args}}
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 if (code == OrthancPluginErrorCode_Success)
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 {
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 return PyBytes_FromStringAndSize(buffer.GetData(), buffer.GetSize());
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 }
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 else
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 return NULL;
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 }
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 {{/return_bytes}}
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 {{#args}}{{release}}{{/args}}
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 return PyLong_FromLong(value);
7ed502b17b8f initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 {{/return_enumeration}}