Skip to content

Commit c3cb7cf

Browse files
committed
Merge from trunk
[SVN r54884]
1 parent bdbd3df commit c3cb7cf

File tree

8 files changed

+49
-27
lines changed

8 files changed

+49
-27
lines changed

example/options_description.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ int main(int ac, char* av[])
7777

7878
cout << "Listen port is " << portnum << "\n";
7979
}
80-
catch(exception& e)
80+
catch(std::exception& e)
8181
{
8282
cout << e.what() << "\n";
8383
return 1;

example/regex.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ int main(int ac, char* av[])
9494
<< vm["magic"].as<magic_number>().n << "\"\n";
9595
}
9696
}
97-
catch(exception& e)
97+
catch(std::exception& e)
9898
{
9999
cout << e.what() << "\n";
100100
}

include/boost/program_options/detail/parsers.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include <boost/program_options/detail/convert.hpp>
1010

11+
#include <iterator>
12+
1113
namespace boost { namespace program_options {
1214

1315
namespace detail {

include/boost/program_options/detail/value_semantic.hpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,12 @@ namespace boost { namespace program_options {
5555
{
5656
static std::basic_string<charT> empty;
5757
if (v.size() > 1)
58-
throw validation_error("multiple values not allowed");
59-
if (v.size() == 1)
58+
boost::throw_exception(validation_error("multiple values not allowed"));
59+
else if (v.size() == 1)
6060
return v.front();
61-
else if (allow_empty)
62-
return empty;
63-
else
64-
throw validation_error("at least one value required");
61+
else if (!allow_empty)
62+
boost::throw_exception(validation_error("at least one value required"));
63+
return empty;
6564
}
6665

6766
/* Throws multiple_occurrences if 'value' is not empty. */

src/cmdline.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ namespace boost { namespace program_options { namespace detail {
152152
error = "style disallows all characters for short options";
153153

154154
if (error)
155-
throw invalid_command_line_style(error);
155+
boost::throw_exception(invalid_command_line_style(error));
156156

157157
// Need to check that if guessing and long disguise are enabled
158158
// -f will mean the same as -foo
@@ -196,24 +196,24 @@ namespace boost { namespace program_options { namespace detail {
196196

197197
if (m_additional_parser)
198198
style_parsers.push_back(
199-
bind(&cmdline::handle_additional_parser, this, _1));
199+
boost::bind(&cmdline::handle_additional_parser, this, _1));
200200

201201
if (m_style & allow_long)
202202
style_parsers.push_back(
203-
bind(&cmdline::parse_long_option, this, _1));
203+
boost::bind(&cmdline::parse_long_option, this, _1));
204204

205205
if ((m_style & allow_long_disguise))
206206
style_parsers.push_back(
207-
bind(&cmdline::parse_disguised_long_option, this, _1));
207+
boost::bind(&cmdline::parse_disguised_long_option, this, _1));
208208

209209
if ((m_style & allow_short) && (m_style & allow_dash_for_short))
210210
style_parsers.push_back(
211-
bind(&cmdline::parse_short_option, this, _1));
211+
boost::bind(&cmdline::parse_short_option, this, _1));
212212

213213
if ((m_style & allow_short) && (m_style & allow_slash_for_short))
214-
style_parsers.push_back(bind(&cmdline::parse_dos_option, this, _1));
214+
style_parsers.push_back(boost::bind(&cmdline::parse_dos_option, this, _1));
215215

216-
style_parsers.push_back(bind(&cmdline::parse_terminator, this, _1));
216+
style_parsers.push_back(boost::bind(&cmdline::parse_terminator, this, _1));
217217

218218
vector<option> result;
219219
while(!args.empty())
@@ -326,8 +326,8 @@ namespace boost { namespace program_options { namespace detail {
326326
if (opt.position_key != -1) {
327327
if (position >= m_positional->max_total_count())
328328
{
329-
throw too_many_positional_options_error(
330-
"too many positional options");
329+
boost::throw_exception(too_many_positional_options_error(
330+
"too many positional options"));
331331
}
332332
opt.string_key = m_positional->name_for_position(position);
333333
++position;
@@ -380,8 +380,8 @@ namespace boost { namespace program_options { namespace detail {
380380
if (present_tokens >= min_tokens)
381381
{
382382
if (!opt.value.empty() && max_tokens == 0) {
383-
throw invalid_command_line_syntax(opt.string_key,
384-
invalid_command_line_syntax::extra_parameter);
383+
boost::throw_exception(invalid_command_line_syntax(opt.string_key,
384+
invalid_command_line_syntax::extra_parameter));
385385
}
386386

387387
// If an option wants, at minimum, N tokens, we grab them
@@ -406,8 +406,8 @@ namespace boost { namespace program_options { namespace detail {
406406
}
407407
else
408408
{
409-
throw invalid_command_line_syntax(opt.string_key,
410-
invalid_command_line_syntax::missing_parameter);
409+
boost::throw_exception(invalid_command_line_syntax(opt.string_key,
410+
invalid_command_line_syntax::missing_parameter));
411411

412412
}
413413
}
@@ -427,8 +427,8 @@ namespace boost { namespace program_options { namespace detail {
427427
name = tok.substr(2, p-2);
428428
adjacent = tok.substr(p+1);
429429
if (adjacent.empty())
430-
throw invalid_command_line_syntax(name,
431-
invalid_command_line_syntax::empty_adjacent_parameter);
430+
boost::throw_exception( invalid_command_line_syntax(name,
431+
invalid_command_line_syntax::empty_adjacent_parameter));
432432
}
433433
else
434434
{

src/parsers.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,16 @@ namespace boost { namespace program_options {
6767
woption result;
6868
result.string_key = opt.string_key;
6969
result.position_key = opt.position_key;
70+
result.unregistered = opt.unregistered;
7071

7172
std::transform(opt.value.begin(), opt.value.end(),
7273
back_inserter(result.value),
73-
bind(from_utf8, _1));
74+
boost::bind(from_utf8, _1));
75+
76+
std::transform(opt.original_tokens.begin(),
77+
opt.original_tokens.end(),
78+
back_inserter(result.original_tokens),
79+
boost::bind(from_utf8, _1));
7480
return result;
7581
}
7682
}

src/variables_map.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,13 @@ namespace boost { namespace program_options {
7474
try {
7575
d.semantic()->parse(v.value(), options.options[i].value, utf8);
7676
}
77+
#ifndef BOOST_NO_EXCEPTIONS
7778
catch(validation_error& e)
7879
{
7980
e.set_option_name(name);
8081
throw;
8182
}
83+
#endif
8284
v.m_value_semantic = d.semantic();
8385

8486
// The option is not composing, and the value is explicitly
@@ -133,7 +135,16 @@ namespace boost { namespace program_options {
133135
k != vm.end();
134136
++k)
135137
{
136-
k->second.m_value_semantic->notify(k->second.value());
138+
/* Users might wish to use variables_map to store their own values
139+
that are not parsed, and therefore will not have value_semantics
140+
defined. Do no crash on such values. In multi-module programs,
141+
one module might add custom values, and the 'notify' function
142+
will be called after that, so we check that value_sematics is
143+
not NULL. See:
144+
https://svn.boost.org/trac/boost/ticket/2782
145+
*/
146+
if (k->second.m_value_semantic)
147+
k->second.m_value_semantic->notify(k->second.value());
137148
}
138149
}
139150

test/unicode_test.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,13 @@ void test_unicode_to_unicode()
3434
args.push_back(L"--foo=\x044F");
3535

3636
variables_map vm;
37-
store(wcommand_line_parser(args).options(desc).run(), vm);
37+
basic_parsed_options<wchar_t> parsed =
38+
wcommand_line_parser(args).options(desc).run();
39+
store(parsed, vm);
3840

39-
BOOST_CHECK(vm["foo"].as<wstring>() == L"\x044F");
41+
BOOST_CHECK(vm["foo"].as<wstring>() == L"\x044F");
42+
BOOST_CHECK(parsed.options[0].original_tokens.size() == 1);
43+
BOOST_CHECK(parsed.options[0].original_tokens[0] == L"--foo=\x044F");
4044
}
4145

4246
// Test that unicode input is property converted into

0 commit comments

Comments
 (0)