| 408 | |
| 409 | template<typename _Ty> |
| 410 | _Ty getValueFromMisc(const char* key, const tomoto::RawDoc::MiscType& misc, const char* failMsg) |
| 411 | { |
| 412 | auto it = misc.find(key); |
| 413 | if (it == misc.end()) throw std::runtime_error{ failMsg + std::string{ " (the required value was not given)" } }; |
| 414 | auto obj = (PyObject*)std::get<std::shared_ptr<void>>(it->second).get(); |
| 415 | _Ty ret; |
| 416 | if (!py::toCpp(obj, ret)) |
| 417 | { |
| 418 | throw std::runtime_error{ failMsg + (" (given " + py::repr(obj) + ")") }; |
| 419 | } |
| 420 | return ret; |
| 421 | } |
| 422 | |
| 423 | template<typename _Ty> |
| 424 | _Ty getValueFromMiscDefault(const char* key, const tomoto::RawDoc::MiscType& misc, const char* failMsg, const _Ty& def = {}) |