diff --git a/aegisub/src/command/command.cpp b/aegisub/src/command/command.cpp index 52b3ca532..86fce7993 100644 --- a/aegisub/src/command/command.cpp +++ b/aegisub/src/command/command.cpp @@ -34,7 +34,16 @@ namespace cmd { } void reg(Command *cmd) { - cmd_map[cmd->name()] = cmd; + std::string name = cmd->name(); + if (cmd_map.count(name)) + delete cmd_map[name]; + cmd_map[name] = cmd; + } + + void unreg(std::string const& name) { + iterator it = find_command(name); + delete it->second; + cmd_map.erase(it); } Command *get(std::string const& name) { diff --git a/aegisub/src/command/command.h b/aegisub/src/command/command.h index bc38e3f1e..71ee48bf6 100644 --- a/aegisub/src/command/command.h +++ b/aegisub/src/command/command.h @@ -137,9 +137,13 @@ namespace cmd { void init_builtin_commands(); /// Register a command. - /// @param cmd Command object. + /// @param cmd Command object to register. The command system takes ownership of this object. void reg(Command *cmd); + /// Unregister a command. + /// @param cmd Command name to unregister. The associated command object is deleted. + void unreg(std::string const& name); + /// Call a command. /// @param name Name of the command to call. /// @param c Current Context. @@ -149,6 +153,6 @@ namespace cmd { /// @param Command object. Command* get(std::string const& name); - /// Unregister all commands + /// Unregister and deletes all commands void clear(); } // namespace cmd