This function builds the python object that is to be returned given a vector of outputs. It automatically chooses the correct output type (None, simple value, tuple of values) wrt the number of outputs. /
| 122 | // * (None, simple value, tuple of values) wrt the number of outputs. |
| 123 | // */ |
| 124 | PyObject* buildReturnValue(const vector<PyObject*>& result_vec) { |
| 125 | int size = result_vec.size(); |
| 126 | |
| 127 | // if there is no result to be returned, return None to the python interpreter |
| 128 | if (size == 0) Py_RETURN_NONE; |
| 129 | |
| 130 | // if there is only one value, return it directly instead of a 1-sized tuple |
| 131 | if (size == 1) return result_vec[0]; |
| 132 | |
| 133 | // otherwise, create a tuple and fill it with the results |
| 134 | PyObject* result = PyTuple_New(result_vec.size()); |
| 135 | |
| 136 | for (int i=0; i<size; i++) { |
| 137 | PyTuple_SET_ITEM(result, i, result_vec[i]); |
| 138 | } |
| 139 | |
| 140 | return result; |
| 141 | } |
| 142 | |
| 143 | PyObject* toPython(void* obj, Edt tp) { |
| 144 | switch (tp) { |