comparison CodeAnalysis/FunctionBody.mustache @ 0:7ed502b17b8f

initial commit
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 26 Mar 2020 18:47:01 +0100
parents
children cbfc72a53970
comparison
equal deleted inserted replaced
-1:000000000000 0:7ed502b17b8f
1 {{#args}}
2 {{python_type}} {{name}}{{initialization}};
3 {{/args}}
4
5 {{#has_args}}
6 if (!PyArg_ParseTuple(args, {{tuple_format}}))
7 {
8 // TODO => RAISE : https://stackoverflow.com/questions/60832317
9 PyErr_SetString(PyExc_TypeError, "Bad types for the arguments ({{count_args}} arguments expected)");
10 return NULL;
11 }
12 {{/has_args}}
13 {{#return_long}}
14 long value = {{c_function}}(OrthancPlugins::GetGlobalContext(){{self}}{{call_args}});
15 {{#args}}{{release}}{{/args}}
16 return PyLong_FromLong(value);
17 {{/return_long}}
18 {{#return_static_string}}
19 const char* s = {{c_function}}(OrthancPlugins::GetGlobalContext(){{self}}{{call_args}});
20 {{#args}}{{release}}{{/args}}
21 if (s == NULL)
22 {
23 Py_INCREF(Py_None);
24 return Py_None;
25 }
26 else
27 {
28 return PyUnicode_FromString(s);
29 }
30 {{/return_static_string}}
31 {{#return_dynamic_string}}
32 OrthancPlugins::OrthancString s;
33 s.Assign({{c_function}}(OrthancPlugins::GetGlobalContext(){{self}}{{call_args}}));
34 {{#args}}{{release}}{{/args}}
35 if (s.GetContent() == NULL)
36 {
37 // TODO => RAISE : https://stackoverflow.com/questions/60832317
38 //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError);
39 PyErr_SetString(PyExc_ValueError, "Internal error");
40 return NULL;
41 }
42 else
43 {
44 return PyUnicode_FromString(s.GetContent());
45 }
46 {{/return_dynamic_string}}
47 {{#return_void}}
48 {{c_function}}(OrthancPlugins::GetGlobalContext(){{self}}{{call_args}});
49 {{#args}}{{release}}{{/args}}
50
51 Py_INCREF(Py_None);
52 return Py_None;
53 {{/return_void}}
54 {{#return_error}}
55 OrthancPluginErrorCode code = {{c_function}}(OrthancPlugins::GetGlobalContext(){{self}}{{call_args}});
56 {{#args}}{{release}}{{/args}}
57
58 if (code == OrthancPluginErrorCode_Success)
59 {
60 Py_INCREF(Py_None);
61 return Py_None;
62 }
63 else
64 {
65 // TODO => RAISE : https://stackoverflow.com/questions/60832317
66 //PythonLock::RaiseException(module, code);
67 PyErr_SetString(PyExc_ValueError, "Internal error");
68 return NULL;
69 }
70 {{/return_error}}
71 {{#return_object}}
72 // This is the case of a constructor
73 {{return_object}}* obj = {{c_function}}(OrthancPlugins::GetGlobalContext(){{self}}{{call_args}});
74 {{#args}}{{release}}{{/args}}
75 if (obj == NULL)
76 {
77 // TODO => RAISE : https://stackoverflow.com/questions/60832317
78 //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError);
79 PyErr_SetString(PyExc_ValueError, "Internal error");
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 {
100 // TODO => RAISE : https://stackoverflow.com/questions/60832317
101 //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError);
102 PyErr_SetString(PyExc_ValueError, "Internal error");
103 return NULL;
104 }
105 {{/return_bytes}}
106 {{#return_enumeration}}
107 {{return_enumeration}} value = {{c_function}}(OrthancPlugins::GetGlobalContext(){{self}}{{call_args}});
108 {{#args}}{{release}}{{/args}}
109 return PyLong_FromLong(value);
110 {{/return_enumeration}}