Mercurial > hg > orthanc-python
annotate CodeAnalysis/FunctionBody.mustache @ 172:8382c7dea471 java-code-model
created CodeAnalysis/GenerateOrthancSDK.py
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 27 Jun 2024 17:47:05 +0200 |
parents | e7ff5efb100d |
children | f49864df6f1f |
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}} |
20 long value = {{c_function}}(OrthancPlugins::GetGlobalContext(){{self}}{{call_args}}); | |
21 {{#args}}{{release}}{{/args}} | |
22 return PyLong_FromLong(value); | |
23 {{/return_long}} | |
24 {{#return_static_string}} | |
25 const char* s = {{c_function}}(OrthancPlugins::GetGlobalContext(){{self}}{{call_args}}); | |
26 {{#args}}{{release}}{{/args}} | |
27 if (s == NULL) | |
28 { | |
29 Py_INCREF(Py_None); | |
30 return Py_None; | |
31 } | |
32 else | |
33 { | |
34 return PyUnicode_FromString(s); | |
35 } | |
36 {{/return_static_string}} | |
37 {{#return_dynamic_string}} | |
38 OrthancPlugins::OrthancString s; | |
39 s.Assign({{c_function}}(OrthancPlugins::GetGlobalContext(){{self}}{{call_args}})); | |
40 {{#args}}{{release}}{{/args}} | |
41 if (s.GetContent() == NULL) | |
42 { | |
75
cbfc72a53970
refactoring calls to PythonLock::RaiseException()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
43 PythonLock::RaiseException(OrthancPluginErrorCode_InternalError); |
0 | 44 return NULL; |
45 } | |
46 else | |
47 { | |
48 return PyUnicode_FromString(s.GetContent()); | |
49 } | |
50 {{/return_dynamic_string}} | |
51 {{#return_void}} | |
52 {{c_function}}(OrthancPlugins::GetGlobalContext(){{self}}{{call_args}}); | |
53 {{#args}}{{release}}{{/args}} | |
54 | |
55 Py_INCREF(Py_None); | |
56 return Py_None; | |
57 {{/return_void}} | |
58 {{#return_error}} | |
59 OrthancPluginErrorCode code = {{c_function}}(OrthancPlugins::GetGlobalContext(){{self}}{{call_args}}); | |
60 {{#args}}{{release}}{{/args}} | |
61 | |
62 if (code == OrthancPluginErrorCode_Success) | |
63 { | |
64 Py_INCREF(Py_None); | |
65 return Py_None; | |
66 } | |
67 else | |
68 { | |
75
cbfc72a53970
refactoring calls to PythonLock::RaiseException()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
69 PythonLock::RaiseException(code); |
0 | 70 return NULL; |
71 } | |
72 {{/return_error}} | |
73 {{#return_object}} | |
74 // This is the case of a constructor | |
75 {{return_object}}* obj = {{c_function}}(OrthancPlugins::GetGlobalContext(){{self}}{{call_args}}); | |
76 {{#args}}{{release}}{{/args}} | |
77 if (obj == NULL) | |
78 { | |
75
cbfc72a53970
refactoring calls to PythonLock::RaiseException()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
79 PythonLock::RaiseException(OrthancPluginErrorCode_InternalError); |
0 | 80 return NULL; |
81 } | |
82 else | |
83 { | |
84 PyObject *argList = Py_BuildValue("Lb", obj, false /* not borrowed */); | |
85 PyObject *python = PyObject_CallObject((PyObject *) &sdk_{{return_object}}_Type, argList); | |
86 Py_DECREF(argList); | |
87 return python; | |
88 } | |
89 {{/return_object}} | |
90 {{#return_bytes}} | |
91 OrthancPlugins::MemoryBuffer buffer; | |
92 OrthancPluginErrorCode code = {{c_function}}(OrthancPlugins::GetGlobalContext(), *buffer{{self}}{{call_args}}); | |
93 {{#args}}{{release}}{{/args}} | |
94 if (code == OrthancPluginErrorCode_Success) | |
95 { | |
96 return PyBytes_FromStringAndSize(buffer.GetData(), buffer.GetSize()); | |
97 } | |
98 else | |
99 { | |
77
e7ff5efb100d
Custom exception "orthanc.OrthancException" is raised instead of "ValueError"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
100 PythonLock::RaiseException(code); |
0 | 101 return NULL; |
102 } | |
103 {{/return_bytes}} | |
104 {{#return_enumeration}} | |
105 {{return_enumeration}} value = {{c_function}}(OrthancPlugins::GetGlobalContext(){{self}}{{call_args}}); | |
106 {{#args}}{{release}}{{/args}} | |
107 return PyLong_FromLong(value); | |
108 {{/return_enumeration}} |