MCPcopy Create free account
hub / github.com/MTG/essentia / PythonDictToParameter

Function PythonDictToParameter

src/python/parsing.cpp:27–61  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25
26
27Parameter* PythonDictToParameter(PyObject* dict, Edt tp) {
28 if (!PyDict_Check(dict)) throw EssentiaException("map parameter not a python dictionary");
29
30 PyObject *key, *value;
31 Py_ssize_t pos = 0;
32
33 switch (tp) {
34 case MAP_VECTOR_REAL: {
35 map<string, vector<Real> > mapVecReal;
36 while (PyDict_Next(dict, &pos, &key, &value)) {
37 if (!PyString_Check(key)) throw EssentiaException("all keys in the dict should be strings");
38
39 string skey = PyString_AS_STRING(key);
40 RogueVector<Real>* rv = (RogueVector<Real>*)VectorReal::fromPythonRef(value);
41 mapVecReal[skey] = *((vector<Real>*)rv);
42 delete rv;
43 }
44 return new Parameter(mapVecReal);
45 }
46
47 case MAP_VECTOR_STRING: {
48 map<string, vector<string> > mapVecString;
49 while (PyDict_Next(dict, &pos, &key, &value)) {
50 if (!PyString_Check(key)) throw EssentiaException("all keys in the dict should be strings");
51
52 string skey = PyString_AS_STRING(key);
53 mapVecString[skey] = *((vector<string>*)VectorString::fromPythonCopy(value));
54 }
55 return new Parameter(mapVecString);
56 }
57
58 default:
59 throw EssentiaException("map type not supported");
60 }
61}
62
63void parseParameters(ParameterMap* pm, PyObject* args, PyObject* keywds) {
64 Py_ssize_t pos = 0;

Callers 1

parseParametersFunction · 0.85

Calls 1

EssentiaExceptionClass · 0.85

Tested by

no test coverage detected