Skip to content

Commit

Permalink
Rename size_t -> std::size_t
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii committed Dec 31, 2019
1 parent ed7e0dc commit d5cd986
Show file tree
Hide file tree
Showing 17 changed files with 115 additions and 112 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ There are several options that are supported on the main app and subcommands and
- `.parse_complete_callback(void() function)`: 🚧 Set the callback that runs at the completion of parsing. for subcommands this is executed at the completion of the single subcommand and can be executed multiple times. See [Subcommand callbacks](#callbacks) for some additional details.
- `.final_callback(void() function)`: 🚧 Set the callback that runs at the end of all processing. This is the last thing that is executed before returning. See [Subcommand callbacks](#callbacks) for some additional details.
- `.immediate_callback()`: 🆕 Specifies whether the callback for a subcommand should be run as a `parse_complete_callback`(true) or `final_callback`(false). When used on the main app 🚧 it will execute the main app callback prior to the callbacks for a subcommand if they do not also have the `immediate_callback` flag set. 🚧 It is preferable to use the `parse_complete_callback` or `final_callback` directly instead of the `callback` and `immediate_callback` if one wishes to control the ordering and timing of callback. Though `immediate_callback` can be used to swap them if that is needed.
- `.pre_parse_callback(void(size_t) function)`: 🆕 Set a callback that executes after the first argument of an application is processed. See [Subcommand callbacks](#callbacks) for some additional details.
- `.pre_parse_callback(void(std::size_t) function)`: 🆕 Set a callback that executes after the first argument of an application is processed. See [Subcommand callbacks](#callbacks) for some additional details.
- `.allow_extras()`: Do not throw an error if extra arguments are left over.
- `.positionals_at_end()`: 🆕 Specify that positional arguments occur as the last arguments and throw an error if an unexpected positional is encountered.
- `.prefix_command()`: Like `allow_extras`, but stop immediately on the first unrecognized item. It is ideal for allowing your app or subcommand to be a "prefix" to calling another app.
Expand Down
2 changes: 1 addition & 1 deletion book/chapters/flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ After parsing, you can use `my_flag->count()` to count the number of times this

## Callback flags

If you want to define a callback that runs when you make a flag, you can use `add_flag_function` (C++11 or newer) or `add_flag` (C++14 or newer only) to add a callback function. The function should have the signature `void(size_t)`. This could be useful for a version printout, etc.
If you want to define a callback that runs when you make a flag, you can use `add_flag_function` (C++11 or newer) or `add_flag` (C++14 or newer only) to add a callback function. The function should have the signature `void(std::size_t)`. This could be useful for a version printout, etc.

```
auto callback = [](int count){std::cout << "This was called " << count << " times";};
Expand Down
2 changes: 1 addition & 1 deletion examples/positional_arity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ int main(int argc, char **argv) {
files->add_option("file1", file1, "first file")->required();
files->add_option("file2", file2, "second file");
// set a pre parse callback that turns the numbers group on or off depending on the number of arguments
app.preparse_callback([numbers](size_t arity) {
app.preparse_callback([numbers](std::size_t arity) {
if(arity <= 2) {
numbers->disabled();
} else {
Expand Down
80 changes: 40 additions & 40 deletions include/CLI/App.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class App {
bool immediate_callback_{false};

/// This is a function that runs prior to the start of parsing
std::function<void(size_t)> pre_parse_callback_{};
std::function<void(std::size_t)> pre_parse_callback_{};

/// This is a function that runs when parsing has finished.
std::function<void()> parse_complete_callback_{};
Expand Down Expand Up @@ -204,19 +204,19 @@ class App {
App *parent_{nullptr};

/// Counts the number of times this command/subcommand was parsed
size_t parsed_{0};
std::size_t parsed_{0};

/// Minimum required subcommands (not inheritable!)
size_t require_subcommand_min_{0};
std::size_t require_subcommand_min_{0};

/// Max number of subcommands allowed (parsing stops after this number). 0 is unlimited INHERITABLE
size_t require_subcommand_max_{0};
std::size_t require_subcommand_max_{0};

/// Minimum required options (not inheritable!)
size_t require_option_min_{0};
std::size_t require_option_min_{0};

/// Max number of options allowed. 0 is unlimited (not inheritable)
size_t require_option_max_{0};
std::size_t require_option_max_{0};

/// The group membership INHERITABLE
std::string group_{"Subcommands"};
Expand Down Expand Up @@ -322,7 +322,7 @@ class App {

/// Set a callback to execute prior to parsing.
///
App *preparse_callback(std::function<void(size_t)> pp_callback) {
App *preparse_callback(std::function<void(std::size_t)> pp_callback) {
pre_parse_callback_ = std::move(pp_callback);
return this;
}
Expand Down Expand Up @@ -1056,12 +1056,12 @@ class App {
/// No argument version of count counts the number of times this subcommand was
/// passed in. The main app will return 1. Unnamed subcommands will also return 1 unless
/// otherwise modified in a callback
size_t count() const { return parsed_; }
std::size_t count() const { return parsed_; }

/// Get a count of all the arguments processed in options and subcommands, this excludes arguments which were
/// treated as extras.
size_t count_all() const {
size_t cnt{0};
std::size_t count_all() const {
std::size_t cnt{0};
for(auto &opt : options_) {
cnt += opt->count();
}
Expand Down Expand Up @@ -1093,17 +1093,17 @@ class App {
App *require_subcommand(int value) {
if(value < 0) {
require_subcommand_min_ = 0;
require_subcommand_max_ = static_cast<size_t>(-value);
require_subcommand_max_ = static_cast<std::size_t>(-value);
} else {
require_subcommand_min_ = static_cast<size_t>(value);
require_subcommand_max_ = static_cast<size_t>(value);
require_subcommand_min_ = static_cast<std::size_t>(value);
require_subcommand_max_ = static_cast<std::size_t>(value);
}
return this;
}

/// Explicitly control the number of subcommands required. Setting 0
/// for the max means unlimited number allowed. Max number inheritable.
App *require_subcommand(size_t min, size_t max) {
App *require_subcommand(std::size_t min, std::size_t max) {
require_subcommand_min_ = min;
require_subcommand_max_ = max;
return this;
Expand All @@ -1122,17 +1122,17 @@ class App {
App *require_option(int value) {
if(value < 0) {
require_option_min_ = 0;
require_option_max_ = static_cast<size_t>(-value);
require_option_max_ = static_cast<std::size_t>(-value);
} else {
require_option_min_ = static_cast<size_t>(value);
require_option_max_ = static_cast<size_t>(value);
require_option_min_ = static_cast<std::size_t>(value);
require_option_max_ = static_cast<std::size_t>(value);
}
return this;
}

/// Explicitly control the number of options required. Setting 0
/// for the max means unlimited number allowed. Max number inheritable.
App *require_option(size_t min, size_t max) {
App *require_option(std::size_t min, std::size_t max) {
require_option_min_ = min;
require_option_max_ = max;
return this;
Expand Down Expand Up @@ -1188,7 +1188,7 @@ class App {
}

std::vector<std::string> args;
args.reserve(static_cast<size_t>(argc) - 1);
args.reserve(static_cast<std::size_t>(argc) - 1);
for(int i = argc - 1; i > 0; i--)
args.emplace_back(argv[i]);
parse(std::move(args));
Expand Down Expand Up @@ -1300,7 +1300,7 @@ class App {
///@{

/// Counts the number of times the given option was passed.
size_t count(std::string option_name) const { return get_option(option_name)->count(); }
std::size_t count(std::string option_name) const { return get_option(option_name)->count(); }

/// Get a subcommand pointer list to the currently selected subcommands (after parsing by default, in command
/// line order; use parsed = false to get the original definition list.)
Expand Down Expand Up @@ -1608,16 +1608,16 @@ class App {
std::string get_footer() const { return (footer_callback_) ? footer_callback_() + '\n' + footer_ : footer_; }

/// Get the required min subcommand value
size_t get_require_subcommand_min() const { return require_subcommand_min_; }
std::size_t get_require_subcommand_min() const { return require_subcommand_min_; }

/// Get the required max subcommand value
size_t get_require_subcommand_max() const { return require_subcommand_max_; }
std::size_t get_require_subcommand_max() const { return require_subcommand_max_; }

/// Get the required min option value
size_t get_require_option_min() const { return require_option_min_; }
std::size_t get_require_option_min() const { return require_option_min_; }

/// Get the required max option value
size_t get_require_option_max() const { return require_option_max_; }
std::size_t get_require_option_max() const { return require_option_max_; }

/// Get the prefix command status
bool get_prefix_command() const { return prefix_command_; }
Expand Down Expand Up @@ -1762,8 +1762,8 @@ class App {
}

/// This returns the number of remaining options, minus the -- separator
size_t remaining_size(bool recurse = false) const {
auto remaining_options = static_cast<size_t>(std::count_if(
std::size_t remaining_size(bool recurse = false) const {
auto remaining_options = static_cast<std::size_t>(std::count_if(
std::begin(missing_), std::end(missing_), [](const std::pair<detail::Classifier, std::string> &val) {
return val.first != detail::Classifier::POSITIONAL_MARK;
}));
Expand Down Expand Up @@ -1798,7 +1798,7 @@ class App {
}
}

size_t nameless_subs{0};
std::size_t nameless_subs{0};
for(const App_p &app : subcommands_) {
app->_validate();
if(app->get_name().empty())
Expand Down Expand Up @@ -1943,7 +1943,7 @@ class App {

#ifdef _MSC_VER
// Windows version
size_t sz = 0;
std::size_t sz = 0;
if(_dupenv_s(&buffer, &sz, opt->envname_.c_str()) == 0 && buffer != nullptr) {
ename_string = std::string(buffer);
free(buffer);
Expand Down Expand Up @@ -2065,7 +2065,7 @@ class App {
return;
}

size_t used_options = 0;
std::size_t used_options = 0;
for(const Option_p &opt : options_) {

if(opt->count() != 0) {
Expand Down Expand Up @@ -2155,7 +2155,7 @@ class App {
/// Throw an error if anything is left over and should not be.
void _process_extras() {
if(!(allow_extras_ || prefix_command_)) {
size_t num_left_over = remaining_size();
std::size_t num_left_over = remaining_size();
if(num_left_over > 0) {
throw ExtrasError(name_, remaining(false));
}
Expand All @@ -2171,7 +2171,7 @@ class App {
/// Modifies the args to fill in the missing items before throwing.
void _process_extras(std::vector<std::string> &args) {
if(!(allow_extras_ || prefix_command_)) {
size_t num_left_over = remaining_size();
std::size_t num_left_over = remaining_size();
if(num_left_over > 0) {
args = remaining(false);
throw ExtrasError(name_, args);
Expand Down Expand Up @@ -2250,7 +2250,7 @@ class App {
}

/// Fill in a single config option
bool _parse_single_config(const ConfigItem &item, size_t level = 0) {
bool _parse_single_config(const ConfigItem &item, std::size_t level = 0) {
if(level < item.parents.size()) {
try {
auto subcom = get_subcommand(item.parents.at(level));
Expand Down Expand Up @@ -2334,13 +2334,13 @@ class App {
}

/// Count the required remaining positional arguments
size_t _count_remaining_positionals(bool required_only = false) const {
size_t retval = 0;
std::size_t _count_remaining_positionals(bool required_only = false) const {
std::size_t retval = 0;
for(const Option_p &opt : options_) {
if(opt->get_positional() && (!required_only || opt->get_required())) {
if(opt->get_items_expected_min() > 0 &&
static_cast<int>(opt->count()) < opt->get_items_expected_min()) {
retval += static_cast<size_t>(opt->get_items_expected_min()) - opt->count();
retval += static_cast<std::size_t>(opt->get_items_expected_min()) - opt->count();
}
}
}
Expand Down Expand Up @@ -2655,7 +2655,7 @@ class App {
}

/// Trigger the pre_parse callback if needed
void _trigger_pre_parse(size_t remaining_args) {
void _trigger_pre_parse(std::size_t remaining_args) {
if(!pre_parse_called_) {
pre_parse_called_ = true;
if(pre_parse_callback_) {
Expand Down Expand Up @@ -2831,7 +2831,7 @@ class Option_group : public App {
inline void TriggerOn(App *trigger_app, App *app_to_enable) {
app_to_enable->enabled_by_default(false);
app_to_enable->disabled_by_default();
trigger_app->preparse_callback([app_to_enable](size_t) { app_to_enable->disabled(false); });
trigger_app->preparse_callback([app_to_enable](std::size_t) { app_to_enable->disabled(false); });
}

/// Helper function to enable one option group/subcommand when another is used
Expand All @@ -2841,7 +2841,7 @@ inline void TriggerOn(App *trigger_app, std::vector<App *> apps_to_enable) {
app->disabled_by_default();
}

trigger_app->preparse_callback([apps_to_enable](size_t) {
trigger_app->preparse_callback([apps_to_enable](std::size_t) {
for(auto &app : apps_to_enable) {
app->disabled(false);
}
Expand All @@ -2852,7 +2852,7 @@ inline void TriggerOn(App *trigger_app, std::vector<App *> apps_to_enable) {
inline void TriggerOff(App *trigger_app, App *app_to_enable) {
app_to_enable->disabled_by_default(false);
app_to_enable->enabled_by_default();
trigger_app->preparse_callback([app_to_enable](size_t) { app_to_enable->disabled(); });
trigger_app->preparse_callback([app_to_enable](std::size_t) { app_to_enable->disabled(); });
}

/// Helper function to disable one option group/subcommand when another is used
Expand All @@ -2862,7 +2862,7 @@ inline void TriggerOff(App *trigger_app, std::vector<App *> apps_to_enable) {
app->enabled_by_default();
}

trigger_app->preparse_callback([apps_to_enable](size_t) {
trigger_app->preparse_callback([apps_to_enable](std::size_t) {
for(auto &app : apps_to_enable) {
app->disabled();
}
Expand Down
4 changes: 2 additions & 2 deletions include/CLI/ConfigFwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace detail {
/// Comma separated join, adds quotes if needed
inline std::string ini_join(std::vector<std::string> args) {
std::ostringstream s;
size_t start = 0;
std::size_t start = 0;
for(const auto &arg : args) {
if(start++ > 0)
s << " ";
Expand Down Expand Up @@ -107,7 +107,7 @@ class ConfigINI : public Config {
std::vector<std::string> items_buffer;

detail::trim(line);
size_t len = line.length();
std::size_t len = line.length();
if(len > 1 && line[0] == '[' && line[len - 1] == ']') {
section = line.substr(1, len - 2);
} else if(len > 0 && line[0] != ';') {
Expand Down
11 changes: 6 additions & 5 deletions include/CLI/Error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,15 @@ class ValidationError : public ParseError {
class RequiredError : public ParseError {
CLI11_ERROR_DEF(ParseError, RequiredError)
explicit RequiredError(std::string name) : RequiredError(name + " is required", ExitCodes::RequiredError) {}
static RequiredError Subcommand(size_t min_subcom) {
static RequiredError Subcommand(std::size_t min_subcom) {
if(min_subcom == 1) {
return RequiredError("A subcommand");
}
return RequiredError("Requires at least " + std::to_string(min_subcom) + " subcommands",
ExitCodes::RequiredError);
}
static RequiredError Option(size_t min_option, size_t max_option, size_t used, const std::string &option_list) {
static RequiredError
Option(std::size_t min_option, std::size_t max_option, std::size_t used, const std::string &option_list) {
if((min_option == 1) && (max_option == 1) && (used == 0))
return RequiredError("Exactly 1 option from [" + option_list + "]");
if((min_option == 1) && (max_option == 1) && (used > 1))
Expand All @@ -239,18 +240,18 @@ class RequiredError : public ParseError {
class ArgumentMismatch : public ParseError {
CLI11_ERROR_DEF(ParseError, ArgumentMismatch)
CLI11_ERROR_SIMPLE(ArgumentMismatch)
ArgumentMismatch(std::string name, int expected, size_t recieved)
ArgumentMismatch(std::string name, int expected, std::size_t recieved)
: ArgumentMismatch(expected > 0 ? ("Expected exactly " + std::to_string(expected) + " arguments to " + name +
", got " + std::to_string(recieved))
: ("Expected at least " + std::to_string(-expected) + " arguments to " + name +
", got " + std::to_string(recieved)),
ExitCodes::ArgumentMismatch) {}

static ArgumentMismatch AtLeast(std::string name, int num, size_t received) {
static ArgumentMismatch AtLeast(std::string name, int num, std::size_t received) {
return ArgumentMismatch(name + ": At least " + std::to_string(num) + " required but received " +
std::to_string(received));
}
static ArgumentMismatch AtMost(std::string name, int num, size_t received) {
static ArgumentMismatch AtMost(std::string name, int num, std::size_t received) {
return ArgumentMismatch(name + ": At Most " + std::to_string(num) + " required but received " +
std::to_string(received));
}
Expand Down
6 changes: 3 additions & 3 deletions include/CLI/FormatterFwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class FormatterBase {
///@{

/// The width of the first column
size_t column_width_{30};
std::size_t column_width_{30};

/// @brief The required help printout labels (user changeable)
/// Values are Needs, Excludes, etc.
Expand Down Expand Up @@ -64,7 +64,7 @@ class FormatterBase {
void label(std::string key, std::string val) { labels_[key] = val; }

/// Set the column width
void column_width(size_t val) { column_width_ = val; }
void column_width(std::size_t val) { column_width_ = val; }

///@}
/// @name Getters
Expand All @@ -79,7 +79,7 @@ class FormatterBase {
}

/// Get the current column width
size_t get_column_width() const { return column_width_; }
std::size_t get_column_width() const { return column_width_; }

///@}
};
Expand Down
Loading

0 comments on commit d5cd986

Please sign in to comment.