Modified registration of action handler,
...so that the previous one can be recovered, if needed.
This commit is contained in:
parent
f7a3c326ec
commit
cdd62988d9
2 changed files with 14 additions and 4 deletions
|
@ -342,15 +342,22 @@ static bool call_wml_action_handler(const std::string &cmd,
|
|||
|
||||
namespace game_events {
|
||||
|
||||
void register_action_handler(const std::string &tag, action_handler *h)
|
||||
void register_action_handler(const std::string &tag, action_handler *h,
|
||||
action_handler **previous)
|
||||
{
|
||||
dynamic_wml_action_map::iterator itor = dynamic_wml_actions.find(tag);
|
||||
action_handler *p = NULL;
|
||||
if (itor != dynamic_wml_actions.end()) {
|
||||
delete itor->second;
|
||||
p = itor->second;
|
||||
itor->second = h;
|
||||
} else {
|
||||
dynamic_wml_actions[tag] = h;
|
||||
}
|
||||
if (previous) {
|
||||
*previous = p;
|
||||
} else {
|
||||
delete p;
|
||||
}
|
||||
}
|
||||
|
||||
static bool unit_matches_filter(const unit& u, const vconfig filter,const map_location& loc);
|
||||
|
|
|
@ -201,9 +201,12 @@ namespace game_events
|
|||
|
||||
/**
|
||||
* Registers a WML action_handler for the lifetime of the current event manager.
|
||||
* The handler is automatically destroyed at the end or when overriden.
|
||||
* The handler is automatically destroyed at the end, if still registered.
|
||||
* The previous handler is stored at the memory pointed by @a previous if
|
||||
* nonnull, deleted otherwise.
|
||||
*/
|
||||
void register_action_handler(const std::string &tag, action_handler *);
|
||||
void register_action_handler(const std::string &tag, action_handler *handler,
|
||||
action_handler **previous = NULL);
|
||||
|
||||
} // end namespace game_events
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue