[+] const AuList<AuString> &AuCmdLine::GetValues(const AuString &key)

This commit is contained in:
Reece Wilson 2023-09-15 20:12:01 +01:00
parent ac86fd481b
commit e3a493bf9c
2 changed files with 44 additions and 9 deletions

View File

@ -13,21 +13,21 @@ namespace Aurora::CmdLine
/**
* @brief Returns a UTF-8 string array of argv[1, ...]
* @return
*/
*/
AUKN_SYM const AuList<AuString> &GetCommandLineArguments();
/**
* @brief Performs a check on whether the exact key matches an argument
* @param key
* @return
*/
*/
AUKN_SYM bool HasFlag(const AuString &key);
/**
* @brief Performs a check on whether such string came before an equals sign
* @param key
* @return
*/
*/
AUKN_SYM bool HasValue(const AuString &key);
/**
@ -35,25 +35,33 @@ namespace Aurora::CmdLine
* @param key
* @param defaultValue
* @return
*/
*/
AUKN_SYM const AuString &GetValue(const AuString &key, const AuString &defaultValue);
/**
* @brief Returns part after key= or an empty string
* @param key
* @return
*/
*/
AUKN_SYM const AuString &GetValue(const AuString &key);
/**
* @brief Returns a constant array of values; key=values and /key values
* @param key
* @return
* @warning multiple of @param key must exist
*/
AUKN_SYM const AuList<AuString> &GetValues(const AuString &key);
/**
* @brief Returns a constant array of flag keys
* @return
*/
*/
AUKN_SYM const AuList<AuString> &GetFlags();
/**
* @brief Returns a constant array of value keys
* @return
*/
*/
AUKN_SYM const AuList<AuString> &GetValues();
}

View File

@ -15,6 +15,7 @@ namespace Aurora::CmdLine
static AuList<AuString> gCmdFlags;
static AuList<AuString> gCmdValues;
static AuHashMap<AuString, AuString> gCmdValueMap;
static AuHashMap<AuString, AuList<AuString>> gCmdValueArrayMap;
static AuHashMap<AuString, bool> gCmdFlagLookup;
static AuList<AuString> gCmdLineString;
@ -30,7 +31,8 @@ namespace Aurora::CmdLine
AUKN_SYM bool HasValue(const AuString &key)
{
return gCmdValueMap.find(key) != gCmdValueMap.end();
return gCmdValueArrayMap.find(key) != gCmdValueArrayMap.end() ||
gCmdValueMap.find(key) != gCmdValueMap.end();
}
AUKN_SYM const AuString &GetValue(const AuString &key, const AuString &defaultValue)
@ -45,6 +47,17 @@ namespace Aurora::CmdLine
return GetValue(key, kEmptyString);
}
AUKN_SYM const AuList<AuString> &GetValues(const AuString &key)
{
static AuList<AuString> kMissing;
auto itr = gCmdValueArrayMap.find(key);
if (itr != gCmdValueArrayMap.end())
{
return itr->second;
}
return kMissing;
}
AUKN_SYM const AuList<AuString> &GetFlags()
{
return gCmdFlags;
@ -125,7 +138,21 @@ namespace Aurora::CmdLine
}
gCmdValues.push_back(key);
gCmdValueMap[key] = extendedLine;
{
auto itr = gCmdValueMap.find(key);
if (itr != gCmdValueMap.end())
{
auto val = (*itr).second;
gCmdValueMap.erase(itr);
auto &arry = gCmdValueArrayMap[key];
arry.push_back(val);
arry.push_back(extendedLine);
}
else
{
gCmdValueMap[key] = extendedLine;
}
}
}
extendedLine.clear();