21 #ifndef GRT_COMMAND_LINE_PARSER_HEADER
22 #define GRT_COMMAND_LINE_PARSER_HEADER
46 CommandLineParser():infoLog(
"[CommandLineParser]"),errorLog(
"[ERROR CommandLineParser]"),warningLog(
"[WARNING CommandLineParser]"){}
53 bool addOption(
const std::string option,
const std::string destination){
54 options[option] = destination;
58 bool parse(
const int argc,
const char * argv[] ){
62 std::map<std::string,std::string>::iterator it;
63 for(
int i=1; i<argc; i++){
66 it = options.find( std::string(argv[i]) );
67 if( it != options.end() ){
68 results[ it->second ] = std::string(argv[i+1]);
75 template<
class T>
bool get(
const std::string destination,T &option,T defaultValue = T()){
78 std::map<std::string,std::string>::iterator it;
79 it = results.find( destination );
81 if( it == results.end() ){
82 option = defaultValue;
83 warningLog <<
"get(const std::string destination,T &option) - Failed to find destination: " << destination << endl;
88 std::stringstream s( it->second );
92 warningLog <<
"get(const std::string destination,T &option) - Can not parse type: " <<
typeid( option ).name() << endl;
100 WarningLog warningLog;
102 std::map< std::string, std::string > options;
103 std::map< std::string, std::string > results;
109 #endif //GRT_COMMAND_LINE_PARSER_HEADER
This file contains the Util class, a wrapper for a number of generic functions that are used througho...