| 175 | |
| 176 | |
| 177 | PyObject* PyStreamingAlgorithm::push(PyStreamingAlgorithm* self, PyObject* args) { |
| 178 | vector<PyObject*> argsV = unpack(args); |
| 179 | if (argsV.size() != 2) { |
| 180 | PyErr_SetString(PyExc_ValueError, "Algorithm.push requires 2 arguments"); |
| 181 | return NULL; |
| 182 | } |
| 183 | |
| 184 | if (!PyString_Check(argsV[0])) { |
| 185 | PyErr_SetString(PyExc_ValueError, "Algorithm.push requires a string as the first argument"); |
| 186 | return NULL; |
| 187 | } |
| 188 | |
| 189 | // name of the source to push onto |
| 190 | string name = PyString_AS_STRING(argsV[0]); |
| 191 | |
| 192 | // check if source exists |
| 193 | if (!contains(self->algo->outputs(), name)) { |
| 194 | ostringstream msg; |
| 195 | msg << self->algo->name() << " does not have an input named " << name; |
| 196 | PyErr_SetString(PyExc_ValueError, msg.str().c_str()); |
| 197 | return NULL; |
| 198 | } |
| 199 | |
| 200 | SourceBase& src = self->algo->output(name); |
| 201 | |
| 202 | // edt of given data |
| 203 | Edt tp = typeInfoToEdt(src.typeInfo()); |
| 204 | |
| 205 | #define PUSH_COPY(tname, type) { \ |
| 206 | type* val = (type*)tname::fromPythonCopy(argsV[1]); \ |
| 207 | src.push(*val); \ |
| 208 | delete val; \ |
| 209 | break; \ |
| 210 | } |
| 211 | |
| 212 | switch(tp) { |
| 213 | case INTEGER: PUSH_COPY(Integer, int); |
| 214 | case REAL: PUSH_COPY(PyReal, Real); |
| 215 | case STRING: PUSH_COPY(String, string); |
| 216 | case STEREOSAMPLE: PUSH_COPY(PyStereoSample, StereoSample); |
| 217 | case VECTOR_STRING: PUSH_COPY(VectorString, vector<string>); |
| 218 | case VECTOR_STEREOSAMPLE: PUSH_COPY(VectorStereoSample, vector<StereoSample>); |
| 219 | |
| 220 | case VECTOR_REAL: { |
| 221 | RogueVector<Real>* val = (RogueVector<Real>*)VectorReal::fromPythonRef(argsV[1]); |
| 222 | src.push(*(vector<Real>*)val); |
| 223 | delete val; |
| 224 | break; |
| 225 | } |
| 226 | |
| 227 | default: |
| 228 | ostringstream msg; |
| 229 | msg << "given value type not supported: " << edtToString(tp); |
| 230 | PyErr_SetString(PyExc_ValueError, msg.str().c_str()); return NULL; |
| 231 | } |
| 232 | |
| 233 | #undef PUSH_COPY |
| 234 | |