IODA Bundle
CommandLineParser.h
Go to the documentation of this file.
1
/*
2
* (C) Copyright 1996-2012 ECMWF.
3
*
4
* This software is licensed under the terms of the Apache Licence Version 2.0
5
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6
* In applying this licence, ECMWF does not waive the privileges and immunities
7
* granted to it by virtue of its status as an intergovernmental organisation nor
8
* does it submit to any jurisdiction.
9
*/
10
11
/// \file CommandLineParser.h
12
///
13
/// @author Piotr Kuchta, ECMWF, July 2009
14
15
#ifndef CommandLineParser_H
16
#define CommandLineParser_H
17
18
#include <map>
19
#include <set>
20
#include <string>
21
#include <vector>
22
23
24
namespace
odc
{
25
namespace
tool {
26
27
class
CommandLineParser
{
28
public
:
29
30
CommandLineParser
(
int
argc
,
char
**
argv
);
31
32
CommandLineParser
(
const
CommandLineParser
&);
33
CommandLineParser
&
operator=
(
const
CommandLineParser
&);
34
35
virtual
~CommandLineParser
();
36
37
void
registerOptionWithArgument
(
const
std::string&);
38
39
/// @return command line parameters (without the options starting with '-')
40
const
std::vector<std::string>
parameters
();
41
std::string
parameters
(
size_t
i
) {
return
parameters
()[
i
]; }
42
43
/// @return true if argumentless option is set
44
bool
optionIsSet
(
const
std::string&);
45
46
/// @return value of the command line option passed to the tool converted
47
/// to given type, or value of the second parameter if option not
48
/// present on command line.
49
template
<
typename
T> T
optionArgument
(
const
std::string&, T defaultValue);
50
51
int
argc
();
52
std::string
argv
(
int
i
);
53
char
**
argv
() {
return
argv_
; }
54
55
private
:
56
57
void
parseCommandLine
();
58
59
60
bool
commandLineParsed_
;
61
int
argc_
;
62
char
**
argv_
;
63
64
std::set<std::string>
registeredOptionsWithArguments_
;
65
66
std::map<std::string, std::string>
optionsWithArguments_
;
67
std::set<std::string>
optionsNoArguments_
;
68
std::vector<std::string>
parameters_
;
69
70
void
print
(std::ostream& s)
const
;
71
friend
std::ostream&
operator<<
(std::ostream& s,
const
CommandLineParser
& o) { o.
print
(s);
return
s; }
72
};
73
74
}
// namespace tool
75
}
// namespace odc
76
77
#endif
78
odc::tool::CommandLineParser
Definition:
CommandLineParser.h:27
odc::tool::CommandLineParser::operator<<
friend std::ostream & operator<<(std::ostream &s, const CommandLineParser &o)
Definition:
CommandLineParser.h:71
odc::tool::CommandLineParser::~CommandLineParser
virtual ~CommandLineParser()
Definition:
CommandLineParser.cc:22
odc::tool::CommandLineParser::commandLineParsed_
bool commandLineParsed_
Definition:
CommandLineParser.h:60
odc::tool::CommandLineParser::operator=
CommandLineParser & operator=(const CommandLineParser &)
Definition:
CommandLineParser.cc:47
odc::tool::CommandLineParser::argv
char ** argv()
Definition:
CommandLineParser.h:53
odc::tool::CommandLineParser::parseCommandLine
void parseCommandLine()
Definition:
CommandLineParser.cc:111
odc::tool::CommandLineParser::parameters_
std::vector< std::string > parameters_
Definition:
CommandLineParser.h:68
odc::tool::CommandLineParser::CommandLineParser
CommandLineParser(int argc, char **argv)
Definition:
CommandLineParser.cc:24
odc::tool::CommandLineParser::optionIsSet
bool optionIsSet(const std::string &)
Definition:
CommandLineParser.cc:88
odc::tool::CommandLineParser::argc
int argc()
Definition:
CommandLineParser.cc:64
odc::tool::CommandLineParser::optionArgument
T optionArgument(const std::string &, T defaultValue)
Definition:
CommandLineParser.cc:99
odc::tool::CommandLineParser::parameters
std::string parameters(size_t i)
Definition:
CommandLineParser.h:41
odc::tool::CommandLineParser::argv_
char ** argv_
Definition:
CommandLineParser.h:62
odc::tool::CommandLineParser::registerOptionWithArgument
void registerOptionWithArgument(const std::string &)
Definition:
CommandLineParser.cc:77
odc::tool::CommandLineParser::print
void print(std::ostream &s) const
Definition:
CommandLineParser.cc:139
odc::tool::CommandLineParser::optionsNoArguments_
std::set< std::string > optionsNoArguments_
Definition:
CommandLineParser.h:67
odc::tool::CommandLineParser::optionsWithArguments_
std::map< std::string, std::string > optionsWithArguments_
Definition:
CommandLineParser.h:66
odc::tool::CommandLineParser::registeredOptionsWithArguments_
std::set< std::string > registeredOptionsWithArguments_
Definition:
CommandLineParser.h:64
odc::tool::CommandLineParser::parameters
const std::vector< std::string > parameters()
Definition:
CommandLineParser.cc:82
odc::tool::CommandLineParser::argc_
int argc_
Definition:
CommandLineParser.h:61
odc
Definition:
ColumnInfo.h:23
proc_gsi_ncdiag.i
i
Definition:
proc_gsi_ncdiag.py:155
odc
src
odc
CommandLineParser.h
Generated on Fri Aug 20 2021 11:49:02 for IODA Bundle by
1.9.1