MCPcopy Create free account
hub / github.com/covscript/covscript / convert

Method convert

include/covscript/core/cni.hpp:361–380  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

359 struct try_convert_and_check {
360 using source_type = typename cni_decayed_convertor<_SourceT, _TargetT>::source_type;
361 static _TargetT convert(any &val)
362 {
363 if (val.is_type_of<source_type>()) {
364 try {
365 return cni_decayed_convertor<_SourceT, _TargetT>::convert_to_cpp(val);
366 }
367 catch (...) {
368 throw cs::runtime_error("Type Conversion Failed. At " + std::to_string(index + 1) + ". Expected " +
369 cxx_demangle(get_name_of_type<_TargetT>()) + ", provided " +
370 cxx_demangle(get_name_of_type<_SourceT>()));
371 }
372 }
373 else if (val.is_type_of<_TargetT>())
374 return convert_helper<_TargetT>::get_val(val);
375 else
376 throw cs::runtime_error("Invalid Argument. At " + std::to_string(index + 1) + ". Expected " +
377 cxx_demangle(get_name_of_type<_TargetT>()) + ", compatible with " +
378 cxx_demangle(get_name_of_type<source_type>()) + ", provided " +
379 val.get_type_name());
380 }
381 };
382
383 template <typename _TargetT, typename _CheckT, std::size_t index>

Callers

nothing calls this directly

Calls 4

runtime_errorClass · 0.85
cxx_demangleFunction · 0.85
get_type_nameMethod · 0.80
to_stringFunction · 0.70

Tested by

no test coverage detected