ATLAS Offline Software
CommandLine.h
Go to the documentation of this file.
1 //$Id
2 /*
3 A C++ commandline parser.
4 */
5 /* ****************************************************************************
6 *
7 * CommandLine.h
8 * Created by John F. Hubbard, on Fri Aug 11 2000, 16:04:24 PST
9 *
10 * Copyright (c) 2000, ATD Azad Technology Development Corporation
11 *
12 * The Reliable Software Outsource Resource
13 * You hire us, we do it for you, and we do it right.
14 *
15 * www.azadtech.com
16 *
17 * Permission is granted to use this code without restriction,
18 * as long as this copyright notice appears in all source files.
19 *
20 * File Contents: Interface and documentation of the CommandLine class.
21 *
22 * %version: 2.30 %
23 * %date_modified: Thu Nov 02 16:10:20 2000 %
24 * %created_by: jhubbard %
25 *
26 *************************************************************************** */
27 
28 #ifndef POOL_COMMANDLINE_H
29 #define POOL_COMMANDLINE_H
30 #ifndef POOL_STDSTRING_H
31 #include <string>
32 #define POOL_STDSTRING_H
33 #endif
34 #ifndef POOL_STDMAP_H
35 #include <map>
36 #define POOL_STDMAP_H
37 #endif
38 #include <sstream>
39 
40 namespace pool
41 {
43  {
44  public:
45  typedef std::map<std::string, std::string> ARGMAPTYPE;
46  CommandLine(int argc, char* argv[]);
47  CommandLine(int argc, char* argv[], const std::string& strFileName);
50  CommandLine(const std::string& strFileName);
51 
52  virtual ~CommandLine();
53  std::string GetByName( const std::string& strArgName ) const;
54  inline bool Exists( const std::string& strArgName ) const;
55  inline int Count() const;
56  virtual std::string Usage();
57  void DumpDiagnostics() const;
58  inline std::string GetProgramName() const;
59  virtual void CheckOptions(const char* opts[]);
60 
61  private:
62  inline bool IsParamName(const std::string& strValue) const;
63  inline std::string GetParamName(const std::string& strWord) const;
64  void ParseCommandLine(int argc, char* argv[]);
65  void ParseSettings(const std::string& strInput);
66  std::string LoadSettingsFile(const std::string& strFileName);
67  void TranslateQuotes(std::istringstream& ist, std::string& strWord);
68 
71  std::string mstrProgramName;
72 
73  // No copying or assignment is supported, at this point:
76  };
77 
78 
79  //inline functions
80  inline int CommandLine::Count() const
81  {
82  return mnParameterCount;
83  }
84 
85  inline bool CommandLine::IsParamName(const std::string& strWord) const
86  {
87  return ( (strWord.length()) > 1 && ( strWord[0] == '-' ) );
88  }
89 
90  inline std::string CommandLine::GetParamName(const std::string& strWord) const
91  {
92  if (IsParamName(strWord) )
93  {
94  return strWord.substr(1, strWord.length() - 1);
95  }
96  return strWord;
97  }
98 
99  inline bool CommandLine::Exists( const std::string& strArgName ) const
100  {
101  return( mArgMap.find(strArgName) != mArgMap.end() );
102  }
103 
104  inline std::string CommandLine::GetProgramName() const
105  {
106  return mstrProgramName;
107  }
108 
109 } //ns pool
110 #endif
111 
112 
pool::CommandLine::mnParameterCount
int mnParameterCount
Definition: CommandLine.h:69
pool::CommandLine::ARGMAPTYPE
std::map< std::string, std::string > ARGMAPTYPE
Definition: CommandLine.h:45
pool
pool namespace
Definition: libname.h:15
pool::CommandLine::DumpDiagnostics
void DumpDiagnostics() const
pool::CommandLine
Definition: CommandLine.h:43
pool::CommandLine::Count
int Count() const
Definition: CommandLine.h:80
LArCellConditions.argv
argv
Definition: LArCellConditions.py:112
pool::CommandLine::CommandLine
CommandLine(int argc, char *argv[], const std::string &strFileName)
pool::CommandLine::CommandLine
CommandLine(const CommandLine &)
pool::CommandLine::CheckOptions
virtual void CheckOptions(const char *opts[])
pool::CommandLine::GetProgramName
std::string GetProgramName() const
Definition: CommandLine.h:104
pool::CommandLine::CommandLine
CommandLine(const std::string &strFileName)
Command line arguments may also be supplied exclusively from a file.
pool::CommandLine::operator=
CommandLine & operator=(const CommandLine &)
pool::CommandLine::ParseCommandLine
void ParseCommandLine(int argc, char *argv[])
pool::CommandLine::~CommandLine
virtual ~CommandLine()
pool::CommandLine::LoadSettingsFile
std::string LoadSettingsFile(const std::string &strFileName)
pool::CommandLine::CommandLine
CommandLine(int argc, char *argv[])
pool::CommandLine::ParseSettings
void ParseSettings(const std::string &strInput)
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:20
pool::CommandLine::mstrProgramName
std::string mstrProgramName
Definition: CommandLine.h:71
pool::CommandLine::mArgMap
ARGMAPTYPE mArgMap
Definition: CommandLine.h:70
pool::CommandLine::Exists
bool Exists(const std::string &strArgName) const
Definition: CommandLine.h:99
pool::CommandLine::IsParamName
bool IsParamName(const std::string &strValue) const
Definition: CommandLine.h:85
pool::CommandLine::GetParamName
std::string GetParamName(const std::string &strWord) const
Definition: CommandLine.h:90
pool::CommandLine::Usage
virtual std::string Usage()
pool::CommandLine::TranslateQuotes
void TranslateQuotes(std::istringstream &ist, std::string &strWord)
athena.opts
opts
Definition: athena.py:86
pool::CommandLine::GetByName
std::string GetByName(const std::string &strArgName) const