ATLAS Offline Software
CmdLineArgs.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef UTILITIES_COLLECTION_CMDLINEARGS
6 #define UTILITIES_COLLECTION_CMDLINEARGS
7 
8 #include <string>
9 #include <vector>
10 #include <algorithm>
11 
12 namespace pool
13 {
14 
16  {
17  public:
18 
20  CmdLineArgs( int argc, const char* argv[] );
21 
23  bool hasQual( const std::string arg ) const;
24 
26  std::string getArg( const std::string arg );
27 
29  std::string getArg( std::vector<std::string>::const_iterator itr );
30 
32  std::vector<std::string>::const_iterator getPos() const;
33 
34  private:
35 
36  std::vector<std::string> argvVector;
37  std::vector<std::string>::const_iterator vecItr;
38  };
39 
40 
41  inline CmdLineArgs::CmdLineArgs( int argc, const char* argv[] )
42  : argvVector(argc)
43  {
44  for( int i=0; i < argc; ++i )
45  argvVector[i].assign( argv[i] );
46  vecItr = argvVector.begin();
47  }
48 
49 
50  inline bool CmdLineArgs::hasQual( const std::string arg ) const
51  {
52  return ( std::find( argvVector.begin(), argvVector.end(), arg ) !=
53  argvVector.end() );
54  }
55 
56 
57  inline std::string CmdLineArgs::getArg( const std::string arg )
58  {
59  std::vector<std::string>::const_iterator itr
60  = std::find( argvVector.begin(), argvVector.end(), arg );
61  return ( getArg( itr ) );
62  }
63 
64 
65  inline std::string CmdLineArgs::getArg(
66  std::vector<std::string>::const_iterator itr )
67  {
68  vecItr = itr;
69  if ( vecItr != argvVector.end() )
70  {
71  vecItr++;
72  if ( vecItr != argvVector.end() )
73  {
74  return *vecItr;
75  }
76  else
77  {
78  return ("");
79  }
80  }
81  else
82  {
83  return ("");
84  }
85  }
86 
87 
88  inline std::vector<std::string>::const_iterator CmdLineArgs::getPos() const
89  {
90  return vecItr;
91  }
92 
93 } // end pool namespace
94 
95 #endif // UTILITIES_COLLECTION_CMDLINEARGS
96 
pool::CmdLineArgs::getArg
std::string getArg(const std::string arg)
Get argument from command line using qualifier.
Definition: CmdLineArgs.h:57
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
pool
pool namespace
Definition: libname.h:15
pool::CmdLineArgs::getPos
std::vector< std::string >::const_iterator getPos() const
Get position on command line.
Definition: CmdLineArgs.h:88
pool::CmdLineArgs
Definition: CmdLineArgs.h:16
LArCellConditions.argv
argv
Definition: LArCellConditions.py:112
pool::CmdLineArgs::argvVector
std::vector< std::string > argvVector
Definition: CmdLineArgs.h:36
lumiFormat.i
int i
Definition: lumiFormat.py:92
pool::CmdLineArgs::CmdLineArgs
CmdLineArgs(int argc, const char *argv[])
Constructor.
Definition: CmdLineArgs.h:41
pool::CmdLineArgs::hasQual
bool hasQual(const std::string arg) const
Check if argument is in command line.
Definition: CmdLineArgs.h:50
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:20
create_dcsc_inputs_sqlite.arg
list arg
Definition: create_dcsc_inputs_sqlite.py:48
pool::CmdLineArgs::vecItr
std::vector< std::string >::const_iterator vecItr
Definition: CmdLineArgs.h:37