summaryrefslogtreecommitdiff
path: root/src/console_internal.h
diff options
context:
space:
mode:
authorLoïc Guilloux <glx22@users.noreply.github.com>2021-04-24 15:19:57 +0200
committerGitHub <noreply@github.com>2021-04-24 15:19:57 +0200
commit888389c28d5f3ad06154e4d2e36de568b6f7966e (patch)
treeb4b342d27ef45202fed571440846e5581a143edf /src/console_internal.h
parentd0e40ab31487cdf59c2fb638bcf553f166f8faf1 (diff)
downloadopenttd-888389c28d5f3ad06154e4d2e36de568b6f7966e.tar.xz
Codechange: Use std::string in console commands/aliases registration, and std::map instead our sorted linked list (#9057)
* Codechange: Use std::string in console commands and aliases registration * Codechange: Use std::map to register console commands * Codechange: Use std::map to register console aliases * Cleanup: Remove now unused function
Diffstat (limited to 'src/console_internal.h')
-rw-r--r--src/console_internal.h36
1 files changed, 21 insertions, 15 deletions
diff --git a/src/console_internal.h b/src/console_internal.h
index 630f69607..ca2f92193 100644
--- a/src/console_internal.h
+++ b/src/console_internal.h
@@ -11,6 +11,7 @@
#define CONSOLE_INTERNAL_H
#include "gfx_type.h"
+#include <map>
static const uint ICON_CMDLN_SIZE = 1024; ///< maximum length of a typed in command
static const uint ICON_MAX_STREAMSIZE = 2048; ///< maximum length of a totally expanded command
@@ -33,9 +34,9 @@ enum ConsoleHookResult {
typedef bool IConsoleCmdProc(byte argc, char *argv[]);
typedef ConsoleHookResult IConsoleHook(bool echo);
struct IConsoleCmd {
- char *name; ///< name of command
- IConsoleCmd *next; ///< next command in list
+ IConsoleCmd(const std::string &name, IConsoleCmdProc *proc, IConsoleHook *hook) : name(name), proc(proc), hook(hook) {}
+ std::string name; ///< name of command
IConsoleCmdProc *proc; ///< process executed when command is typed
IConsoleHook *hook; ///< any special trigger action that needs executing
};
@@ -53,25 +54,31 @@ struct IConsoleCmd {
* - ";" allows for combining commands (see example 'ng')
*/
struct IConsoleAlias {
- char *name; ///< name of the alias
- IConsoleAlias *next; ///< next alias in list
+ IConsoleAlias(const std::string &name, const std::string &cmdline) : name(name), cmdline(cmdline) {}
- char *cmdline; ///< command(s) that is/are being aliased
+ std::string name; ///< name of the alias
+ std::string cmdline; ///< command(s) that is/are being aliased
};
-/* console parser */
-extern IConsoleCmd *_iconsole_cmds; ///< List of registered commands.
-extern IConsoleAlias *_iconsole_aliases; ///< List of registered aliases.
+struct IConsole
+{
+ typedef std::map<std::string, IConsoleCmd> CommandList;
+ typedef std::map<std::string, IConsoleAlias> AliasList;
+
+ /* console parser */
+ static CommandList &Commands();
+ static AliasList &Aliases();
+
+ /* Commands */
+ static void CmdRegister(const std::string &name, IConsoleCmdProc *proc, IConsoleHook *hook = nullptr);
+ static IConsoleCmd *CmdGet(const std::string &name);
+ static void AliasRegister(const std::string &name, const std::string &cmd);
+ static IConsoleAlias *AliasGet(const std::string &name);
+};
/* console functions */
void IConsoleClearBuffer();
-/* Commands */
-void IConsoleCmdRegister(const char *name, IConsoleCmdProc *proc, IConsoleHook *hook = nullptr);
-void IConsoleAliasRegister(const char *name, const char *cmd);
-IConsoleCmd *IConsoleCmdGet(const char *name);
-IConsoleAlias *IConsoleAliasGet(const char *name);
-
/* console std lib (register ingame commands/aliases) */
void IConsoleStdLibRegister();
@@ -81,6 +88,5 @@ bool GetArgumentInteger(uint32 *value, const char *arg);
void IConsoleGUIInit();
void IConsoleGUIFree();
void IConsoleGUIPrint(TextColour colour_code, char *string);
-char *RemoveUnderscores(char *name);
#endif /* CONSOLE_INTERNAL_H */