MCPcopy Create free account
hub / github.com/NVIDIAGameWorks/Falcor / jsonToPython

Function jsonToPython

Source/Falcor/Utils/Properties.cpp:240–284  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

238}
239
240pybind11::object jsonToPython(const json& j)
241{
242 if (j.is_null())
243 {
244 return pybind11::none();
245 }
246 else if (j.is_boolean())
247 {
248 return pybind11::bool_(j.get<bool>());
249 }
250 else if (j.is_number_unsigned())
251 {
252 return pybind11::int_(j.get<json::number_unsigned_t>());
253 }
254 else if (j.is_number_integer())
255 {
256 return pybind11::int_(j.get<json::number_integer_t>());
257 }
258 else if (j.is_number_float())
259 {
260 return pybind11::float_(j.get<double>());
261 }
262 else if (j.is_string())
263 {
264 return pybind11::str(j.get<std::string>());
265 }
266 else if (j.is_array())
267 {
268 pybind11::list obj(j.size());
269 for (std::size_t i = 0; i < j.size(); i++)
270 {
271 obj[i] = jsonToPython(j[i]);
272 }
273 return std::move(obj);
274 }
275 else // Object
276 {
277 pybind11::dict obj;
278 for (json::const_iterator it = j.cbegin(); it != j.cend(); ++it)
279 {
280 obj[pybind11::str(it.key())] = jsonToPython(it.value());
281 }
282 return std::move(obj);
283 }
284}
285} // namespace
286
287Properties::Properties()

Callers 1

toPythonMethod · 0.85

Calls 4

noneFunction · 0.85
sizeMethod · 0.45
keyMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected