FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
rstudio/src/cpp/core/include/core/ProgramOptions.hpp at main · ssh352/rstudio · GitHub
ssh352
/
rstudio
Public
forked from
rstudio/rstudio
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
rstudio
/
src
/
cpp
/
core
/
include
/
core
/
ProgramOptions.hpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
169 lines (142 loc) · 5.16 KB
Breadcrumbs
rstudio
/
src
/
cpp
/
core
/
include
/
core
/
ProgramOptions.hpp
Copy path
File metadata and controls
169 lines (142 loc) · 5.16 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
* ProgramOptions.hpp
*
* Copyright (C) 2022 by Posit Software, PBC
*
* Unless you have received this program directly from Posit Software pursuant
* to the terms of a commercial license agreement with Posit Software, then
* this program is licensed to you under the terms of version 3 of the
* GNU Affero General Public License. This program is distributed WITHOUT
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
* AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
*
*/
#
ifndef
CORE_PROGRAM_OPTIONS_HPP
#
define
CORE_PROGRAM_OPTIONS_HPP
#
include
<
set
>
#
include
<
string
>
#
include
<
vector
>
#
include
<
sstream
>
#
include
<
boost/algorithm/string.hpp
>
#
include
<
boost/utility.hpp
>
#
include
<
boost/program_options.hpp
>
#
include
<
core/ProgramStatus.hpp
>
namespace
std
{
//
needed for boost to compile std::vector<T> default value for option
template
<
typename
T>
inline
std::ostream&
operator
<<(std::ostream &os,
const
std::vector<T>& vec)
{
for
(
auto
item : vec)
{
os << item <<
"
"
;
}
return
os;
}
//
needed for boost to compile std::set<T> default value for option
template
<
typename
T>
inline
std::ostream&
operator
<<(std::ostream &os,
const
std::set<T, std::less<T>, std::allocator<T>>& set)
{
for
(
auto
item : set)
{
os << item <<
"
,
"
;
}
return
os;
}
//
needed to parse comma-separated lists from options files directly into a set
//
There must be an operator>>(std::istream&, T&) in the std namespace to compile for type T
template
<
typename
T>
inline
std::istream&
operator
>>(std::istream& is, std::set<T, std::less<T>, std::allocator<T>>& set)
{
std::string list;
is >> list;
std::vector<std::string> splitList;
boost::split
(splitList, list,
boost::is_any_of
(
"
,
"
));
for
(
const
auto
& strVal : splitList)
{
T value;
std::stringstream
stream
(strVal);
stream >> value;
if
(stream.
fail
())
{
is.
setstate
(stream.
rdstate
());
return
is;
}
set.
insert
(value);
}
return
is;
}
}
namespace
rstudio
{
namespace
core
{
class
Error
;
class
ErrorLocation
;
class
ProgramStatus
;
namespace
program_options
{
struct
OptionsDescription
{
OptionsDescription
(
const
std::string& programName,
const
std::string& defaultConfigFilePath = std::string())
: programName(programName),
defaultConfigFilePath
(defaultConfigFilePath),
commandLine(
"
command-line options
"
),
configFile(
"
config-file options
"
)
{
}
std::string programName;
std::string defaultConfigFilePath;
boost::program_options::options_description commandLine;
boost::program_options::positional_options_description positionalOptions;
boost::program_options::options_description configFile;
};
ProgramStatus
read
(
const
OptionsDescription& optionsDescription,
int
argc,
const
char
*
const
argv[],
std::vector<std::string>* pUnrecognized,
bool
* pHelp,
bool
allowUnregisteredConfigOptions =
false
,
bool
configFileHasPrecedence =
false
);
inline
ProgramStatus
read
(
const
OptionsDescription& optionsDescription,
int
argc,
const
char
*
const
argv[],
bool
* pHelp,
bool
allowUnregisteredConfigOptions =
false
,
bool
configFileHasPrecedence =
false
)
{
return
read
(optionsDescription, argc, argv,
NULL
, pHelp,
allowUnregisteredConfigOptions, configFileHasPrecedence);
}
inline
ProgramStatus
read
(
const
OptionsDescription& optionsDescription,
int
argc,
const
char
*
const
argv[],
std::vector<std::string>* pUnrecognized,
bool
allowUnregisteredConfigOptions =
false
,
bool
configFileHasPrecedence =
false
)
{
bool
help;
return
read
(optionsDescription, argc, argv, pUnrecognized, &help,
allowUnregisteredConfigOptions, configFileHasPrecedence);
}
inline
ProgramStatus
read
(
const
OptionsDescription& optionsDescription,
int
argc,
const
char
*
const
argv[],
bool
allowUnregisteredConfigOptions =
false
,
bool
configFileHasPrecedence =
false
)
{
bool
help;
return
read
(optionsDescription, argc, argv, &help,
allowUnregisteredConfigOptions, configFileHasPrecedence);
}
void
reportError
(
const
Error& error,
const
ErrorLocation& location,
bool
forceStdErr =
false
);
void
reportError
(
const
std::string& errorMessage,
const
ErrorLocation& location,
bool
forceStdErr =
false
);
void
reportWarnings
(
const
std::string& warningMessages,
const
ErrorLocation& location);
}
//
namespace program_options
}
//
namespace core
}
//
namespace rstudio
#endif
//
CORE_PROGRAM_OPTIONS_HPP
Back
|
FazBrowse Home
|
New Git URL