ATLAS Offline Software
Loading...
Searching...
No Matches
CommandLine.h
Go to the documentation of this file.
1//$Id
2/*
3A 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, 2024, 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
40namespace 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 const 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 const std::string& CommandLine::GetProgramName() const
105 {
106 return mstrProgramName;
107 }
108
109} //ns pool
110#endif
111
112
void ParseSettings(const std::string &strInput)
virtual void CheckOptions(const char *opts[])
CommandLine(const CommandLine &)
bool IsParamName(const std::string &strValue) const
Definition CommandLine.h:85
void DumpDiagnostics() const
CommandLine(int argc, char *argv[], const std::string &strFileName)
const std::string & GetProgramName() const
void ParseCommandLine(int argc, char *argv[])
ARGMAPTYPE mArgMap
Definition CommandLine.h:70
virtual std::string Usage()
void TranslateQuotes(std::istringstream &ist, std::string &strWord)
std::string LoadSettingsFile(const std::string &strFileName)
std::string mstrProgramName
Definition CommandLine.h:71
CommandLine(const std::string &strFileName)
Command line arguments may also be supplied exclusively from a file.
CommandLine & operator=(const CommandLine &)
std::string GetByName(const std::string &strArgName) const
std::map< std::string, std::string > ARGMAPTYPE
Definition CommandLine.h:45
virtual ~CommandLine()
CommandLine(int argc, char *argv[])
int Count() const
Definition CommandLine.h:80
bool Exists(const std::string &strArgName) const
Definition CommandLine.h:99
std::string GetParamName(const std::string &strWord) const
Definition CommandLine.h:90
pool namespace
Definition libname.h:15