mirror of
https://github.com/boostorg/program_options.git
synced 2026-01-20 16:52:14 +00:00
Compare commits
1 Commits
boost-1.56
...
boost-1.50
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
78e9c5ec3e |
@@ -8,7 +8,7 @@
|
||||
#ifndef PROGRAM_OPTIONS_VP_2003_05_19
|
||||
#define PROGRAM_OPTIONS_VP_2003_05_19
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#if _MSC_VER >= 1020
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
|
||||
@@ -105,9 +105,12 @@ namespace boost { namespace program_options {
|
||||
int);
|
||||
#endif
|
||||
// For some reason, this declaration, which is require by the standard,
|
||||
// cause msvc 7.1 to not generate code to specialization defined in
|
||||
// cause gcc 3.2 to not generate code to specialization defined in
|
||||
// value_semantic.cpp
|
||||
#if ! ( BOOST_WORKAROUND(BOOST_MSVC, == 1310) )
|
||||
#if ! ( ( BOOST_WORKAROUND(__GNUC__, <= 3) &&\
|
||||
BOOST_WORKAROUND(__GNUC_MINOR__, < 3) ) || \
|
||||
( BOOST_WORKAROUND(BOOST_MSVC, == 1310) ) \
|
||||
)
|
||||
BOOST_PROGRAM_OPTIONS_DECL void validate(boost::any& v,
|
||||
const std::vector<std::string>& xs,
|
||||
std::string*,
|
||||
|
||||
@@ -25,8 +25,7 @@ namespace boost { namespace program_options {
|
||||
|
||||
inline std::string strip_prefixes(const std::string& text)
|
||||
{
|
||||
// "--foo-bar" -> "foo-bar"
|
||||
return text.substr(text.find_first_not_of("-/"));
|
||||
return text.substr(text.find_last_of("-/") + 1);
|
||||
}
|
||||
|
||||
/** Base class for all errors in the library. */
|
||||
@@ -105,13 +104,13 @@ namespace boost { namespace program_options {
|
||||
std::map<std::string, string_pair > m_substitution_defaults;
|
||||
|
||||
public:
|
||||
/** template with placeholders */
|
||||
std::string m_error_template;
|
||||
/** template with placeholders */
|
||||
std::string m_error_template;
|
||||
|
||||
error_with_option_name(const std::string& template_,
|
||||
const std::string& option_name = "",
|
||||
const std::string& original_token = "",
|
||||
int option_style = 0);
|
||||
error_with_option_name(const std::string& template_,
|
||||
const std::string& option_name = "",
|
||||
const std::string& original_token = "",
|
||||
int option_style = 0);
|
||||
|
||||
/** gcc says that throw specification on dtor is loosened
|
||||
* without this line
|
||||
@@ -251,7 +250,7 @@ namespace boost { namespace program_options {
|
||||
}
|
||||
|
||||
/** Does NOT set option name, because no option name makes sense */
|
||||
virtual void set_option_name(const std::string&) {}
|
||||
virtual void set_option_name(const std::string& option_name){}
|
||||
|
||||
~error_with_no_option_name() throw() {}
|
||||
};
|
||||
|
||||
@@ -61,8 +61,8 @@ namespace program_options {
|
||||
|
||||
Alas, derived->base conversion for auto_ptr does not really work,
|
||||
see
|
||||
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2000/n1232.pdf
|
||||
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#84
|
||||
http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2000/n1232.pdf
|
||||
http://std.dkuug.dk/jtc1/sc22/wg21/docs/cwg_defects.html#84
|
||||
|
||||
So, we have to use plain old pointers. Besides, users are not
|
||||
expected to use the constructor directly.
|
||||
@@ -199,10 +199,6 @@ namespace program_options {
|
||||
*/
|
||||
options_description& add(const options_description& desc);
|
||||
|
||||
/** Find the maximum width of the option column, including options
|
||||
in groups. */
|
||||
unsigned get_option_column_width() const;
|
||||
|
||||
public:
|
||||
/** Returns an object of implementation-defined type suitable for adding
|
||||
options to options_description. The returned object will
|
||||
@@ -233,7 +229,7 @@ namespace program_options {
|
||||
|
||||
/** Outputs 'desc' to the specified stream, calling 'f' to output each
|
||||
option_description element. */
|
||||
void print(std::ostream& os, unsigned width = 0) const;
|
||||
void print(std::ostream& os) const;
|
||||
|
||||
private:
|
||||
typedef std::map<std::string, int>::const_iterator name2index_iterator;
|
||||
|
||||
@@ -98,7 +98,7 @@ namespace boost { namespace program_options {
|
||||
void store(const basic_parsed_options<char>& options,
|
||||
variables_map& m, bool);
|
||||
|
||||
friend class BOOST_PROGRAM_OPTIONS_DECL variables_map;
|
||||
friend BOOST_PROGRAM_OPTIONS_DECL class variables_map;
|
||||
};
|
||||
|
||||
/** Implements string->string mapping with convenient value casting
|
||||
|
||||
@@ -249,7 +249,7 @@ namespace boost { namespace program_options { namespace detail {
|
||||
bool ok = false;
|
||||
for(unsigned i = 0; i < style_parsers.size(); ++i)
|
||||
{
|
||||
unsigned current_size = static_cast<unsigned>(args.size());
|
||||
unsigned current_size = args.size();
|
||||
vector<option> next = style_parsers[i](args);
|
||||
|
||||
// Check that option names
|
||||
@@ -321,7 +321,7 @@ namespace boost { namespace program_options { namespace detail {
|
||||
// We only allow to grab tokens that are not already
|
||||
// recognized as key options.
|
||||
|
||||
int can_take_more = max_tokens - static_cast<int>(opt.value.size());
|
||||
int can_take_more = max_tokens - opt.value.size();
|
||||
unsigned j = i+1;
|
||||
for (; can_take_more && j < result.size(); --can_take_more, ++j)
|
||||
{
|
||||
@@ -440,7 +440,7 @@ namespace boost { namespace program_options { namespace detail {
|
||||
unsigned min_tokens = d.semantic()->min_tokens();
|
||||
unsigned max_tokens = d.semantic()->max_tokens();
|
||||
|
||||
unsigned present_tokens = static_cast<unsigned>(opt.value.size() + other_tokens.size());
|
||||
unsigned present_tokens = opt.value.size() + other_tokens.size();
|
||||
|
||||
if (present_tokens >= min_tokens)
|
||||
{
|
||||
@@ -455,7 +455,7 @@ namespace boost { namespace program_options { namespace detail {
|
||||
// if they look like options
|
||||
if (opt.value.size() <= min_tokens)
|
||||
{
|
||||
min_tokens -= static_cast<unsigned>(opt.value.size());
|
||||
min_tokens -= opt.value.size();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -147,7 +147,7 @@ namespace boost { namespace program_options {
|
||||
if (prefix_style == command_line_style::allow_long_disguise)
|
||||
return "-" + m_long_name;
|
||||
}
|
||||
// sanity check: m_short_name[0] should be '-' or '/'
|
||||
// sanity check: m_short_name[0] should be '-' or '/'
|
||||
if (m_short_name.length() == 2)
|
||||
{
|
||||
if (prefix_style == command_line_style::allow_slash_for_short)
|
||||
@@ -469,7 +469,7 @@ namespace boost { namespace program_options {
|
||||
// Take care to never increment the iterator past
|
||||
// the end, since MSVC 8.0 (brokenly), assumes that
|
||||
// doing that, even if no access happens, is a bug.
|
||||
unsigned remaining = static_cast<unsigned>(std::distance(line_begin, par_end));
|
||||
unsigned remaining = distance(line_begin, par_end);
|
||||
string::const_iterator line_end = line_begin +
|
||||
((remaining < line_length) ? remaining : line_length);
|
||||
|
||||
@@ -489,7 +489,7 @@ namespace boost { namespace program_options {
|
||||
{
|
||||
// is last_space within the second half ot the
|
||||
// current line
|
||||
if (static_cast<unsigned>(std::distance(last_space, line_end)) <
|
||||
if (static_cast<unsigned>(distance(last_space, line_end)) <
|
||||
(line_length / 2))
|
||||
{
|
||||
line_end = last_space;
|
||||
@@ -502,8 +502,8 @@ namespace boost { namespace program_options {
|
||||
|
||||
if (first_line)
|
||||
{
|
||||
indent += static_cast<unsigned>(par_indent);
|
||||
line_length -= static_cast<unsigned>(par_indent); // there's less to work with now
|
||||
indent += par_indent;
|
||||
line_length -= par_indent; // there's less to work with now
|
||||
first_line = false;
|
||||
}
|
||||
|
||||
@@ -592,7 +592,7 @@ namespace boost { namespace program_options {
|
||||
os.put(' ');
|
||||
}
|
||||
} else {
|
||||
for(unsigned pad = first_column_width - static_cast<unsigned>(ss.str().size()); pad > 0; --pad)
|
||||
for(unsigned pad = first_column_width - ss.str().size(); pad > 0; --pad)
|
||||
{
|
||||
os.put(' ');
|
||||
}
|
||||
@@ -604,9 +604,12 @@ namespace boost { namespace program_options {
|
||||
}
|
||||
}
|
||||
|
||||
unsigned
|
||||
options_description::get_option_column_width() const
|
||||
void
|
||||
options_description::print(std::ostream& os) const
|
||||
{
|
||||
if (!m_caption.empty())
|
||||
os << m_caption << ":\n";
|
||||
|
||||
/* Find the maximum width of the option column */
|
||||
unsigned width(23);
|
||||
unsigned i; // vc6 has broken for loop scoping
|
||||
@@ -617,11 +620,6 @@ namespace boost { namespace program_options {
|
||||
ss << " " << opt.format_name() << ' ' << opt.format_parameter();
|
||||
width = (max)(width, static_cast<unsigned>(ss.str().size()));
|
||||
}
|
||||
|
||||
/* Get width of groups as well*/
|
||||
for (unsigned j = 0; j < groups.size(); ++j)
|
||||
width = max(width, groups[j]->get_option_column_width());
|
||||
|
||||
/* this is the column were description should start, if first
|
||||
column is longer, we go to a new line */
|
||||
const unsigned start_of_description_column = m_line_length - m_min_description_length;
|
||||
@@ -630,20 +628,9 @@ namespace boost { namespace program_options {
|
||||
|
||||
/* add an additional space to improve readability */
|
||||
++width;
|
||||
return width;
|
||||
}
|
||||
|
||||
void
|
||||
options_description::print(std::ostream& os, unsigned width) const
|
||||
{
|
||||
if (!m_caption.empty())
|
||||
os << m_caption << ":\n";
|
||||
|
||||
if (!width)
|
||||
width = get_option_column_width();
|
||||
|
||||
|
||||
/* The options formatting style is stolen from Subversion. */
|
||||
for (unsigned i = 0; i < m_options.size(); ++i)
|
||||
for (i = 0; i < m_options.size(); ++i)
|
||||
{
|
||||
if (belong_to_group[i])
|
||||
continue;
|
||||
@@ -656,8 +643,7 @@ namespace boost { namespace program_options {
|
||||
}
|
||||
|
||||
for (unsigned j = 0; j < groups.size(); ++j) {
|
||||
os << "\n";
|
||||
groups[j]->print(os, width);
|
||||
os << "\n" << *groups[j];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace boost { namespace program_options {
|
||||
positional_options_description::max_total_count() const
|
||||
{
|
||||
return m_trailing.empty() ?
|
||||
static_cast<unsigned>(m_names.size()) : (std::numeric_limits<unsigned>::max)();
|
||||
m_names.size() : (std::numeric_limits<unsigned>::max)();
|
||||
}
|
||||
|
||||
const std::string&
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
#include <boost/program_options/parsers.hpp>
|
||||
#include <cctype>
|
||||
|
||||
using std::size_t;
|
||||
|
||||
#ifdef _WIN32
|
||||
namespace boost { namespace program_options {
|
||||
|
||||
@@ -91,7 +89,7 @@ namespace boost { namespace program_options {
|
||||
{
|
||||
std::vector<std::wstring> result;
|
||||
std::vector<std::string> aux = split_winmain(to_internal(cmdline));
|
||||
for (size_t i = 0, e = aux.size(); i < e; ++i)
|
||||
for (unsigned i = 0, e = aux.size(); i < e; ++i)
|
||||
result.push_back(from_utf8(aux[i]));
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -32,7 +32,6 @@ test-suite program_options :
|
||||
[ po-test split_test.cpp ]
|
||||
[ po-test unrecognized_test.cpp ]
|
||||
[ po-test required_test.cpp : required_test.cfg ]
|
||||
[ po-test exception_txt_test.cpp ]
|
||||
;
|
||||
|
||||
exe test_convert : test_convert.cpp ;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user