cepgen
is hosted by
Hepforge
,
IPPP Durham
CepGen
1.2.5
Central exclusive processes event generator
Loading...
Searching...
No Matches
ArgumentsParser.h
Go to the documentation of this file.
1
/*
2
* CepGen: a central exclusive processes event generator
3
* Copyright (C) 2019-2024 Laurent Forthomme
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* any later version.
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
*/
18
19
#ifndef CepGen_Utils_ArgumentsParser_h
20
#define CepGen_Utils_ArgumentsParser_h
21
22
#include <map>
23
#include <string>
24
25
#include "
CepGen/Utils/Limits.h
"
26
27
namespace
cepgen
{
31
class
ArgumentsParser
{
32
public
:
36
ArgumentsParser
(
int
argc,
char
* argv[]);
38
template
<
typename
... Args>
39
inline
ArgumentsParser
&
addArgument
(Args&&... args) {
40
params_.emplace_back(std::forward<Args>(args)...);
41
params_.rbegin()->optional =
false
;
42
return
*
this
;
43
}
45
template
<
typename
... Args>
46
inline
ArgumentsParser
&
addOptionalArgument
(Args&&... args) {
47
params_.emplace_back(std::forward<Args>(args)...);
48
params_.rbegin()->optional =
true
;
49
return
*
this
;
50
}
51
ArgumentsParser
&
parse
();
52
std::string
operator[]
(std::string name)
const
;
53
void
dump
()
const
;
54
void
print_help
()
const
;
55
void
print_version
()
const
;
56
std::string
help_message
()
const
;
57
inline
bool
debugging
()
const
{
return
debug_req_; }
59
inline
const
std::vector<std::string>&
extra_config
()
const
{
return
extra_config_; }
60
61
private
:
63
class
Parameter {
64
public
:
66
Parameter(std::string, std::string =
""
, std::string* =
nullptr
, std::string =
""
);
68
Parameter(std::string name, std::string,
unsigned
int
* =
nullptr
,
unsigned
int
= 0);
70
Parameter(std::string, std::string,
int
* =
nullptr
,
int
= 0);
72
Parameter(std::string, std::string,
bool
* =
nullptr
,
bool
=
false
);
74
Parameter(std::string, std::string,
double
* =
nullptr
,
double
= -999.999);
76
Parameter(std::string, std::string, std::vector<std::string>* =
nullptr
, std::vector<std::string> = {});
78
Parameter(std::string, std::string, std::vector<int>* =
nullptr
, std::vector<int> = {});
80
Parameter(std::string, std::string, std::vector<double>* =
nullptr
, std::vector<double> = {});
82
Parameter(std::string, std::string, Limits* =
nullptr
, Limits = Limits{});
83
84
Parameter& parse();
85
inline
bool
boolean()
const
{
return
bool_variable_ !=
nullptr
; }
86
bool
matches(
const
std::string&)
const
;
87
88
//----- parameters attributes
89
90
std::vector<std::string> name;
91
std::string description;
92
std::string value;
93
bool
optional{
true
};
94
95
private
:
96
//----- parameters containers
97
98
std::string* str_variable_{
nullptr
};
99
double
* float_variable_{
nullptr
};
100
int
* int_variable_{
nullptr
};
101
unsigned
int
* uint_variable_{
nullptr
};
102
bool
* bool_variable_{
nullptr
};
103
Limits* lim_variable_{
nullptr
};
104
std::vector<std::string>* vec_str_variable_{
nullptr
};
105
std::vector<int>* vec_int_variable_{
nullptr
};
106
std::vector<double>* vec_float_variable_{
nullptr
};
107
};
108
typedef
std::vector<Parameter> ParametersCollection;
109
110
std::string command_name_;
111
const
ParametersCollection help_str_;
112
const
ParametersCollection version_str_;
113
const
ParametersCollection config_str_;
114
const
ParametersCollection debug_str_;
115
bool
help_req_{
false
}, version_req_{
false
}, debug_req_{
false
};
116
ParametersCollection params_;
117
std::vector<std::pair<std::string, std::string> > args_;
118
std::vector<std::string> extra_config_;
119
};
120
}
// namespace cepgen
121
122
#endif
Limits.h
cepgen::ArgumentsParser
A generic command line arguments parser.
Definition
ArgumentsParser.h:31
cepgen::ArgumentsParser::print_version
void print_version() const
Show version.
Definition
ArgumentsParser.cpp:95
cepgen::ArgumentsParser::extra_config
const std::vector< std::string > & extra_config() const
Definition
ArgumentsParser.h:59
cepgen::ArgumentsParser::debugging
bool debugging() const
Is the debugging flag set? Extra configuration flags in arguments?
Definition
ArgumentsParser.h:57
cepgen::ArgumentsParser::addArgument
ArgumentsParser & addArgument(Args &&... args)
Add a parameter required for the parser.
Definition
ArgumentsParser.h:39
cepgen::ArgumentsParser::parse
ArgumentsParser & parse()
Associate command-line arguments to parameters.
Definition
ArgumentsParser.cpp:106
cepgen::ArgumentsParser::print_help
void print_help() const
Show usage.
Definition
ArgumentsParser.cpp:93
cepgen::ArgumentsParser::help_message
std::string help_message() const
Usage message.
Definition
ArgumentsParser.cpp:170
cepgen::ArgumentsParser::addOptionalArgument
ArgumentsParser & addOptionalArgument(Args &&... args)
Add a non-mandatory parameters that can be parsed.
Definition
ArgumentsParser.h:46
cepgen::ArgumentsParser::dump
void dump() const
Dump the list of arguments into the terminal.
Definition
ArgumentsParser.cpp:97
cepgen::ArgumentsParser::operator[]
std::string operator[](std::string name) const
Read required and optional parameters.
Definition
ArgumentsParser.cpp:159
cepgen
Common namespace for this Monte Carlo generator.
Definition
CommandLineHandler.cpp:36
CepGen
Utils
ArgumentsParser.h
Generated on Mon Jul 29 2024 for CepGen by
1.9.7