mirror of
https://github.com/boostorg/program_options.git
synced 2026-01-20 16:52:14 +00:00
Compare commits
1 Commits
boost-1.41
...
boost-1.39
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4c903e8d49 |
22
CMakeLists.txt
Normal file
22
CMakeLists.txt
Normal file
@@ -0,0 +1,22 @@
|
||||
#----------------------------------------------------------------------------
|
||||
# This file was automatically generated from the original CMakeLists.txt file
|
||||
# Add a variable to hold the headers for the library
|
||||
set (lib_headers
|
||||
program_options.hpp
|
||||
program_options
|
||||
)
|
||||
|
||||
# Add a library target to the build system
|
||||
boost_library_project(
|
||||
program_options
|
||||
SRCDIRS src
|
||||
TESTDIRS test
|
||||
HEADERS ${lib_headers}
|
||||
# DOCDIRS
|
||||
DESCRIPTION "Access to configuration data given on command line, in config files and other sources."
|
||||
MODULARIZED
|
||||
AUTHORS "Vladimir Prus <ghost -at- cs.msu.su>"
|
||||
# MAINTAINERS
|
||||
)
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ int main(int ac, char* av[])
|
||||
|
||||
cout << "Listen port is " << portnum << "\n";
|
||||
}
|
||||
catch(std::exception& e)
|
||||
catch(exception& e)
|
||||
{
|
||||
cout << e.what() << "\n";
|
||||
return 1;
|
||||
|
||||
@@ -94,7 +94,7 @@ int main(int ac, char* av[])
|
||||
<< vm["magic"].as<magic_number>().n << "\"\n";
|
||||
}
|
||||
}
|
||||
catch(std::exception& e)
|
||||
catch(exception& e)
|
||||
{
|
||||
cout << e.what() << "\n";
|
||||
}
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
|
||||
#include <boost/program_options/detail/convert.hpp>
|
||||
|
||||
#include <iterator>
|
||||
|
||||
namespace boost { namespace program_options {
|
||||
|
||||
namespace detail {
|
||||
|
||||
@@ -55,12 +55,13 @@ namespace boost { namespace program_options {
|
||||
{
|
||||
static std::basic_string<charT> empty;
|
||||
if (v.size() > 1)
|
||||
boost::throw_exception(validation_error("multiple values not allowed"));
|
||||
else if (v.size() == 1)
|
||||
throw validation_error("multiple values not allowed");
|
||||
if (v.size() == 1)
|
||||
return v.front();
|
||||
else if (!allow_empty)
|
||||
boost::throw_exception(validation_error("at least one value required"));
|
||||
return empty;
|
||||
else if (allow_empty)
|
||||
return empty;
|
||||
else
|
||||
throw validation_error("at least one value required");
|
||||
}
|
||||
|
||||
/* Throws multiple_occurrences if 'value' is not empty. */
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace boost { namespace program_options {
|
||||
add(const char* name, int max_count);
|
||||
|
||||
/** Returns the maximum number of positional options that can
|
||||
be present. Can return (numeric_limits<unsigned>::max)() to
|
||||
be present. Can return numeric_limits<unsigned>::max() to
|
||||
indicate unlimited number. */
|
||||
unsigned max_total_count() const;
|
||||
|
||||
|
||||
3
module.cmake
Normal file
3
module.cmake
Normal file
@@ -0,0 +1,3 @@
|
||||
boost_module(program_options DEPENDS any bind smart_ptr tokenizer)
|
||||
|
||||
# bind is needed because of a dependency on boost/mem_fn.hpp
|
||||
5
src/CMakeLists.txt
Normal file
5
src/CMakeLists.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
boost_add_library(boost_program_options
|
||||
cmdline.cpp config_file.cpp options_description.cpp parsers.cpp
|
||||
variables_map.cpp value_semantic.cpp positional_options.cpp
|
||||
utf8_codecvt_facet.cpp convert.cpp winmain.cpp
|
||||
SHARED_COMPILE_FLAGS "-DBOOST_PROGRAM_OPTIONS_DYN_LINK=1")
|
||||
@@ -152,7 +152,7 @@ namespace boost { namespace program_options { namespace detail {
|
||||
error = "style disallows all characters for short options";
|
||||
|
||||
if (error)
|
||||
boost::throw_exception(invalid_command_line_style(error));
|
||||
throw invalid_command_line_style(error);
|
||||
|
||||
// Need to check that if guessing and long disguise are enabled
|
||||
// -f will mean the same as -foo
|
||||
@@ -196,24 +196,24 @@ namespace boost { namespace program_options { namespace detail {
|
||||
|
||||
if (m_additional_parser)
|
||||
style_parsers.push_back(
|
||||
boost::bind(&cmdline::handle_additional_parser, this, _1));
|
||||
bind(&cmdline::handle_additional_parser, this, _1));
|
||||
|
||||
if (m_style & allow_long)
|
||||
style_parsers.push_back(
|
||||
boost::bind(&cmdline::parse_long_option, this, _1));
|
||||
bind(&cmdline::parse_long_option, this, _1));
|
||||
|
||||
if ((m_style & allow_long_disguise))
|
||||
style_parsers.push_back(
|
||||
boost::bind(&cmdline::parse_disguised_long_option, this, _1));
|
||||
bind(&cmdline::parse_disguised_long_option, this, _1));
|
||||
|
||||
if ((m_style & allow_short) && (m_style & allow_dash_for_short))
|
||||
style_parsers.push_back(
|
||||
boost::bind(&cmdline::parse_short_option, this, _1));
|
||||
bind(&cmdline::parse_short_option, this, _1));
|
||||
|
||||
if ((m_style & allow_short) && (m_style & allow_slash_for_short))
|
||||
style_parsers.push_back(boost::bind(&cmdline::parse_dos_option, this, _1));
|
||||
style_parsers.push_back(bind(&cmdline::parse_dos_option, this, _1));
|
||||
|
||||
style_parsers.push_back(boost::bind(&cmdline::parse_terminator, this, _1));
|
||||
style_parsers.push_back(bind(&cmdline::parse_terminator, this, _1));
|
||||
|
||||
vector<option> result;
|
||||
while(!args.empty())
|
||||
@@ -326,8 +326,8 @@ namespace boost { namespace program_options { namespace detail {
|
||||
if (opt.position_key != -1) {
|
||||
if (position >= m_positional->max_total_count())
|
||||
{
|
||||
boost::throw_exception(too_many_positional_options_error(
|
||||
"too many positional options"));
|
||||
throw too_many_positional_options_error(
|
||||
"too many positional options");
|
||||
}
|
||||
opt.string_key = m_positional->name_for_position(position);
|
||||
++position;
|
||||
@@ -380,8 +380,8 @@ namespace boost { namespace program_options { namespace detail {
|
||||
if (present_tokens >= min_tokens)
|
||||
{
|
||||
if (!opt.value.empty() && max_tokens == 0) {
|
||||
boost::throw_exception(invalid_command_line_syntax(opt.string_key,
|
||||
invalid_command_line_syntax::extra_parameter));
|
||||
throw invalid_command_line_syntax(opt.string_key,
|
||||
invalid_command_line_syntax::extra_parameter);
|
||||
}
|
||||
|
||||
// If an option wants, at minimum, N tokens, we grab them
|
||||
@@ -406,8 +406,8 @@ namespace boost { namespace program_options { namespace detail {
|
||||
}
|
||||
else
|
||||
{
|
||||
boost::throw_exception(invalid_command_line_syntax(opt.string_key,
|
||||
invalid_command_line_syntax::missing_parameter));
|
||||
throw invalid_command_line_syntax(opt.string_key,
|
||||
invalid_command_line_syntax::missing_parameter);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -427,8 +427,8 @@ namespace boost { namespace program_options { namespace detail {
|
||||
name = tok.substr(2, p-2);
|
||||
adjacent = tok.substr(p+1);
|
||||
if (adjacent.empty())
|
||||
boost::throw_exception( invalid_command_line_syntax(name,
|
||||
invalid_command_line_syntax::empty_adjacent_parameter));
|
||||
throw invalid_command_line_syntax(name,
|
||||
invalid_command_line_syntax::empty_adjacent_parameter);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -67,16 +67,10 @@ namespace boost { namespace program_options {
|
||||
woption result;
|
||||
result.string_key = opt.string_key;
|
||||
result.position_key = opt.position_key;
|
||||
result.unregistered = opt.unregistered;
|
||||
|
||||
std::transform(opt.value.begin(), opt.value.end(),
|
||||
back_inserter(result.value),
|
||||
boost::bind(from_utf8, _1));
|
||||
|
||||
std::transform(opt.original_tokens.begin(),
|
||||
opt.original_tokens.end(),
|
||||
back_inserter(result.original_tokens),
|
||||
boost::bind(from_utf8, _1));
|
||||
bind(from_utf8, _1));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,13 +74,11 @@ namespace boost { namespace program_options {
|
||||
try {
|
||||
d.semantic()->parse(v.value(), options.options[i].value, utf8);
|
||||
}
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
catch(validation_error& e)
|
||||
{
|
||||
e.set_option_name(name);
|
||||
throw;
|
||||
}
|
||||
#endif
|
||||
v.m_value_semantic = d.semantic();
|
||||
|
||||
// The option is not composing, and the value is explicitly
|
||||
@@ -135,16 +133,7 @@ namespace boost { namespace program_options {
|
||||
k != vm.end();
|
||||
++k)
|
||||
{
|
||||
/* Users might wish to use variables_map to store their own values
|
||||
that are not parsed, and therefore will not have value_semantics
|
||||
defined. Do no crash on such values. In multi-module programs,
|
||||
one module might add custom values, and the 'notify' function
|
||||
will be called after that, so we check that value_sematics is
|
||||
not NULL. See:
|
||||
https://svn.boost.org/trac/boost/ticket/2782
|
||||
*/
|
||||
if (k->second.m_value_semantic)
|
||||
k->second.m_value_semantic->notify(k->second.value());
|
||||
k->second.m_value_semantic->notify(k->second.value());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
21
test/CMakeLists.txt
Normal file
21
test/CMakeLists.txt
Normal file
@@ -0,0 +1,21 @@
|
||||
boost_additional_test_dependencies(program_options BOOST_DEPENDS test)
|
||||
|
||||
set(PROGRAM_OPTIONS_LIBRARIES
|
||||
boost_program_options
|
||||
boost_test_exec_monitor)
|
||||
|
||||
macro(program_options_test_run TESTNAME)
|
||||
boost_test_run(${TESTNAME}
|
||||
DEPENDS boost_program_options boost_test_exec_monitor STATIC)
|
||||
boost_test_run("${TESTNAME}_dll"
|
||||
"${TESTNAME}.cpp"
|
||||
DEPENDS boost_program_options boost_test_exec_monitor-static SHARED)
|
||||
endmacro(program_options_test_run)
|
||||
|
||||
program_options_test_run(options_description_test)
|
||||
program_options_test_run(parsers_test)
|
||||
program_options_test_run(variable_map_test)
|
||||
program_options_test_run(cmdline_test)
|
||||
program_options_test_run(positional_options_test)
|
||||
program_options_test_run(unicode_test)
|
||||
program_options_test_run(winmain)
|
||||
@@ -34,13 +34,9 @@ void test_unicode_to_unicode()
|
||||
args.push_back(L"--foo=\x044F");
|
||||
|
||||
variables_map vm;
|
||||
basic_parsed_options<wchar_t> parsed =
|
||||
wcommand_line_parser(args).options(desc).run();
|
||||
store(parsed, vm);
|
||||
store(wcommand_line_parser(args).options(desc).run(), vm);
|
||||
|
||||
BOOST_CHECK(vm["foo"].as<wstring>() == L"\x044F");
|
||||
BOOST_CHECK(parsed.options[0].original_tokens.size() == 1);
|
||||
BOOST_CHECK(parsed.options[0].original_tokens[0] == L"--foo=\x044F");
|
||||
BOOST_CHECK(vm["foo"].as<wstring>() == L"\x044F");
|
||||
}
|
||||
|
||||
// Test that unicode input is property converted into
|
||||
|
||||
Reference in New Issue
Block a user