[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[oMetah-devel] ometah/interface itsArgument.cpp itsArgument.hp...
From: |
Jean-Philippe Aumasson |
Subject: |
[oMetah-devel] ometah/interface itsArgument.cpp itsArgument.hp... |
Date: |
Thu, 02 Jun 2005 08:42:48 -0400 |
CVSROOT: /cvsroot/ometah
Module name: ometah
Branch:
Changes by: Jean-Philippe Aumasson <address@hidden> 05/06/02 12:42:47
Modified files:
interface : itsArgument.cpp itsArgument.hpp ometah.cpp
ometah.hpp
Log message:
* command line parameters are successfully catched with defArg, value
returned with getValue functions
* no syntax checking, neither associated value correctness
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/interface/itsArgument.cpp.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/interface/itsArgument.hpp.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/interface/ometah.cpp.diff?tr1=1.22&tr2=1.23&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/interface/ometah.hpp.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
Patches:
Index: ometah/interface/itsArgument.cpp
diff -u ometah/interface/itsArgument.cpp:1.4
ometah/interface/itsArgument.cpp:1.5
--- ometah/interface/itsArgument.cpp:1.4 Thu Jun 2 10:59:30 2005
+++ ometah/interface/itsArgument.cpp Thu Jun 2 12:42:47 2005
@@ -1,5 +1,5 @@
/***************************************************************************
- * $Id: itsArgument.cpp,v 1.4 2005/06/02 10:59:30 nojhan Exp $
+ * $Id: itsArgument.cpp,v 1.5 2005/06/02 12:42:47 jpa Exp $
* Copyright : Université Paris 12 Val-de-Marne
* Author : Johann Dréo <address@hidden>
* Author : Jean-Philippe Aumasson <address@hidden>
@@ -38,8 +38,8 @@
}
// constructor...
-itsArgument::itsArgument(string flaShort, string flagLong, string usage,
- bool hasValue, string type, string valueDefault)
+itsArgument::itsArgument(string flagShort, string flagLong, string usage,
+ bool hasValue, string type, string value)
{
this->flagShort = flagShort;
@@ -47,7 +47,7 @@
this->usage = usage;
this->hasValue = hasValue;
this->type = type;
- this->value = valueDefault;
+ this->value = value;
}
// return default key (ie -v )
@@ -79,9 +79,10 @@
}
// constructor, with argv as the command line values
-itsParser::itsParser(vector<string> argv)
+itsParser::itsParser(int argc, vector<string> argv)
{
this->argv = argv;
+ this->argc = argc;
}
// parse argv searching the given flag, then update the vector with a new
argument
@@ -89,22 +90,43 @@
bool hasValue, string type, string valueDefault)
{
- int i =1;
+
+#ifdef DEBUG
+ cout << "Enter defArg: ";
+ cout << "\n flagshort: " << flagShort << "\n flagLong: " << flagLong
+ << "\n usage : " << usage << "\n hasValue: " << hasValue
+ << "\n type: " << type << "\n valueDef: " << valueDefault << "\n";
+#endif
+
+ unsigned i = 1;
bool found = false;
- string value = "";
+ string value = valueDefault;
- while ((i < this->argc) && (!found)) {
-
- if ( (flagShort == this->argv[i]) || (flagLong == this->argv[i]) ){
-
- i = this->argc;
- if (hasValue) {
- value = argv[i+1];
+ while ( (i < this->argv.size()) && (!found)) {
+
+ if ( (flagShort == this->argv.at(i)) || (flagLong == this->argv.at(i))){
+
+ if (hasValue){
+
+ if ((++i) < this->argv.size())
+ value = this->argv.at(i);
+ else; // EXCEPTION !
+ }
+ else { // no value associated => arg has boolean value
+ value = "true";
}
found = true;
}
+ i++;
}
+
+#ifdef DEBUG
+ cout << "Argument final:";
+ cout << "\n flagshort: " << flagShort << "\n flagLong: " << flagLong
+ << "\n usage : " << usage << "\n hasValue: " << hasValue
+ << "\n type: " << type << "\n value: " << value;
+#endif
itsArgument newArgument(flagShort, flagLong, usage, hasValue, type, value);
arguments.push_back(newArgument);
@@ -113,7 +135,6 @@
}
-
string itsParser::getStringValue(string key){
vector<itsArgument>::iterator iter;
@@ -121,6 +142,7 @@
while (iter != arguments.end()){
if (iter->getKey() == key)
return iter->getValue();
+ iter++;
}
return "";
}
@@ -133,6 +155,7 @@
if (iter->getKey() == key){
return atof((iter->getValue()).c_str());
}
+ iter++;
}
return -1.;
}
@@ -148,6 +171,7 @@
istr >> i;
return i;
}
+ iter++;
}
return i;
}
@@ -159,6 +183,7 @@
while (iter != arguments.end()){
if (iter->getKey() == key)
return (iter->getValue() != "");
+ iter++;
}
return false;
}
Index: ometah/interface/itsArgument.hpp
diff -u ometah/interface/itsArgument.hpp:1.4
ometah/interface/itsArgument.hpp:1.5
--- ometah/interface/itsArgument.hpp:1.4 Thu Jun 2 10:59:30 2005
+++ ometah/interface/itsArgument.hpp Thu Jun 2 12:42:47 2005
@@ -1,5 +1,5 @@
/***************************************************************************
- * $Id: itsArgument.hpp,v 1.4 2005/06/02 10:59:30 nojhan Exp $
+ * $Id: itsArgument.hpp,v 1.5 2005/06/02 12:42:47 jpa Exp $
* Copyright : Université Paris 12 Val-de-Marne
* Author : Johann Dréo <address@hidden>
* Author : Jean-Philippe Aumasson <address@hidden>
@@ -30,6 +30,8 @@
#include "../common/logic.hpp"
+// #define DEBUG 1
+
using namespace std;
class itsArgument
@@ -89,7 +91,7 @@
~itsParser();
// constructor
- itsParser(vector<string>);
+ itsParser(int, vector<string>);
bool defArg(string flagShort, string flagLong, string usage,
bool hasValue=false, string type="", string valueDefault="");
Index: ometah/interface/ometah.cpp
diff -u ometah/interface/ometah.cpp:1.22 ometah/interface/ometah.cpp:1.23
--- ometah/interface/ometah.cpp:1.22 Thu Jun 2 10:59:30 2005
+++ ometah/interface/ometah.cpp Thu Jun 2 12:42:47 2005
@@ -1,5 +1,5 @@
/***************************************************************************
- * $Id: ometah.cpp,v 1.22 2005/06/02 10:59:30 nojhan Exp $
+ * $Id: ometah.cpp,v 1.23 2005/06/02 12:42:47 jpa Exp $
* Copyright : Université Paris 12 Val-de-Marne
* Author : Johann Dréo <address@hidden>
* Author : Jean-Philippe Aumasson <address@hidden>
@@ -33,11 +33,15 @@
{
vector<string> argumentsVector;
-
for(int i=0; i<argc; i++){
argumentsVector.push_back(argv[i]);
}
+ itsParser theParser(argc, argumentsVector);
+
+ theParser.defArg("-p","--problem","problem name", true, "string",
"Rosenbrock");
+
+ cout << "\ngetValue : " << theParser.getStringValue("-p") << endl;
// differents sets of objects
itsSet<itsMetaheuristic*> setMetaheuristic;
@@ -57,6 +61,7 @@
factoryMetaheuristics = new itsEstimationOfDistributionFactory;
setMetaheuristic.add( factoryMetaheuristics->create() );
+
/*
* Problems part
@@ -85,13 +90,14 @@
factoryServer = new itsCommunicationServerFactory_embedded;
setCommunicationServer.add( factoryServer->create() );
-
- itsParser argumentsParser(argumentsVector);
+ /*
+ itsParser argumentsParser(argumentsVector);
- argumentsParser.defArg("i","iterations","Maximum number of
iterations",true,"int","2");
+ argumentsParser.defArg("i","iterations","Maximum number of
iterations",true,"int","2");
- int i = argumentsParser.getIntValue("i");
- cout << "test i :" << i << endl;
+ int i = argumentsParser.getIntValue("i");
+ cout << "test i :" << i << endl;
+ */
/*
* Choose the items
@@ -159,7 +165,7 @@
//clog << setProblem.item()->getName() << " description:" << endl;
//clog << setProblem.item()->getInformations() << endl;
-
+ /*
try {
setMetaheuristic.item()->start();
}
@@ -172,7 +178,7 @@
catch (...) {
cerr << "Unknown error" << endl;
}
-
+ */
}
Index: ometah/interface/ometah.hpp
diff -u ometah/interface/ometah.hpp:1.3 ometah/interface/ometah.hpp:1.4
--- ometah/interface/ometah.hpp:1.3 Thu Jun 2 10:59:30 2005
+++ ometah/interface/ometah.hpp Thu Jun 2 12:42:47 2005
@@ -1,5 +1,5 @@
/***************************************************************************
- * $Id: ometah.hpp,v 1.3 2005/06/02 10:59:30 nojhan Exp $
+ * $Id: ometah.hpp,v 1.4 2005/06/02 12:42:47 jpa Exp $
* Copyright : Université Paris 12 Val-de-Marne
* Author : Johann Dréo <address@hidden>
* Author : Jean-Philippe Aumasson <address@hidden>
@@ -49,4 +49,5 @@
// interfaces
#include "itsArgument.hpp"
+
using namespace std;
- [oMetah-devel] ometah/interface itsArgument.cpp itsArgument.hp..., Jean-Philippe Aumasson, 2005/06/02
- [oMetah-devel] ometah/interface itsArgument.cpp itsArgument.hp...,
Jean-Philippe Aumasson <=
- [oMetah-devel] ometah/interface itsArgument.cpp itsArgument.hp..., Jean-Philippe Aumasson, 2005/06/02
- [oMetah-devel] ometah/interface itsArgument.cpp itsArgument.hp..., Jean-Philippe Aumasson, 2005/06/03
- [oMetah-devel] ometah/interface itsArgument.cpp itsArgument.hp..., Jean-Philippe Aumasson, 2005/06/03
- [oMetah-devel] ometah/interface itsArgument.cpp itsArgument.hp..., Jean-Philippe Aumasson, 2005/06/03
- [oMetah-devel] ometah/interface itsArgument.cpp itsArgument.hp..., Jean-Philippe Aumasson, 2005/06/03