-
Notifications
You must be signed in to change notification settings - Fork 415
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from meeh420/master
Adding lightweight option parser
- Loading branch information
Showing
5 changed files
with
72 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include "util.h" | ||
|
||
namespace i2p | ||
{ | ||
namespace util | ||
{ | ||
std::map<std::string, std::string> mapArgs; | ||
|
||
void ParseArguments(int argc, const char* const argv[]) | ||
{ | ||
mapArgs.clear(); | ||
for (int i = 1; i < argc; i++) | ||
{ | ||
std::string strKey (argv[i]); | ||
std::string strValue; | ||
size_t has_data = strKey.find('='); | ||
if (has_data != std::string::npos) | ||
{ | ||
strValue = strKey.substr(has_data+1); | ||
strKey = strKey.substr(0, has_data); | ||
} | ||
if (strKey[0] != '-') | ||
break; | ||
|
||
mapArgs[strKey] = strValue; | ||
} | ||
} | ||
|
||
int GetIntArg(const std::string& strArg, int nDefault) | ||
{ | ||
if (mapArgs.count(strArg)) | ||
return atoi(mapArgs[strArg].c_str()); | ||
return nDefault; | ||
} | ||
|
||
std::string GetStringArg(const std::string& strArg, std::string nDefault) | ||
{ | ||
if (mapArgs.count(strArg)) | ||
return mapArgs[strArg]; | ||
return nDefault; | ||
} | ||
|
||
|
||
} // Namespace end | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#ifndef UTIL_H | ||
#define UTIL_H | ||
|
||
#include <map> | ||
#include <string> | ||
|
||
namespace i2p | ||
{ | ||
namespace util | ||
{ | ||
extern std::map<std::string, std::string> mapArgs; | ||
void ParseArguments(int argc, const char* const argv[]); | ||
int GetIntArg(const std::string& strArg, int nDefault); | ||
|
||
} | ||
} | ||
|
||
|
||
#endif |