-
Notifications
You must be signed in to change notification settings - Fork 0
/
CCmdlineParams.cpp
64 lines (52 loc) · 1.3 KB
/
CCmdlineParams.cpp
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
#include <Windows.h>
#include "CCmdlineParams.h"
std::map<std::string, std::string> CCmdlineParams::m_paramMap;
UINT CCmdlineParams::Process(const char* pChar)
{
m_paramMap.clear();
size_t pos = 0;
std::string str(pChar), substr;
while ((pos = str.find(" -")) != std::string::npos)
{
substr = str.substr(0, pos);
ProcessSubstr(substr);
str.erase(0, pos + 2);
}
substr = str.substr(pos + 1);
ProcessSubstr(substr);
return m_paramMap.size();
}
void CCmdlineParams::ProcessSubstr(std::string strSubstr)
{
std::pair<std::string, std::string> pair;
size_t pos = strSubstr.find(' ');
if (pos != std::string::npos)
{
pair = std::pair<std::string, std::string>(strSubstr.substr(0, pos), strSubstr.substr(pos + 1));
}
else
{
pair = std::pair<std::string, std::string>(strSubstr, "");
}
m_paramMap.insert(pair);
}
size_t CCmdlineParams::GetArgumentCount()
{
return m_paramMap.size();
}
bool CCmdlineParams::ArgumentExists(std::string strKey)
{
return m_paramMap.count(strKey) > 0;
}
bool CCmdlineParams::ArgumentHasValue(std::string strKey)
{
return m_paramMap.find(strKey)->second.length() > 0;
}
std::string& CCmdlineParams::GetArgumentValue(std::string strKey)
{
return m_paramMap.find(strKey)->second;
}
std::map<std::string, std::string>& CCmdlineParams::GetParamsMap()
{
return m_paramMap;
}