-
Notifications
You must be signed in to change notification settings - Fork 0
/
CmdSystem.h
69 lines (49 loc) · 1.53 KB
/
CmdSystem.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#ifndef CMDSYSTEM_H
#define CMDSYSTEM_H
#include <string>
#include "CommandArgs.h"
#include <string_view>
#include <unordered_map>
#include <vector>
typedef void ( *cmdFunction_t )( const CommandArgs &args );
struct Command
{
Command() = default;
~Command() = default;
Command( std::string_view n, cmdFunction_t f, std::string_view d = "" ) : name( n ), function( f ), description( d )
{
}
std::string name;
cmdFunction_t function;
std::string description;
};
class CmdSystem final
{
private:
static constexpr unsigned int MAX_BUFFER_SIZE = 0x3FFF + 1;
unsigned int wait = 0;
unsigned int buffLength = 0;
std::string buffer;
std::unordered_map<std::string, Command> commands;
public:
CmdSystem();
~CmdSystem() = default;
void AddCommand( const std::string &name, cmdFunction_t function, std::string_view desc );
void ExecuteCommandBuffer();
void AppendCommandText( std::string_view text );
void InsertCommandText( std::string_view text );
void ExecuteCommandText( std::string_view text );
std::vector<std::pair<std::string, std::string>> GetAutocompleteList( std::string_view name );
private:
void setWait( const unsigned int n );
void execute( const CommandArgs &args );
friend void List_f( const CommandArgs &args );
friend void Echo_f( const CommandArgs &args );
friend void Wait_f( const CommandArgs &args );
};
inline void CmdSystem::setWait( const unsigned int n )
{
wait = n + 1;
}
inline CmdSystem commandSys;
#endif // CMDSYSTEM_H