/** @brief Set a variable by its name. * @param self Module. * @param args Positional arguments. * @param keywds Keyword arguments. * @return Computed value, NULL if errors have been detected. */ static PyObject* set(PyObject *self, PyObject *args, PyObject *keywds) { Aqua::CalcServer::CalcServer *C = Aqua::CalcServer::CalcServer::singleton(); Aqua::InputOutput::Variables *vars = C->variables(); const char* varname; PyObject *value; int i0 = 0; int n = 0; static char *kwlist[] = {"varname", "value", "offset", "n", NULL}; if (!PyArg_ParseTupleAndKeywords(args, keywds, "sO|ii", kwlist, &varname, &value, &i0, &n)){ return NULL; } Aqua::InputOutput::Variable *var = vars->get(varname); if(!var){ std::ostringstream errstr; errstr << "Variable \"" << varname << "\" has not been declared"; PyErr_SetString(PyExc_ValueError, errstr.str().c_str()); return NULL; } if(var->setFromPythonObject(value, i0, n)){ return NULL; } // Populate the variable if it is a scalar one if(var->type().find('*') == std::string::npos){ try { vars->populate(var); } catch(...) { return NULL; } } Py_RETURN_NONE; }
/** @brief Set a variable by its name. * @param self Module. * @param args Positional arguments. * @param keywds Keyword arguments. * @return Computed value, NULL if errors have been detected. */ static PyObject* set(PyObject *self, PyObject *args, PyObject *keywds) { Aqua::CalcServer::CalcServer *C = Aqua::CalcServer::CalcServer::singleton(); Aqua::InputOutput::Variables *V = C->variables(); const char* varname; PyObject *value; int i0 = 0; int n = 0; static char *kwlist[] = {"varname", "value", "offset", "n", NULL}; if (!PyArg_ParseTupleAndKeywords(args, keywds, "sO|ii", kwlist, &varname, &value, &i0, &n)){ return NULL; } Aqua::InputOutput::Variable *var = V->get(varname); if(!var){ char errstr[64 + strlen(varname)]; sprintf(errstr, "Variable \"%s\" has not been declared", varname); PyErr_SetString(PyExc_ValueError, errstr); return NULL; } if(var->setFromPythonObject(value, i0, n)){ return NULL; } // Populate the variable if it is a scalar one if(!strchr(var->type(), '*')){ if(V->populate(var)){ return NULL; } } Py_RETURN_NONE; }