Skip to content

Commit ab9901f

Browse files
committed
Merge from trunk.
[SVN r58818]
1 parent 5820ee9 commit ab9901f

35 files changed

+1543
-321
lines changed

build/Jamfile.v2

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11

22
project boost/program_options
3-
:
4-
source-location ../src
3+
: source-location ../src
54
;
65

76
SOURCES =
87
cmdline config_file options_description parsers variables_map
98
value_semantic positional_options utf8_codecvt_facet
10-
convert winmain
9+
convert winmain split
1110
;
1211

1312
lib boost_program_options
13+
: $(SOURCES).cpp
14+
: <link>shared:<define>BOOST_PROGRAM_OPTIONS_DYN_LINK=1 # tell source we're building dll's
1415
:
15-
$(SOURCES).cpp
16-
:
17-
<link>shared:<define>BOOST_PROGRAM_OPTIONS_DYN_LINK=1 # tell source we're building dll's
16+
: <link>shared:<define>BOOST_PROGRAM_OPTIONS_DYN_LINK=1
1817
;
1918

20-
boost-install boost_program_options ;
19+
boost-install boost_program_options ;

example/multiple_sources.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,16 @@ int main(int ac, char* av[])
2727
{
2828
try {
2929
int opt;
30+
string config_file;
3031

3132
// Declare a group of options that will be
3233
// allowed only on command line
3334
po::options_description generic("Generic options");
3435
generic.add_options()
3536
("version,v", "print version string")
36-
("help", "produce help message")
37+
("help", "produce help message")
38+
("config,c", po::value<string>(&config_file)->default_value("multiple_sources.cfg"),
39+
"name of a file of a configuration.")
3740
;
3841

3942
// Declare a group of options that will be
@@ -71,10 +74,19 @@ int main(int ac, char* av[])
7174
po::variables_map vm;
7275
store(po::command_line_parser(ac, av).
7376
options(cmdline_options).positional(p).run(), vm);
74-
75-
ifstream ifs("multiple_sources.cfg");
76-
store(parse_config_file(ifs, config_file_options), vm);
7777
notify(vm);
78+
79+
ifstream ifs(config_file.c_str());
80+
if (!ifs)
81+
{
82+
cout << "can not open config file: " << config_file << "\n";
83+
return 0;
84+
}
85+
else
86+
{
87+
store(parse_config_file(ifs, config_file_options), vm);
88+
notify(vm);
89+
}
7890

7991
if (vm.count("help")) {
8092
cout << visible << "\n";

example/regex.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ struct magic_number {
4343
*/
4444
void validate(boost::any& v,
4545
const std::vector<std::string>& values,
46-
magic_number* target_type, int)
46+
magic_number*, int)
4747
{
4848
static regex r("\\d\\d\\d-(\\d\\d\\d)");
4949

@@ -61,7 +61,7 @@ void validate(boost::any& v,
6161
if (regex_match(s, match, r)) {
6262
v = any(magic_number(lexical_cast<int>(match[1])));
6363
} else {
64-
throw validation_error("invalid value");
64+
throw validation_error(validation_error::invalid_option_value);
6565
}
6666
}
6767

example/response_file.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ int main(int ac, char* av[])
7070
ss << ifs.rdbuf();
7171
// Split the file content
7272
char_separator<char> sep(" \n\r");
73-
tokenizer<char_separator<char> > tok(ss.str(), sep);
73+
string sstr = ss.str();
74+
tokenizer<char_separator<char> > tok(sstr, sep);
7475
vector<string> args;
7576
copy(tok.begin(), tok.end(), back_inserter(args));
7677
// Parse the file and store the options
@@ -87,7 +88,7 @@ int main(int ac, char* av[])
8788
cout << "Magic value: " << vm["magic"].as<int>() << "\n";
8889
}
8990
}
90-
catch(exception& e) {
91+
catch (std::exception& e) {
9192
cout << e.what() << "\n";
9293
}
9394
}

include/boost/program_options/cmdline.hpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace boost { namespace program_options { namespace command_line_style {
2626
enum style_t {
2727
/// Allow "--long_name" style
2828
allow_long = 1,
29-
/// Alow "-<single character" style
29+
/// Allow "-<single character" style
3030
allow_short = allow_long << 1,
3131
/// Allow "-" in short options
3232
allow_dash_for_short = allow_short << 1,
@@ -62,14 +62,19 @@ namespace boost { namespace program_options { namespace command_line_style {
6262
long option name if guessing is in effect.
6363
*/
6464
allow_guessing = allow_sticky << 1,
65-
/** Ignore the difference in case for options.
66-
@todo Should this apply to long options only?
65+
/** Ignore the difference in case for long options.
6766
*/
68-
case_insensitive = allow_guessing << 1,
67+
long_case_insensitive = allow_guessing << 1,
68+
/** Ignore the difference in case for short options.
69+
*/
70+
short_case_insensitive = long_case_insensitive << 1,
71+
/** Ignore the difference in case for all options.
72+
*/
73+
case_insensitive = (long_case_insensitive | short_case_insensitive),
6974
/** Allow long options with single option starting character,
7075
e.g <tt>-foo=10</tt>
7176
*/
72-
allow_long_disguise = case_insensitive << 1,
77+
allow_long_disguise = short_case_insensitive << 1,
7378
/** The more-or-less traditional unix style. */
7479
unix_style = (allow_short | short_allow_adjacent | short_allow_next
7580
| allow_long | long_allow_adjacent | long_allow_next

include/boost/program_options/detail/cmdline.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,15 @@ namespace boost { namespace program_options { namespace detail {
108108
void extra_style_parser(style_parser s);
109109

110110
void check_style(int style) const;
111-
111+
112+
bool is_style_active(style_t style) const;
112113

113114
void init(const std::vector<std::string>& args);
114115

115116
void
116117
finish_option(option& opt,
117-
std::vector<std::string>& other_tokens);
118+
std::vector<std::string>& other_tokens,
119+
const std::vector<style_parser>& style_parsers);
118120

119121
// Copies of input.
120122
std::vector<std::string> args;

include/boost/program_options/detail/value_semantic.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace boost { namespace program_options {
3333
void
3434
typed_value<T, charT>::notify(const boost::any& value_store) const
3535
{
36-
const T* value = boost::any_cast<const T>(&value_store);
36+
const T* value = boost::any_cast<T>(&value_store);
3737
if (m_store_to) {
3838
*m_store_to = *value;
3939
}
@@ -55,11 +55,11 @@ namespace boost { namespace program_options {
5555
{
5656
static std::basic_string<charT> empty;
5757
if (v.size() > 1)
58-
boost::throw_exception(validation_error("multiple values not allowed"));
58+
boost::throw_exception(validation_error(validation_error::multiple_values_not_allowed));
5959
else if (v.size() == 1)
6060
return v.front();
6161
else if (!allow_empty)
62-
boost::throw_exception(validation_error("at least one value required"));
62+
boost::throw_exception(validation_error(validation_error::at_least_one_value_required));
6363
return empty;
6464
}
6565

0 commit comments

Comments
 (0)