1 /////////////////////////////////////////
2 //
3 //   OpenLieroX
4 //
5 //   Auxiliary Software class library
6 //
7 //   based on the work of JasonB
8 //   enhanced by Dark Charlie and Albert Zeyer
9 //
10 //   code under LGPL
11 //
12 /////////////////////////////////////////
13 
14 
15 // Command/variable parsing header
16 // Created 9/4/02
17 // Jason Boettcher
18 
19 
20 #ifndef __CON_COMMAND_H__
21 #define __CON_COMMAND_H__
22 
23 #include <string>
24 #include <vector>
25 #include <map>
26 
27 typedef std::map<size_t,size_t> ParamSeps;
28 
29 ParamSeps ParseParams_Seps(const std::string& params);
30 std::vector<std::string> ParseParams(const std::string& params);
31 
32 struct CmdLineIntf;
33 class AutocompletionInfo;
34 
35 CmdLineIntf& stdoutCLI();
36 
37 
38 
39 // Colours
40 enum CmdLineMsgType {
41 	CNC_NORMAL = 0,
42 	CNC_NOTIFY = 1, //Color(200,200,200)
43 	CNC_ERROR = 2, //Color(255,0,0)
44 	CNC_WARNING = 3, //Color(200,128,128)
45 	CNC_DEV = 4, //Color(100,100,255)
46 	CNC_CHAT = 5, //Color(100,255,100)
47 };
48 
CmdLineMsgTypeAsString(CmdLineMsgType type)49 inline std::string CmdLineMsgTypeAsString(CmdLineMsgType type) {
50 	switch (type) {
51 		case CNC_NORMAL: return "";
52 		case CNC_NOTIFY: return "NOTIFY";
53 		case CNC_ERROR: return "ERROR";
54 		case CNC_WARNING: return "WARNING";
55 		case CNC_DEV: return "DEV";
56 		case CNC_CHAT: return "CHAT";
57 	}
58 	return "INVALIDMSGTYPE";
59 }
60 
61 
62 /*
63 	The intended way to use:
64 
65 	After pushing a CLI::Command to the command queue, you have to wait
66 	and you will get multiple pushReturnArg calls and at the end a
67 	finalizeReturn call. You can do any further handling in the finalizeReturn
68 	call.
69 
70 	At the very end, you also get a finishedCommand call. This one is ignored
71 	in most CLI implementations. The chat CLI uses is to destroy itself
72 	because it has an own instance for each executed command.
73 */
74 struct CmdLineIntf {
75 	virtual void pushReturnArg(const std::string& str) = 0;
76 	virtual void finalizeReturn() = 0;
77 	virtual void writeMsg(const std::string& msg, CmdLineMsgType type = CNC_NORMAL) = 0;
finishedCommandCmdLineIntf78 	virtual void finishedCommand(const std::string& cmd) {} // gets called after a cmd was executed from this CLI
~CmdLineIntfCmdLineIntf79 	virtual ~CmdLineIntf() {}
80 
81 	struct Command {
82 		CmdLineIntf* sender;
83 		std::string cmd;
CommandCmdLineIntf::Command84 		Command(CmdLineIntf* s, const std::string& c) : sender(s), cmd(c) {}
85 	};
86 
87 
88 };
89 
90 
91 // Pushs a command into the command queue. This will not do any parsing nor executing.
92 // All that is done when you call HandlePendingCommands().
93 void Execute(const CmdLineIntf::Command& cmd);
Execute(CmdLineIntf * sender,const std::string & cmd)94 inline void Execute(CmdLineIntf* sender, const std::string& cmd) { Execute(CmdLineIntf::Command(sender, cmd)); }
95 
96 // Executes all commands in the queue. This is called from the gameloopthread.
97 void HandlePendingCommands();
98 
99 
100 #endif  //  __CON_COMMAND_H__
101