lemon/arg_parser.h
changeset 2621 814ba94d9989
parent 2553 bfced05fa852
equal deleted inserted replaced
7:fffdfde03b96 8:a3681377d924
   308       RefType(ArgParser &p,const std::string &n) :_parser(p),_name(n) {}
   308       RefType(ArgParser &p,const std::string &n) :_parser(p),_name(n) {}
   309       ///\e
   309       ///\e
   310       operator bool() 
   310       operator bool() 
   311       {
   311       {
   312 	Opts::iterator i = _parser._opts.find(_name);
   312 	Opts::iterator i = _parser._opts.find(_name);
   313 	LEMON_ASSERT(i==_parser._opts.end(),
   313 	LEMON_ASSERT(i!=_parser._opts.end(),
   314 		     std::string()+"Unkown option: '"+_name+"'");
   314 		     std::string()+"Unkown option: '"+_name+"'");
   315 	LEMON_ASSERT(i->second.type!=ArgParser::BOOL,
   315 	LEMON_ASSERT(i->second.type==ArgParser::BOOL,
   316 		     std::string()+"'"+_name+"' is a bool option");
   316 		     std::string()+"'"+_name+"' is a bool option");
   317 	return *(i->second.bool_p);
   317 	return *(i->second.bool_p);
   318       }
   318       }
   319       ///\e
   319       ///\e
   320       operator std::string()
   320       operator std::string()
   321       {
   321       {
   322 	Opts::iterator i = _parser._opts.find(_name);
   322 	Opts::iterator i = _parser._opts.find(_name);
   323 	LEMON_ASSERT(i==_parser._opts.end(),
   323 	LEMON_ASSERT(i!=_parser._opts.end(),
   324 		     std::string()+"Unkown option: '"+_name+"'");
   324 		     std::string()+"Unkown option: '"+_name+"'");
   325 	LEMON_ASSERT(i->second.type!=ArgParser::STRING,
   325 	LEMON_ASSERT(i->second.type==ArgParser::STRING,
   326 		     std::string()+"'"+_name+"' is a string option");
   326 		     std::string()+"'"+_name+"' is a string option");
   327 	return *(i->second.string_p);
   327 	return *(i->second.string_p);
   328       }
   328       }
   329       ///\e
   329       ///\e
   330       operator double() 
   330       operator double() 
   331       {
   331       {
   332 	Opts::iterator i = _parser._opts.find(_name);
   332 	Opts::iterator i = _parser._opts.find(_name);
   333 	LEMON_ASSERT(i==_parser._opts.end(),
   333 	LEMON_ASSERT(i!=_parser._opts.end(),
   334 		     std::string()+"Unkown option: '"+_name+"'");
   334 		     std::string()+"Unkown option: '"+_name+"'");
   335 	LEMON_ASSERT(i->second.type!=ArgParser::DOUBLE &&
   335 	LEMON_ASSERT(i->second.type==ArgParser::DOUBLE ||
   336 		     i->second.type!=ArgParser::INTEGER,
   336 		     i->second.type==ArgParser::INTEGER,
   337 		     std::string()+"'"+_name+"' is a floating point option");
   337 		     std::string()+"'"+_name+"' is a floating point option");
   338 	return i->second.type==ArgParser::DOUBLE ?
   338 	return i->second.type==ArgParser::DOUBLE ?
   339 	  *(i->second.double_p) : *(i->second.int_p);
   339 	  *(i->second.double_p) : *(i->second.int_p);
   340       }
   340       }
   341       ///\e
   341       ///\e
   342       operator int() 
   342       operator int() 
   343       {
   343       {
   344 	Opts::iterator i = _parser._opts.find(_name);
   344 	Opts::iterator i = _parser._opts.find(_name);
   345 	LEMON_ASSERT(i==_parser._opts.end(),
   345 	LEMON_ASSERT(i!=_parser._opts.end(),
   346 		     std::string()+"Unkown option: '"+_name+"'");
   346 		     std::string()+"Unkown option: '"+_name+"'");
   347 	LEMON_ASSERT(i->second.type!=ArgParser::INTEGER,
   347 	LEMON_ASSERT(i->second.type==ArgParser::INTEGER,
   348 		     std::string()+"'"+_name+"' is an integer option");
   348 		     std::string()+"'"+_name+"' is an integer option");
   349 	return *(i->second.int_p);
   349 	return *(i->second.int_p);
   350       }
   350       }
   351 
   351 
   352     };
   352     };