OpenTTD Source  12.0-beta2
console_internal.h
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
10 #ifndef CONSOLE_INTERNAL_H
11 #define CONSOLE_INTERNAL_H
12 
13 #include "gfx_type.h"
14 #include <map>
15 
16 static const uint ICON_CMDLN_SIZE = 1024;
17 static const uint ICON_MAX_STREAMSIZE = 2048;
18 
24 };
25 
34 typedef bool IConsoleCmdProc(byte argc, char *argv[]);
35 typedef ConsoleHookResult IConsoleHook(bool echo);
36 struct IConsoleCmd {
37  IConsoleCmd(const std::string &name, IConsoleCmdProc *proc, IConsoleHook *hook) : name(name), proc(proc), hook(hook) {}
38 
39  std::string name;
41  IConsoleHook *hook;
42 };
43 
56 struct IConsoleAlias {
57  IConsoleAlias(const std::string &name, const std::string &cmdline) : name(name), cmdline(cmdline) {}
58 
59  std::string name;
60  std::string cmdline;
61 };
62 
63 struct IConsole
64 {
65  typedef std::map<std::string, IConsoleCmd> CommandList;
66  typedef std::map<std::string, IConsoleAlias> AliasList;
67 
68  /* console parser */
69  static CommandList &Commands();
70  static AliasList &Aliases();
71 
72  /* Commands */
73  static void CmdRegister(const std::string &name, IConsoleCmdProc *proc, IConsoleHook *hook = nullptr);
74  static IConsoleCmd *CmdGet(const std::string &name);
75  static void AliasRegister(const std::string &name, const std::string &cmd);
76  static IConsoleAlias *AliasGet(const std::string &name);
77 };
78 
79 /* console functions */
80 void IConsoleClearBuffer();
81 
82 /* console std lib (register ingame commands/aliases) */
83 void IConsoleStdLibRegister();
84 
85 /* Supporting functions */
86 bool GetArgumentInteger(uint32 *value, const char *arg);
87 
88 void IConsoleGUIInit();
89 void IConsoleGUIFree();
90 void IConsoleGUIPrint(TextColour colour_code, char *string);
91 
92 #endif /* CONSOLE_INTERNAL_H */
IConsoleCmd::proc
IConsoleCmdProc * proc
process executed when command is typed
Definition: console_internal.h:40
ICON_CMDLN_SIZE
static const uint ICON_CMDLN_SIZE
maximum length of a typed in command
Definition: console_internal.h:16
GetArgumentInteger
bool GetArgumentInteger(uint32 *value, const char *arg)
Change a string into its number representation.
Definition: console.cpp:135
IConsole::AliasGet
static IConsoleAlias * AliasGet(const std::string &name)
Find the alias pointed to by its string.
Definition: console.cpp:201
IConsoleGUIPrint
void IConsoleGUIPrint(TextColour colour_code, char *string)
Handle the printing of text entered into the console or redirected there by any other means.
Definition: console_gui.cpp:512
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:250
IConsoleAlias::cmdline
std::string cmdline
command(s) that is/are being aliased
Definition: console_internal.h:60
IConsoleCmd::hook
IConsoleHook * hook
any special trigger action that needs executing
Definition: console_internal.h:41
IConsoleCmd::name
std::string name
name of command
Definition: console_internal.h:39
IConsole::CmdRegister
static void CmdRegister(const std::string &name, IConsoleCmdProc *proc, IConsoleHook *hook=nullptr)
Register a new command to be used in the console.
Definition: console.cpp:168
ICON_MAX_STREAMSIZE
static const uint ICON_MAX_STREAMSIZE
maximum length of a totally expanded command
Definition: console_internal.h:17
IConsoleCmd
Definition: console_internal.h:36
CHR_ALLOW
@ CHR_ALLOW
Allow command execution.
Definition: console_internal.h:21
IConsoleAlias::name
std::string name
name of the alias
Definition: console_internal.h:59
IConsole::AliasRegister
static void AliasRegister(const std::string &name, const std::string &cmd)
Register a an alias for an already existing command in the console.
Definition: console.cpp:190
IConsoleAlias
–Aliases– Aliases are like shortcuts for complex functions, variable assignments, etc.
Definition: console_internal.h:56
IConsole
Definition: console_internal.h:63
CHR_DISALLOW
@ CHR_DISALLOW
Disallow command execution.
Definition: console_internal.h:22
CHR_HIDE
@ CHR_HIDE
Hide the existence of the command.
Definition: console_internal.h:23
IConsoleCmdProc
bool IConsoleCmdProc(byte argc, char *argv[])
–Commands– Commands are commands, or functions.
Definition: console_internal.h:34
gfx_type.h
ConsoleHookResult
ConsoleHookResult
Return values of console hooks (#IConsoleHook).
Definition: console_internal.h:20
IConsole::CmdGet
static IConsoleCmd * CmdGet(const std::string &name)
Find the command pointed to by its string.
Definition: console.cpp:178
Commands
Commands
List of commands.
Definition: command_type.h:175