[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 05:41:57 -0400 |
CVSROOT: /cvsroot/ometah
Module name: ometah
Branch:
Changes by: Jean-Philippe Aumasson <address@hidden> 05/06/02 09:41:57
Modified files:
interface : itsArgument.cpp itsArgument.hpp ometah.cpp
Log message:
* turned hash_map to vector, done get*Values methods, and defArgs..
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/interface/itsArgument.cpp.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/interface/itsArgument.hpp.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/interface/ometah.cpp.diff?tr1=1.20&tr2=1.21&r1=text&r2=text
Patches:
Index: ometah/interface/itsArgument.cpp
diff -u ometah/interface/itsArgument.cpp:1.2
ometah/interface/itsArgument.cpp:1.3
--- ometah/interface/itsArgument.cpp:1.2 Wed Jun 1 20:40:48 2005
+++ ometah/interface/itsArgument.cpp Thu Jun 2 09:41:56 2005
@@ -1,5 +1,5 @@
/***************************************************************************
- * $Id: itsArgument.cpp,v 1.2 2005/06/01 20:40:48 jpa Exp $
+ * $Id: itsArgument.cpp,v 1.3 2005/06/02 09:41:56 jpa Exp $
* Copyright : Université Paris 12 Val-de-Marne
* Author : Johann Dréo <address@hidden>
* Author : Jean-Philippe Aumasson <address@hidden>
@@ -28,26 +28,134 @@
using namespace std;
+
+// ITS ARGUMENT
+
+
+// destructor
itsArgument::~itsArgument(){
}
-itsArgument::itsArgument(){
+// constructor...
+itsArgument::itsArgument(string flagShort, string flagLong, bool hasValue,
string usage, string type, string value){
+ this->flagShort = flagShort;
+ this->flagLong = flagLong;
+ this->hasValue = hasValue;
+ this->usage = usage;
+ this->type = type;
+ this->value = value;
}
+// return default key (ie -v )
+string itsArgument::getKey(){
+
+ return this->flagShort;
+}
+
+// return long key (ie --version)
+string itsArgument::getLongKey(){
+
+ return this->flagLong;
+}
+// return the argument as a string
+string itsArgument::getValue(){
+
+ if (this->hasValue)
+ return this->value;
+ return "";
+}
+
+// ITSPARSER
+
+// destructor
itsParser::~itsParser(){
}
-itsParser::itsParser(){
+// constructor, with argv as the command line values
+itsParser::itsParser(vector<string> argv){
+ this->argv = argv;
+
}
+// parse argv searching the given flag, then update the vector with a new
argument
int itsParser::defArg(string flagShort, string flagLong,
bool hasValue, string desc, string type){
- /* parse argv searching the given argument, and update the hash
- with a new itsArgument */
- return 1;
+
+ int i =1;
+ int found = 0;
+ string value = "";
+
+
+ while ((i < this->argc) && (!found)){
+
+ if ( (flagShort == this->argv[i]) || (flagLong == this->argv[i]) ){
+
+ i = this->argc;
+ if (hasValue){
+ value = argv[i+1];
+ }
+ found = 1;
+ }
+ }
+
+ itsArgument newArgument(flagShort, flagLong, hasValue, desc, type, value);
+ arguments.push_back(newArgument);
+
+ return found;
+}
+
+
+
+string itsParser::getStringValue(string key){
+
+ vector<itsArgument>::iterator iter;
+ iter = arguments.begin();
+ while (iter != arguments.end()){
+ if (iter->getKey() == key)
+ return iter->getValue();
+ }
+ return "";
+}
+
+double itsParser::getDoubleValue(string key){
+
+ vector<itsArgument>::iterator iter;
+ iter = arguments.begin();
+ while (iter != arguments.end()){
+ if (iter->getKey() == key){
+ return atof((iter->getValue()).c_str());
+ }
+ }
+ return -1.;
+}
+
+int itsParser::getIntValue(string key){
+
+ int i = -1;
+ vector<itsArgument>::iterator iter;
+ iter = arguments.begin();
+ while (iter != arguments.end()){
+ if (iter->getKey() == key){
+ istringstream istr(iter->getValue() );
+ istr >> i;
+ return i;
+ }
+ }
+ return i;
+}
+
+bool itsParser::getBoolValue(string key){
+
+ vector<itsArgument>::iterator iter;
+ iter = arguments.begin();
+ while (iter != arguments.end()){
+ if (iter->getKey() == key)
+ return (iter->getValue() != "");
+ }
+ return false;
}
Index: ometah/interface/itsArgument.hpp
diff -u ometah/interface/itsArgument.hpp:1.2
ometah/interface/itsArgument.hpp:1.3
--- ometah/interface/itsArgument.hpp:1.2 Wed Jun 1 20:40:48 2005
+++ ometah/interface/itsArgument.hpp Thu Jun 2 09:41:57 2005
@@ -1,5 +1,5 @@
/***************************************************************************
- * $Id: itsArgument.hpp,v 1.2 2005/06/01 20:40:48 jpa Exp $
+ * $Id: itsArgument.hpp,v 1.3 2005/06/02 09:41:57 jpa Exp $
* Copyright : Université Paris 12 Val-de-Marne
* Author : Johann Dréo <address@hidden>
* Author : Jean-Philippe Aumasson <address@hidden>
@@ -25,6 +25,10 @@
#include <hash_map.h>
#include <string>
+#include <sstream>
+#include <stdlib.h>
+
+#include "../common/logic.hpp"
using namespace std;
@@ -46,13 +50,24 @@
// type of the associated value, if there
string type;
+
+
+
public:
- // desctructor
+
+string value;
+
+ // destructor
~itsArgument();
// constructor
- itsArgument();
+ itsArgument(string, string, bool, string, string, string);
+
+ string getKey();
+ string getLongKey();
+
+ string getValue();
};
@@ -62,7 +77,11 @@
protected:
int argc;
- string * argv;
+
+ vector<string> argv;
+
+ // flag (short or long) -> associated argument
+ vector<itsArgument> arguments;
public:
@@ -70,11 +89,16 @@
~itsParser();
// constructor
- itsParser();
+ itsParser(vector<string>);
int defArg(string, string, bool, string, string);
- // flag (short or long) -> associated argument
- // hash_map<string, itsArgument, eqstr> flag2arg;
+ string getStringValue(string);
+
+ double getDoubleValue(string);
+
+ int getIntValue(string);
+
+ bool getBoolValue(string);
};
Index: ometah/interface/ometah.cpp
diff -u ometah/interface/ometah.cpp:1.20 ometah/interface/ometah.cpp:1.21
--- ometah/interface/ometah.cpp:1.20 Wed Jun 1 15:50:57 2005
+++ ometah/interface/ometah.cpp Thu Jun 2 09:41:57 2005
@@ -1,5 +1,5 @@
/***************************************************************************
- * $Id: ometah.cpp,v 1.20 2005/06/01 15:50:57 jpa Exp $
+ * $Id: ometah.cpp,v 1.21 2005/06/02 09:41:57 jpa Exp $
* Copyright : Université Paris 12 Val-de-Marne
* Author : Johann Dréo <address@hidden>
* Author : Jean-Philippe Aumasson <address@hidden>
@@ -91,12 +91,17 @@
int main(int argc, char ** argv)
{
+ vector<string> v;
- cmdargs_t cmd;
-
- // check cmd line correctness and alter cmd_args
- if (!get_args(argc, argv, &cmd))
- usage(argv[0]);
+ for(int i=0; i<argc; i++){
+ v.push_back(argv[i]);
+ }
+
+ cmdargs_t cmd;
+
+ // check cmd line correctness and alter cmd_args
+ if (!get_args(argc, argv, &cmd))
+ usage(argv[0]);
// differents sets of objects
- [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/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