-
Notifications
You must be signed in to change notification settings - Fork 0
/
CommandArgs.h
53 lines (40 loc) · 1.01 KB
/
CommandArgs.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
#ifndef COMMANDARGS_H
#define COMMANDARGS_H
#include <string>
#include <cassert>
#include <string_view>
class CommandArgs final
{
private:
static constexpr unsigned int MAX_ARGS = 32;
unsigned int argc = 0;
std::string argv[MAX_ARGS];
public:
CommandArgs() = default;
explicit CommandArgs( std::string_view command );
~CommandArgs() = default;
void Tokenize( std::string_view command );
unsigned int Argc() const;
std::string_view CommandName() const;
const std::string &operator[]( const unsigned int i ) const;
std::string &operator[]( const unsigned int i );
};
inline unsigned int CommandArgs::Argc() const
{
return argc;
}
inline std::string_view CommandArgs::CommandName() const
{
return argv[0];
}
inline const std::string &CommandArgs::operator[]( const unsigned int i ) const
{
assert( i < argc );
return argv[i];
}
inline std::string &CommandArgs::operator[]( const unsigned int i )
{
assert( i < argc );
return argv[i];
}
#endif // COMMANDARGS_H