1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2025-10-23 01:47:39 +00:00

dialog:: more fixes

This commit is contained in:
Zeno Rogue
2023-08-09 14:22:32 +02:00
parent b6f13b953b
commit 4668321e4e
3 changed files with 25 additions and 12 deletions

View File

@@ -8,11 +8,15 @@ namespace hr {
template<class Sig>
class function;
/* callable objects derived from funbase can be retrieved from hr::function using target_base */
struct funbase { virtual ~funbase() {} };
template<class R, class... Args>
struct function_state_base {
virtual R call(Args...) const = 0;
virtual function_state_base *clone() const = 0;
virtual ~function_state_base() {}
virtual funbase* as_funbase() = 0;
};
template<class T, class R, class... Args>
@@ -25,6 +29,10 @@ struct function_state : function_state_base<R, Args...> {
function_state_base<R, Args...> *clone() const override {
return new function_state(*this);
}
virtual funbase* as_funbase() {
if(std::is_base_of<funbase, T>::value) return (funbase*) (&t_);
return nullptr;
}
};
template<class R, class... Args>
@@ -65,6 +73,10 @@ public:
if(!ptr) return nullptr;
return &ptr->t_;
}
struct funbase* target_base() {
return ptr_->as_funbase();
}
};
} // namespace hr