Index: code/trunk/src/util/ArgReader.cc
===================================================================
--- code/trunk/src/util/ArgReader.cc	(revision 1505)
+++ code/trunk/src/util/ArgReader.cc	(revision 1535)
@@ -21,7 +21,7 @@
  *
  *   Author:
- *      Benjamin Knecht <beni_at_orxonox.net>, (C) 2007
+ *      Reto Grieder
  *   Co-authors:
- *      ...
+ *      Benjamin Knecht <beni_at_orxonox.net>
  *
  */
@@ -33,78 +33,62 @@
 
 #include "ArgReader.h"
+#include "SubString.h"
 
-#include <iostream>
+ArgReader::ArgReader(int argc, char **argv)
+{
+  failure_ = false;
+  errorString_ = "";
+  CmdLineArg arg;
 
-ArgReader::ArgReader(int argc, char** argv)
-{
-  counter_ = argc;
-  arguments_ = argv;
-  fail_ = false;
-  errorStr_ = "";
-}
+  int i = 1;
+  while (i < argc)
+  {
+    if (argv[i][0] == '-' && argv[i][1] == '-') // name
+    {
+      if (argv[i][2] == '\0')
+      {
+        failure_ = true;
+        errorString_ += "Expected word after \"--\".\n";
+      }
+      arg.bChecked_ = false;
+      arg.name_ = argv[i] + 2;
+      arg.value_ = "";
+      arguments_.push_back(arg);
+    }
+    else // value
+    {
+      if (arguments_.size() == 0)
+      {
+        failure_ = true;
+        errorString_ += "Expected \"--\" in command line arguments.\n";
+        arg.bChecked_ = false;
+        arg.name_ = "";
+        arg.value_ = "";
+        arguments_.push_back(arg);
+      }
 
-void ArgReader::checkArgument(std::string option, std::string &string, bool must)
-{
-  int argpos = checkOption(option) + 1;
-  if(argpos != 0)
-  {
-    string = arguments_[argpos];
+      if (arguments_.back().value_ != "")
+        arguments_.back().value_ += " " + std::string(argv[i]);
+      else
+        arguments_.back().value_ = argv[i];
+    }
+    ++i;
   }
-  else
-  {
-    if(must) {
-      errorStr_ = errorStr_ + "Cannot find mandatory argument \"" + option + "\"\n";
-      fail_ = true;
-    }
-  }
-
-}
-
-void ArgReader::checkArgument(std::string option, int &integer, bool must)
-{
-  int argpos = checkOption(option) + 1;
-  if(argpos != 0)
-  {
-    integer = atoi(arguments_[argpos]);
-  }
-  else
-  {
-    if(must) {
-      errorStr_ = errorStr_ + "Cannot find mandatory argument \"" + option + "\"\n";
-      fail_ = true;
-    }
-  }
-}
-
-void ArgReader::checkArgument(std::string option, float &floating, bool must)
-{
-  int argpos = checkOption(option) + 1;
-  if(argpos != 0)
-  {
-    floating = (float)atof(arguments_[argpos]);
-  }
-  else
-  {
-    if(must) {
-      errorStr_ = errorStr_ + "Cannot find mandatory argument \"" + option + "\"\n";
-      fail_ = true;
-    }
-  }
-}
-
-int ArgReader::checkOption(std::string option)
-{
-  for(int i = 1; i < counter_; i++)
-  {
-    if(arguments_[i] == "--" + option)
-        return i;
-  }
-  return -1;
 }
 
 bool ArgReader::errorHandling()
 {
-  if(fail_)
-    std::cout << errorStr_;
-  return fail_;
+  bool argumentsChecked = true;
+  for (unsigned int i = 1; i < arguments_.size(); ++i)
+    argumentsChecked &= arguments_[i].bChecked_;
+
+  if (!argumentsChecked)
+    errorString_ += "Not all arguments could be matched.\n";
+
+  return !argumentsChecked || failure_;
 }
+
+const std::string& ArgReader::getErrorString()
+{
+  return errorString_;
+}
Index: code/trunk/src/util/ArgReader.h
===================================================================
--- code/trunk/src/util/ArgReader.h	(revision 1505)
+++ code/trunk/src/util/ArgReader.h	(revision 1535)
@@ -21,7 +21,7 @@
  *
  *   Author:
+ *      Reto Grieder
+ *   Co-authors:
  *      Benjamin Knecht <beni_at_orxonox.net>
- *   Co-authors:
- *      ...
  *
  */
@@ -39,4 +39,13 @@
 
 #include <string>
+#include <vector>
+#include "Convert.h"
+
+struct _UtilExport CmdLineArg
+{
+  std::string name_;
+  std::string value_;
+  bool bChecked_;
+};
 
 class _UtilExport ArgReader
@@ -44,17 +53,64 @@
   public:
     ArgReader(int argc, char **argv);
-    void checkArgument(std::string option, std::string& string, bool must=false);
-    void checkArgument(std::string option, int& integer, bool must=false);
-    void checkArgument(std::string option, float& floating, bool must=false);
+    template <class T>
+    void checkArgument(std::string option, T* value, bool must = false);
     bool errorHandling();
-  private:
-    int checkOption(std::string option);
+    const std::string& getErrorString();
 
   private:
-    int counter_;
-    char **arguments_;
-    bool fail_;
-    std::string errorStr_;
+    std::vector<CmdLineArg> arguments_;
+    bool failure_;
+    std::string errorString_;
 };
 
+template <class T>
+void ArgReader::checkArgument(std::string option, T* value, bool must)
+{
+  unsigned int iArg = 0;
+  while (iArg < arguments_.size())
+  {
+    if (arguments_[iArg].name_ == option)
+      break;
+    ++iArg;
+  }
+  if (iArg == arguments_.size())
+  {
+    if (must)
+    {
+      failure_ = true;
+      errorString_ += "Cannot find mandatory argument \"" + option + "\"\n";
+      return;
+    }
+    else
+      return;
+  }
+
+  arguments_[iArg].bChecked_ = true;
+
+  if (!convertValue(value, arguments_[iArg].value_))
+  {
+    failure_ = true;
+    errorString_ += "Cannot convert argument value for option \"" + option + "\"\n";
+  }
+}
+
+template <>
+void ArgReader::checkArgument(std::string option, bool* value, bool must)
+{
+  // for type bool, only check whether the option was set or not
+  unsigned int iArg = 0;
+  while (iArg < arguments_.size())
+  {
+    if (arguments_[iArg].name_ == option)
+    {
+      arguments_[iArg].bChecked_ = true;
+      *value = true;
+      break;
+    }
+    ++iArg;
+  }
+  if (iArg == arguments_.size())
+    *value = false;
+}
+
 #endif /* _ArgReader_H__ */
