Index: lemon/arg_parser.cc
===================================================================
--- lemon/arg_parser.cc	(revision 2402)
+++ lemon/arg_parser.cc	(revision 2406)
@@ -29,5 +29,5 @@
   ArgParser::ArgParser(int argc, char **argv) :_argc(argc), _argv(argv),
 					       _command_name(argv[0]) {
-    refOption("-help","Print a short help message",_showHelp,this);
+    funcOption("-help","Print a short help message",_showHelp,this);
     synonym("help","-help");
     synonym("h","-help");
@@ -122,8 +122,8 @@
   ArgParser &ArgParser::refOption(const std::string &name,
 			       const std::string &help,
-			       int &value, bool obl)
-  {
-    ParData p;
-    p.int_p=&value;
+			       int &ref, bool obl)
+  {
+    ParData p;
+    p.int_p=&ref;
     p.self_delete=false;
     p.help=help;
@@ -136,8 +136,8 @@
   ArgParser &ArgParser::refOption(const std::string &name,
 			       const std::string &help,
-			       double &value, bool obl)
-  {
-    ParData p;
-    p.double_p=&value;
+			       double &ref, bool obl)
+  {
+    ParData p;
+    p.double_p=&ref;
     p.self_delete=false;
     p.help=help;
@@ -150,8 +150,8 @@
   ArgParser &ArgParser::refOption(const std::string &name,
 			       const std::string &help,
-			       bool &value, bool obl)
-  {
-    ParData p;
-    p.bool_p=&value;
+			       bool &ref, bool obl)
+  {
+    ParData p;
+    p.bool_p=&ref;
     p.self_delete=false;
     p.help=help;
@@ -160,5 +160,5 @@
     _opts[name]=p;
 
-    value = false;
+    ref = false;
 
     return *this;
@@ -167,8 +167,8 @@
   ArgParser &ArgParser::refOption(const std::string &name,
 			       const std::string &help,
-			       std::string &value, bool obl)
-  {
-    ParData p;
-    p.string_p=&value;
+			       std::string &ref, bool obl)
+  {
+    ParData p;
+    p.string_p=&ref;
     p.self_delete=false;
     p.help=help;
@@ -179,5 +179,5 @@
   }
 
-  ArgParser &ArgParser::refOption(const std::string &name,
+  ArgParser &ArgParser::funcOption(const std::string &name,
 			       const std::string &help,
 			       void (*func)(void *),void *data)
@@ -198,6 +198,6 @@
   {
     Opts::iterator i = _opts.find(opt);
-    if(i==_opts.end()) exit(3); ///\todo throw exception instead
-    else if(i->second.ingroup) exit(3); ///\todo throw exception instead
+    if(i==_opts.end()) throw LogicError();
+    else if(i->second.ingroup) throw LogicError();
     else {
       GroupData &g=_groups[group];
@@ -221,5 +221,5 @@
     Opts::iterator s = _opts.find(syn);
     if(o==_opts.end()||s!=_opts.end())
-      exit(3); ///\todo throw exception instead
+      throw LogicError();
     else {
       ParData p;
Index: lemon/arg_parser.h
===================================================================
--- lemon/arg_parser.h	(revision 2402)
+++ lemon/arg_parser.h	(revision 2406)
@@ -27,4 +27,5 @@
 #include <sstream>
 #include <algorithm>
+#include <lemon/error.h>
 
 ///\ingroup misc
@@ -152,48 +153,4 @@
 		      std::string value="", bool obl=false);
     
-
-
-
-    ///Add a new integer type option
-
-    ///\param name The name of the option. The leading '-' must be omitted.
-    ///\param help A help string.
-    ///\retval value The value of the argument will be written to this variable.
-    ///\param obl Indicate if the option is mandatory.
-    ArgParser &refOption(const std::string &name,
-		    const std::string &help,
-		    int &value, bool obl=false);
-
-    ///Add a new floating type option
-
-    ///\param name The name of the option. The leading '-' must be omitted.
-    ///\param help A help string.
-    ///\retval value The value of the argument will be written to this variable.
-    ///\param obl Indicate if the option is mandatory.
-    ArgParser &refOption(const std::string &name,
-		      const std::string &help,
-		      double &value, bool obl=false);
-
-    ///Add a new bool type option
-
-    ///\param name The name of the option. The leading '-' must be omitted.
-    ///\param help A help string.
-    ///\retval value The value of the argument will be written to this variable.
-    ///\param obl Indicate if the option is mandatory.
-    ////\note A mandatory bool obtion is of very little use.)
-    ArgParser &refOption(const std::string &name,
-		      const std::string &help,
-		      bool &value, bool obl=false);
-
-    ///Add a new string type option
-
-    ///\param name The name of the option. The leading '-' must be omitted.
-    ///\param help A help string.
-    ///\retval value The value of the argument will be written to this variable.
-    ///\param obl Indicate if the option is mandatory.
-    ArgParser &refOption(const std::string &name,
-		      const std::string &help,
-		      std::string &value, bool obl=false);
-    
     ///Bind a function to an option.
 
@@ -203,7 +160,61 @@
     ///  must be of type "void f(void *)"
     ///\param data Data to be passed to \c func
+    ArgParser &funcOption(const std::string &name,
+		    const std::string &help,
+		    void (*func)(void *),void *data);
+
+    ///\name Options with an external strorage.
+    ///Using this functions, the value of the option will be directly written
+    ///into a variable once the option appears in the command line.
+
+    ///@{
+
+    ///Add a new integer type option with a storage reference
+
+    ///\param name The name of the option. The leading '-' must be omitted.
+    ///\param help A help string.
+    ///\retval ref The value of the argument will be written to this variable.
+    ///\param obl Indicate if the option is mandatory.
     ArgParser &refOption(const std::string &name,
 		    const std::string &help,
-		    void (*func)(void *),void *data);
+		    int &ref, bool obl=false);
+
+    ///Add a new floating type option with a storage reference
+
+    ///\param name The name of the option. The leading '-' must be omitted.
+    ///\param help A help string.
+    ///\retval ref The value of the argument will be written to this variable.
+    ///\param obl Indicate if the option is mandatory.
+    ArgParser &refOption(const std::string &name,
+		      const std::string &help,
+		      double &ref, bool obl=false);
+
+    ///Add a new bool type option with a storage reference
+
+    ///\param name The name of the option. The leading '-' must be omitted.
+    ///\param help A help string.
+    ///\retval ref The value of the argument will be written to this variable.
+    ///\param obl Indicate if the option is mandatory.
+    ////\note A mandatory bool obtion is of very little use.)
+    ArgParser &refOption(const std::string &name,
+		      const std::string &help,
+		      bool &ref, bool obl=false);
+
+    ///Add a new string type option with a storage reference
+
+    ///\param name The name of the option. The leading '-' must be omitted.
+    ///\param help A help string.
+    ///\retval ref The value of the argument will be written to this variable.
+    ///\param obl Indicate if the option is mandatory.
+    ArgParser &refOption(const std::string &name,
+		      const std::string &help,
+		      std::string &ref, bool obl=false);
+    
+    ///@}
+
+    ///\name Option Groups and Synonyms
+    ///
+    
+    ///@{
 
     ///Boundle some options into a group
@@ -222,4 +233,10 @@
     ArgParser &onlyOneGroup(const std::string &group);
   
+    ///Make a group mandatory
+
+    ///Using this function, at least one of the members of \c group
+    ///must be given.
+    ArgParser &mandatoryGroup(const std::string &group);
+    
     ///Create synonym to an option
 
@@ -229,10 +246,6 @@
 			   const std::string &opt);
     
-    ///Make a group mandatory
-
-    ///Using this function, at least one of the members of \c group
-    ///must be given.
-    ArgParser &mandatoryGroup(const std::string &group);
-    
+    ///@}
+
     ///Give help string for non-parsed arguments.
 
@@ -264,5 +277,5 @@
     void checkMandatories();
     
-    ///\e
+    ///Start the parsing process
     ArgParser &parse();
 
@@ -281,4 +294,10 @@
 
 
+    ///Magic type for operator[]
+    
+    ///This is the type of the return value of ArgParser::operator[]().
+    ///It automatically converts to int, double, bool or std::string, if it
+    ///match the type of the option, otherwise it throws an exception.
+    ///(i.e. it performs runtime type checking).
     class RefType 
     {
@@ -286,31 +305,40 @@
       std::string _name;
     public:
+      ///\e
       RefType(ArgParser &p,const std::string &n) :_parser(p),_name(n) {}
+      ///\e
       operator bool() 
       {
 	Opts::iterator i = _parser._opts.find(_name);
-	if(i==_parser._opts.end()) exit(3); ///\todo throw exception instead
-	else if(i->second.type!=ArgParser::BOOL) exit(3);
+	if(i==_parser._opts.end()) throw LogicError();
+	else if(i->second.type!=ArgParser::BOOL)
+	  throw LogicError();
 	else return *(i->second.bool_p);
       }
+      ///\e
       operator std::string()
       {
 	Opts::iterator i = _parser._opts.find(_name);
-	if(i==_parser._opts.end()) exit(3); ///\todo throw exception instead
-	else if(i->second.type!=ArgParser::STRING) exit(3);
+	if(i==_parser._opts.end()) throw LogicError();
+	else if(i->second.type!=ArgParser::STRING)
+	  throw LogicError();
 	else return *(i->second.string_p);
       }
+      ///\e
       operator double() 
       {
 	Opts::iterator i = _parser._opts.find(_name);
-	if(i==_parser._opts.end()) exit(3); ///\todo throw exception instead
-	else if(i->second.type!=ArgParser::DOUBLE) exit(3);
+	if(i==_parser._opts.end()) throw LogicError();
+	else if(i->second.type!=ArgParser::DOUBLE) 
+	  throw LogicError();
 	else return *(i->second.double_p);
       }
+      ///\e
       operator int() 
       {
 	Opts::iterator i = _parser._opts.find(_name);
-	if(i==_parser._opts.end()) exit(3); ///\todo throw exception instead
-	else if(i->second.type!=ArgParser::INTEGER) exit(3);
+	if(i==_parser._opts.end()) throw LogicError();
+	else if(i->second.type!=ArgParser::INTEGER)
+	  throw LogicError();
 	else return *(i->second.int_p);
       }
@@ -318,10 +346,13 @@
     };
 
+    ///Give back the value of an option
+    
+    ///Give back the value of an option
+    ///\sa RefType
     RefType operator[](const std::string &n)
     {
       return RefType(*this, n);
-    }
-    
-      
+    }    
+ 
   };
 }
