21 #ifndef GRT_COMMAND_LINE_PARSER_HEADER
22 #define GRT_COMMAND_LINE_PARSER_HEADER
36 #include "WarningLog.h"
46 CommandLineParser():infoLog(
"[CommandLineParser]"),errorLog(
"[ERROR CommandLineParser]"),warningLog(
"[WARNING CommandLineParser]"){}
60 bool addOption(
const std::string &option,
const std::string &
id){
63 std::map<std::string,std::string>::iterator it = options.find( option );
64 if( it != options.end() ){
80 bool parse(
const int argc,
char * argv[] ){
84 std::map<std::string,std::string>::iterator it;
85 for(
int i=1; i<argc; i++){
88 it = options.find( std::string(argv[i]) );
89 if( it != options.end() ){
90 results[ it->second ] = std::string(argv[i+1]);
106 template<
class T>
bool get(
const std::string &id,T &value,T defaultValue = T()){
109 std::map<std::string,std::string>::iterator it;
110 it = results.find(
id );
112 if( it == results.end() ){
113 value = defaultValue;
114 warningLog <<
"get(const std::string &id,T &value) - Failed to find id: " <<
id << std::endl;
120 std::stringstream s( it->second );
124 value = defaultValue;
125 warningLog <<
"get(const std::string &id,T &value) - Can not parse type: " <<
typeid( value ).name() << std::endl;
141 std::map<std::string,std::string>::iterator it;
142 it = results.find(
id );
144 if( it == results.end() ){
145 warningLog <<
"validate(const std::string ) - Failed to find id: " <<
id << std::endl;
160 infoLog.setEnableInstanceLogging( loggingEnabled );
171 warningLog.setEnableInstanceLogging( loggingEnabled );
182 errorLog.setEnableInstanceLogging( loggingEnabled );
190 std::map< std::string, std::string > options;
191 std::map< std::string, std::string > results;
197 #endif //GRT_COMMAND_LINE_PARSER_HEADER
bool addOption(const std::string &option, const std::string &id)
bool validate(const std::string &id)
bool setWarningLoggingEnabled(const bool loggingEnabled)
virtual ~CommandLineParser()
bool parse(const int argc, char *argv[])
bool setErrorLoggingEnabled(const bool loggingEnabled)
bool setInfoLoggingEnabled(const bool loggingEnabled)