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:
@@ -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
|
||||
|
Reference in New Issue
Block a user