Scene file error will throw exemption rather than causing segfault. Change function wrapper classes, use macro for template specialization.
Refactor code to retrieve function pointer by adding function to scene class:
template< class T, class F > std::shared_ptr< F > get_fn_ptr( const std::string& name ) {
if( !functions.contains( name ) ) {
throw std::runtime_error( "function " + name + " not found in scene" );
return nullptr;
}
else {
if( !std::holds_alternative< any_fn< T > >( functions[ name ] ) ) {
throw std::runtime_error( "function " + name + " not of return type " + typeid( T ).name() );
return nullptr;
}
else {
auto fn = std::get< any_fn< T > >( functions[ name ] );
if( !std::holds_alternative< std::shared_ptr< F > >( fn.any_fn_ptr ) ) {
throw std::runtime_error( "function " + name + " not of type " + typeid( F ).name() );
return nullptr;
}
else {
return std::get< std::shared_ptr< F > >( fn.any_fn_ptr );
}
}
}
}
Scene file error will throw exemption rather than causing segfault. Change function wrapper classes, use macro for template specialization.
Refactor code to retrieve function pointer by adding function to scene class: