1.1 --- a/lemon/arg_parser.cc Mon Jul 14 09:37:51 2008 +0100
1.2 +++ b/lemon/arg_parser.cc Mon Jul 14 10:55:43 2008 +0100
1.3 @@ -239,11 +239,11 @@
1.4 return *this;
1.5 }
1.6
1.7 - void ArgParser::show(std::ostream &os,Opts::iterator i)
1.8 + void ArgParser::show(std::ostream &os,Opts::const_iterator i) const
1.9 {
1.10 os << "-" << i->first;
1.11 if(i->second.has_syn)
1.12 - for(Opts::iterator j=_opts.begin();j!=_opts.end();++j)
1.13 + for(Opts::const_iterator j=_opts.begin();j!=_opts.end();++j)
1.14 if(j->second.syn&&j->second.help==i->first)
1.15 os << "|-" << j->first;
1.16 switch(i->second.type) {
1.17 @@ -261,9 +261,9 @@
1.18 }
1.19 }
1.20
1.21 - void ArgParser::show(std::ostream &os,Groups::iterator i)
1.22 + void ArgParser::show(std::ostream &os,Groups::const_iterator i) const
1.23 {
1.24 - GroupData::Opts::iterator o=i->second.opts.begin();
1.25 + GroupData::Opts::const_iterator o=i->second.opts.begin();
1.26 while(o!=i->second.opts.end()) {
1.27 show(os,_opts.find(*o));
1.28 ++o;
1.29 @@ -271,7 +271,7 @@
1.30 }
1.31 }
1.32
1.33 - void ArgParser::showHelp(Opts::iterator i)
1.34 + void ArgParser::showHelp(Opts::const_iterator i) const
1.35 {
1.36 if(i->second.help.size()==0||i->second.syn) return;
1.37 std::cerr << " ";
1.38 @@ -279,20 +279,21 @@
1.39 std::cerr << std::endl;
1.40 std::cerr << " " << i->second.help << std::endl;
1.41 }
1.42 - void ArgParser::showHelp(std::vector<ArgParser::OtherArg>::iterator i)
1.43 + void ArgParser::showHelp(std::vector<ArgParser::OtherArg>::const_iterator i)
1.44 + const
1.45 {
1.46 if(i->help.size()==0) return;
1.47 std::cerr << " " << i->name << std::endl
1.48 << " " << i->help << std::endl;
1.49 }
1.50
1.51 - void ArgParser::shortHelp()
1.52 + void ArgParser::shortHelp() const
1.53 {
1.54 const unsigned int LINE_LEN=77;
1.55 const std::string indent(" ");
1.56 std::cerr << "Usage:\n " << _command_name;
1.57 int pos=_command_name.size()+2;
1.58 - for(Groups::iterator g=_groups.begin();g!=_groups.end();++g) {
1.59 + for(Groups::const_iterator g=_groups.begin();g!=_groups.end();++g) {
1.60 std::ostringstream cstr;
1.61 cstr << ' ';
1.62 if(!g->second.mandatory) cstr << '[';
1.63 @@ -305,7 +306,7 @@
1.64 std::cerr << cstr.str();
1.65 pos+=cstr.str().size();
1.66 }
1.67 - for(Opts::iterator i=_opts.begin();i!=_opts.end();++i)
1.68 + for(Opts::const_iterator i=_opts.begin();i!=_opts.end();++i)
1.69 if(!i->second.ingroup&&!i->second.syn) {
1.70 std::ostringstream cstr;
1.71 cstr << ' ';
1.72 @@ -319,7 +320,7 @@
1.73 std::cerr << cstr.str();
1.74 pos+=cstr.str().size();
1.75 }
1.76 - for(std::vector<OtherArg>::iterator i=_others_help.begin();
1.77 + for(std::vector<OtherArg>::const_iterator i=_others_help.begin();
1.78 i!=_others_help.end();++i)
1.79 {
1.80 std::ostringstream cstr;
1.81 @@ -335,18 +336,18 @@
1.82 std::cerr << std::endl;
1.83 }
1.84
1.85 - void ArgParser::showHelp()
1.86 + void ArgParser::showHelp() const
1.87 {
1.88 shortHelp();
1.89 std::cerr << "Where:\n";
1.90 - for(std::vector<OtherArg>::iterator i=_others_help.begin();
1.91 + for(std::vector<OtherArg>::const_iterator i=_others_help.begin();
1.92 i!=_others_help.end();++i) showHelp(i);
1.93 - for(Opts::iterator i=_opts.begin();i!=_opts.end();++i) showHelp(i);
1.94 + for(Opts::const_iterator i=_opts.begin();i!=_opts.end();++i) showHelp(i);
1.95 exit(1);
1.96 }
1.97
1.98
1.99 - void ArgParser::unknownOpt(std::string arg)
1.100 + void ArgParser::unknownOpt(std::string arg) const
1.101 {
1.102 std::cerr << "\nUnknown option: " << arg << "\n";
1.103 std::cerr << "\nType '" << _command_name <<
1.104 @@ -354,7 +355,7 @@
1.105 exit(1);
1.106 }
1.107
1.108 - void ArgParser::requiresValue(std::string arg, OptType t)
1.109 + void ArgParser::requiresValue(std::string arg, OptType t) const
1.110 {
1.111 std::cerr << "Argument '" << arg << "' requires a";
1.112 switch(t) {
1.113 @@ -375,10 +376,10 @@
1.114 }
1.115
1.116
1.117 - void ArgParser::checkMandatories()
1.118 + void ArgParser::checkMandatories() const
1.119 {
1.120 bool ok=true;
1.121 - for(Opts::iterator i=_opts.begin();i!=_opts.end();++i)
1.122 + for(Opts::const_iterator i=_opts.begin();i!=_opts.end();++i)
1.123 if(i->second.mandatory&&!i->second.set)
1.124 {
1.125 if(ok)
1.126 @@ -387,18 +388,18 @@
1.127 ok=false;
1.128 showHelp(i);
1.129 }
1.130 - for(Groups::iterator i=_groups.begin();i!=_groups.end();++i)
1.131 + for(Groups::const_iterator i=_groups.begin();i!=_groups.end();++i)
1.132 if(i->second.mandatory||i->second.only_one)
1.133 {
1.134 int set=0;
1.135 - for(GroupData::Opts::iterator o=i->second.opts.begin();
1.136 + for(GroupData::Opts::const_iterator o=i->second.opts.begin();
1.137 o!=i->second.opts.end();++o)
1.138 if(_opts.find(*o)->second.set) ++set;
1.139 if(i->second.mandatory&&!set) {
1.140 std::cerr << _command_name <<
1.141 ": At least one of the following arguments is mandatory.\n";
1.142 ok=false;
1.143 - for(GroupData::Opts::iterator o=i->second.opts.begin();
1.144 + for(GroupData::Opts::const_iterator o=i->second.opts.begin();
1.145 o!=i->second.opts.end();++o)
1.146 showHelp(_opts.find(*o));
1.147 }
1.148 @@ -406,7 +407,7 @@
1.149 std::cerr << _command_name <<
1.150 ": At most one of the following arguments can be given.\n";
1.151 ok=false;
1.152 - for(GroupData::Opts::iterator o=i->second.opts.begin();
1.153 + for(GroupData::Opts::const_iterator o=i->second.opts.begin();
1.154 o!=i->second.opts.end();++o)
1.155 showHelp(_opts.find(*o));
1.156 }