-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathapp_parser_arg.hpp
More file actions
121 lines (90 loc) · 3.11 KB
/
app_parser_arg.hpp
File metadata and controls
121 lines (90 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#pragma once
#include <std_fs>
#include <stdfwd/string_view>
#include <stdfwd/vector>
#include <memory>
#include <optional>
//------------------------------------------------------------------------------
namespace cxxopts
{
class Options;
class ParseResult;
}
//------------------------------------------------------------------------------
namespace application
{
//------------------------------------------------------------------------------
class ParserArg
{
public:
ParserArg();
~ParserArg();
using Strings = stdfwd::vector< std::string >;
using StringOpt = std::optional< std::string >;
using StringsOpt = std::optional< Strings >;
using IntOpt = std::optional< int >;
using BoolOpt = std::optional< bool >;
using Path = stdfs::path;
using PathOpt = std::optional< Path >;
using Paths = stdfwd::vector< Path >;
using PathsOpt = std::optional< Paths >;
void parse( int _argc, char * _argv[] );
void addArgument(
std::string_view _fullname,
std::string_view _description,
const std::string & _defaultValue );
void addArgument(
std::string_view _fullname,
std::string_view _description,
const Strings & _defaultValues );
void addArgument(
std::string_view _fullname,
std::string_view _description,
int _defaultValue );
void addArgument(
std::string_view _fullname,
std::string_view _description,
bool _defaultValue );
void addArgument(
std::string_view _fullname,
std::string_view _description,
const Path & _defaultValue );
void addArgument(
std::string_view _fullname,
std::string_view _description,
const Paths & _defaultValues );
void
addArgument( std::string_view _fullname, std::string_view _description );
StringOpt getArgumentStringValue( std::string_view _arg ) const;
StringsOpt getArgumentStringsValue( std::string_view _arg ) const;
IntOpt getArgumentIntValue( std::string_view _arg ) const;
BoolOpt getArgumentBoolValue( std::string_view _arg ) const;
PathOpt getArgumentPathValue( std::string_view _arg ) const;
PathsOpt getArgumentPathsValue( std::string_view _arg ) const;
bool isExistArgument( std::string_view _arg ) const;
void printHelp( std::ostream & _stream ) const;
private:
cxxopts::Options & getImpl();
const cxxopts::Options & getImpl() const;
template< class _TypeOpt >
_TypeOpt getArgValue( std::string_view _arg ) const;
template< class _DefaultValue >
void addArg(
std::string_view _fullname,
std::string_view _description,
const _DefaultValue & _defaultValues );
static const std::string & toString( const std::string & _str );
static std::string toString( const Strings & _stringArray );
static std::string toString( int _number );
static std::string toString( bool _bool );
static std::string toString( const Path & _path );
static std::string removeQuotes( std::string_view _str );
static Strings removeQuotes( const Strings & _values );
static Strings toStrings( const Paths & _paths );
static Paths toPaths( const Strings & _strings );
private:
std::unique_ptr< cxxopts::Options > m_impl;
std::unique_ptr< cxxopts::ParseResult > m_resultOpt;
};
//------------------------------------------------------------------------------
}