SleakEngine
0.1.0
C++23 multi-backend game engine
Toggle main menu visibility
Loading...
Searching...
No Matches
CommandLine.cpp
Go to the documentation of this file.
1
#include <
Core/CommandLine.hpp
>
2
#include <iostream>
3
4
namespace
Sleak
{
5
6
std::unordered_map<std::string, std::string> CommandLine::s_values;
7
std::unordered_set<std::string> CommandLine::s_flags;
8
void(*CommandLine::s_helpCallback)(
const
char
* exe) =
nullptr
;
9
10
void
CommandLine::SetHelpCallback
(
void
(*callback)(
const
char
* exe)) {
11
s_helpCallback = callback;
12
}
13
14
void
CommandLine::Parse
(
int
argc,
char
** argv) {
15
s_values.clear();
16
s_flags.clear();
17
18
for
(
int
i = 1; i < argc; ++i) {
19
std::string a = argv[i];
20
if
(a.empty())
continue
;
21
22
if
(a ==
"help"
|| a ==
"--help"
|| a ==
"-help"
) {
23
if
(s_helpCallback) s_helpCallback(argv[0]);
24
continue
;
25
}
26
27
if
(a.size() >= 2 && a[0] ==
'-'
&& a[1] ==
'-'
) {
28
// Boolean flag: --bench, --fullscreen, --vsync …
29
s_flags.insert(a);
30
}
else
if
(a[0] ==
'-'
) {
31
// Key-value flag: -r vulkan -w 1920 -world MyWorld …
32
// Next token is the value if it doesn't start with '-'.
33
if
(i + 1 < argc && argv[i + 1][0] !=
'-'
) {
34
s_values[a] = argv[++i];
35
}
else
{
36
// No value → treat as boolean flag
37
s_flags.insert(a);
38
}
39
}
40
}
41
}
42
43
std::string
CommandLine::GetValue
(
const
std::string& flag,
44
const
std::string& defaultVal) {
45
auto
it = s_values.find(flag);
46
return
(it != s_values.end()) ? it->second : defaultVal;
47
}
48
49
bool
CommandLine::HasFlag
(
const
std::string& flag) {
50
return
s_flags.count(flag) > 0;
51
}
52
53
}
// namespace Sleak
CommandLine.hpp
Sleak::CommandLine::GetValue
static std::string GetValue(const std::string &flag, const std::string &defaultVal="")
Returns the raw string value stored for -flag, or defaultVal if it was not passed.
Definition
CommandLine.cpp:43
Sleak::CommandLine::SetHelpCallback
static void SetHelpCallback(void(*callback)(const char *exe))
Definition
CommandLine.cpp:10
Sleak::CommandLine::HasFlag
static bool HasFlag(const std::string &flag)
True if --flag was present on the command line.
Definition
CommandLine.cpp:49
Sleak::CommandLine::Parse
static void Parse(int argc, char **argv)
Parses argv into the value/flag tables. Call once from main(), before Application.
Definition
CommandLine.cpp:14
Sleak
Root namespace for everything the engine exposes.
Definition
Camera.hpp:10
src
Core
CommandLine.cpp
Generated on
for SleakEngine by
1.18.0