lemon/arg_parser.h
changeset 215 17c644f5f98d
parent 209 765619b7cbb2
child 261 1c2ac7deb5d8
     1.1 --- a/lemon/arg_parser.h	Mon Jul 14 09:37:51 2008 +0100
     1.2 +++ b/lemon/arg_parser.h	Mon Jul 14 10:55:43 2008 +0100
     1.3 @@ -271,17 +271,20 @@
     1.4  
     1.5      ///@}
     1.6  
     1.7 -    void show(std::ostream &os,Opts::iterator i);
     1.8 -    void show(std::ostream &os,Groups::iterator i);
     1.9 -    void showHelp(Opts::iterator i);
    1.10 -    void showHelp(std::vector<OtherArg>::iterator i);
    1.11 -    void shortHelp();
    1.12 -    void showHelp();
    1.13 +  private:
    1.14 +    void show(std::ostream &os,Opts::const_iterator i) const;
    1.15 +    void show(std::ostream &os,Groups::const_iterator i) const;
    1.16 +    void showHelp(Opts::const_iterator i) const;
    1.17 +    void showHelp(std::vector<OtherArg>::const_iterator i) const;
    1.18  
    1.19 -    void unknownOpt(std::string arg);
    1.20 +    void unknownOpt(std::string arg) const;
    1.21  
    1.22 -    void requiresValue(std::string arg, OptType t);
    1.23 -    void checkMandatories();
    1.24 +    void requiresValue(std::string arg, OptType t) const;
    1.25 +    void checkMandatories() const;
    1.26 +
    1.27 +    void shortHelp() const;
    1.28 +    void showHelp() const;
    1.29 +  public:
    1.30  
    1.31      ///Start the parsing process
    1.32      ArgParser &parse();
    1.33 @@ -293,12 +296,12 @@
    1.34      }
    1.35  
    1.36      ///Give back the command name (the 0th argument)
    1.37 -    const std::string &commandName() { return _command_name; }
    1.38 +    const std::string &commandName() const { return _command_name; }
    1.39  
    1.40      ///Check if an opion has been given to the command.
    1.41 -    bool given(std::string op)
    1.42 +    bool given(std::string op) const
    1.43      {
    1.44 -      Opts::iterator i = _opts.find(op);
    1.45 +      Opts::const_iterator i = _opts.find(op);
    1.46        return i!=_opts.end()?i->second.set:false;
    1.47      }
    1.48  
    1.49 @@ -311,15 +314,15 @@
    1.50      ///throws an exception (i.e. it performs runtime type checking).
    1.51      class RefType
    1.52      {
    1.53 -      ArgParser &_parser;
    1.54 +      const ArgParser &_parser;
    1.55        std::string _name;
    1.56      public:
    1.57        ///\e
    1.58 -      RefType(ArgParser &p,const std::string &n) :_parser(p),_name(n) {}
    1.59 +      RefType(const ArgParser &p,const std::string &n) :_parser(p),_name(n) {}
    1.60        ///\e
    1.61        operator bool()
    1.62        {
    1.63 -        Opts::iterator i = _parser._opts.find(_name);
    1.64 +        Opts::const_iterator i = _parser._opts.find(_name);
    1.65          LEMON_ASSERT(i!=_parser._opts.end(),
    1.66                       std::string()+"Unkown option: '"+_name+"'");
    1.67          LEMON_ASSERT(i->second.type==ArgParser::BOOL,
    1.68 @@ -329,7 +332,7 @@
    1.69        ///\e
    1.70        operator std::string()
    1.71        {
    1.72 -        Opts::iterator i = _parser._opts.find(_name);
    1.73 +        Opts::const_iterator i = _parser._opts.find(_name);
    1.74          LEMON_ASSERT(i!=_parser._opts.end(),
    1.75                       std::string()+"Unkown option: '"+_name+"'");
    1.76          LEMON_ASSERT(i->second.type==ArgParser::STRING,
    1.77 @@ -339,7 +342,7 @@
    1.78        ///\e
    1.79        operator double()
    1.80        {
    1.81 -        Opts::iterator i = _parser._opts.find(_name);
    1.82 +        Opts::const_iterator i = _parser._opts.find(_name);
    1.83          LEMON_ASSERT(i!=_parser._opts.end(),
    1.84                       std::string()+"Unkown option: '"+_name+"'");
    1.85          LEMON_ASSERT(i->second.type==ArgParser::DOUBLE ||
    1.86 @@ -351,7 +354,7 @@
    1.87        ///\e
    1.88        operator int()
    1.89        {
    1.90 -        Opts::iterator i = _parser._opts.find(_name);
    1.91 +        Opts::const_iterator i = _parser._opts.find(_name);
    1.92          LEMON_ASSERT(i!=_parser._opts.end(),
    1.93                       std::string()+"Unkown option: '"+_name+"'");
    1.94          LEMON_ASSERT(i->second.type==ArgParser::INTEGER,
    1.95 @@ -365,7 +368,7 @@
    1.96  
    1.97      ///Give back the value of an option.
    1.98      ///\sa RefType
    1.99 -    RefType operator[](const std::string &n)
   1.100 +    RefType operator[](const std::string &n) const
   1.101      {
   1.102        return RefType(*this, n);
   1.103      }
   1.104 @@ -374,7 +377,7 @@
   1.105  
   1.106      ///Give back a reference to a vector consisting of the program arguments
   1.107      ///not starting with a '-' character.
   1.108 -    std::vector<std::string> &files() { return _file_args; }
   1.109 +    const std::vector<std::string> &files() const { return _file_args; }
   1.110  
   1.111    };
   1.112  }