/** @file
    $Id$
    $Date$
    $Author$
    @copy © Marc Wäckerlin
    @license LGPL, see file COPYING
    $Log$
    Revision 1.3  2005/02/08 12:31:36  marc
    new static methods to simplify access to options
    Revision 1.2  2004/11/25 18:26:04  marc
    Constness corrected
    Revision 1.1  2004/08/28 16:13:42  marc
    mrw-c++-0.92 (mrw)
    - new file: version.cxx
    - new file header for all sources
    - work around warning in mrw::auto
    - possibility to compile without log4cxx
    - work around bugs in demangle.h and libiberty.h
    - corrections in documentation
    - added simple tracing mechanism
    - more warnings
    - small corrections in Auto<>::Free and a new test for it
    - possibility to compile without stack trace
*/
#include 
#include 
namespace mrw {
  
  const std::string& Param::Value::toString() const throw(std::exception) {
    throw mrw::bad_cast();
  }
  
  int Param::Value::toInt() const throw(std::exception) {
    throw mrw::bad_cast();
  }
  bool Param::Value::toBool() const throw(std::exception) {
    throw mrw::bad_cast();
  }
  void Param::IntValue::operator=(const std::string& s) throw(std::exception) {
    if (!(std::stringstream(s)>>_i)) throw mrw::bad_cast();
  }
  const mrw::SmartPointer& Param::operator[](unsigned int i) const
    throw(std::exception) {
    if (i<_params.size()) return _params[i];
    throw mrw::out_of_range
      (((std::stringstream&)
        (std::stringstream()<<"check failed: "
         <& Param::setable(unsigned int i)
    throw(std::exception) {
    if (i<_params.size()) return _params[i];
    throw mrw::out_of_range
      (((std::stringstream&)
        (std::stringstream()<<"check failed: "
         <second;
  }
  const Opt& Args::find(const std::string& s) const throw(std::exception) {
    LongOpts::const_iterator it(_longopts.find(s));
    if (it==_longopts.end()) throw mrw::out_of_range(s);
    return *it->second;
  }
  Args& Args::parse(int argc, char const*const*const argv)
    throw(std::exception) {
    if (argc>0) _filename = argv[0];
    for (int i(1); isecond->args().size()>=argc)
          throw mrw::invalid_argument(arg);
        it->second->set();
        for (int j(0), l(it->second->args().size()); jsecond->args().setable(j)) = argv[++i];
        }
      } else if (arg.find("-")==0) {            // short arguments
        // first check all, then set all
        for (int j(1), l(arg.size()); jsecond->args().size()>0 &&
              (j+1!=l || i+it->second->args().size()>=argc))
            throw mrw::invalid_argument(arg);
        }
        for (int j(1), l(arg.size()); jsecond->set();
          if (j+1==l && it->second->args().size()>0) {
            for (int k(0); k < it->second->args().size(); ++k) {
              *(it->second->args().setable(k)) = argv[++i];
            }
          }
        }
      } else {
        if (arg!="--") _otherargs.push_back(arg);
        while (++i