/data3/calcul/jacquem/working_dir/Micromegas/micromegasFrameWork/src/tools/Arguments.cpp

Go to the documentation of this file.
00001 #include "Arguments.hh"
00002 #include <iostream>
00003 
00004 
00005 
00006 using namespace std;
00007 
00008 
00009 //---------------------------- Constructor -----------------------//
00010 Arguments::Arguments(int argc, char** argv, string _usage)
00011 {
00012 
00013   this->pUsage = _usage;
00014   unsigned int nbArgs = 1;
00015   for (int index = 0 ; index < argc ; index++ )
00016   {
00017     if ( index == 0 && argc >= 1) { command = argv[index]; } 
00018     else 
00019     {
00020       if ( argv[index][0] == '-'  && argc >= index+2)
00021       {
00022         string optionKey = argv[index];
00023         stringKeyMap.insert(make_pair(optionKey,argv[++index]));
00024       }
00025       else 
00026       {
00027         orderKeyMap.insert(make_pair(nbArgs++,argv[index]));
00028       }
00029     }
00030   }
00031 }
00032 
00033 //---------------------------- Destructor -----------------------//
00034 Arguments::~Arguments()
00035 {
00036 }
00037 
00038 //---------------------------- getOption(string) -----------------------//
00039 
00040 string Arguments::getOption(const string key) const
00041 {
00042   map<const string, string>::const_iterator it = stringKeyMap.find(key);
00043   if ( it !=  stringKeyMap.end() ) { return it->second; } 
00044   return string("");
00045 } 
00046 
00047 //---------------------------- getArg(unsigned int) -----------------------//
00048 string Arguments::getArgument(const unsigned int key) const
00049 {
00050 
00051   map<const unsigned int, string>::const_iterator it = orderKeyMap.find(key);
00052   if ( it !=  orderKeyMap.end() )  { return orderKeyMap.find(key)->second; }
00053   return string("");
00054 }
00055 
00056 //---------------------------- usage(void) -----------------------//
00057 void Arguments::usage(void)
00058 {
00059   cout << "usage: " << pUsage << endl;
00060 }
00061 

Generated on Mon Jan 7 13:15:22 2013 for MicromegasFramework by  doxygen 1.4.7