Skip to content

Update deprecated uses of boost/bind.hpp, replace standard function wrappers with boost::bind #91

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions example/config_file_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ stringstream make_file()
ss << "word = word\n";
ss << "phrase = this is a phrase\n";
ss << "quoted = \"quotes are in result\"\n";

ss << "\n[ints]\n";
ss << "positive = 41\n";
ss << "negative = -42\n";
Expand Down Expand Up @@ -71,7 +71,7 @@ stringstream make_file()
ss << "onoff_true = on\n";
ss << "onoff_false = off\n";
ss << "present_equal_true = \n";
//FAILS: Must be an =
//FAILS: Must be an =
//ss << "present_no_equal_true\n";

ss.seekp(ios_base::beg);
Expand Down Expand Up @@ -236,7 +236,7 @@ int main(int ac, char* av[])
auto opts = set_options();
po::variables_map vars;
auto unregistered = parse_file(file, opts, vars);
check_results(vars, unregistered);
check_results(vars, unregistered);

return 0;
}
10 changes: 5 additions & 5 deletions example/custom_syntax.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

/** This example shows how to support custom options syntax.

It's possible to install 'custom_parser'. It will be invoked on all command
line tokens and can return name/value pair, or nothing. If it returns
It's possible to install 'custom_parser'. It will be invoked on all command
line tokens and can return name/value pair, or nothing. If it returns
nothing, usual processing will be done.
*/

Expand All @@ -20,7 +20,7 @@ using namespace boost::program_options;
#include <iostream>
using namespace std;

/* This custom option parse function recognize gcc-style
/* This custom option parse function recognize gcc-style
option "-fbar" / "-fno-bar".
*/
pair<string, string> reg_foo(const string& s)
Expand All @@ -32,7 +32,7 @@ pair<string, string> reg_foo(const string& s)
return make_pair(s.substr(2), string("true"));
} else {
return make_pair(string(), string());
}
}
}

int main(int ac, char* av[])
Expand All @@ -53,7 +53,7 @@ int main(int ac, char* av[])
cout << "\nIn addition -ffoo and -fno-foo syntax are recognized.\n";
}
if (vm.count("foo")) {
cout << "foo value with the value of "
cout << "foo value with the value of "
<< vm["foo"].as<string>() << "\n";
}
}
Expand Down
6 changes: 3 additions & 3 deletions example/first.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ int main(int ac, char* av[])
("compression", po::value<double>(), "set compression level")
;

po::variables_map vm;
po::variables_map vm;
po::store(po::parse_command_line(ac, av, desc), vm);
po::notify(vm);
po::notify(vm);

if (vm.count("help")) {
cout << desc << "\n";
return 0;
}

if (vm.count("compression")) {
cout << "Compression level was set to "
cout << "Compression level was set to "
<< vm["compression"].as<double>() << ".\n";
} else {
cout << "Compression level was not set.\n";
Expand Down
34 changes: 17 additions & 17 deletions example/multiple_sources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ using namespace std;
template<class T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
copy(v.begin(), v.end(), ostream_iterator<T>(os, " "));
copy(v.begin(), v.end(), ostream_iterator<T>(os, " "));
return os;
}

Expand All @@ -28,8 +28,8 @@ int main(int ac, char* av[])
try {
int opt;
string config_file;
// Declare a group of options that will be

// Declare a group of options that will be
// allowed only on command line
po::options_description generic("Generic options");
generic.add_options()
Expand All @@ -38,16 +38,16 @@ int main(int ac, char* av[])
("config,c", po::value<string>(&config_file)->default_value("multiple_sources.cfg"),
"name of a file of a configuration.")
;
// Declare a group of options that will be

// Declare a group of options that will be
// allowed both on command line and in
// config file
po::options_description config("Configuration");
config.add_options()
("optimization", po::value<int>(&opt)->default_value(10),
("optimization", po::value<int>(&opt)->default_value(10),
"optimization level")
("include-path,I",
po::value< vector<string> >()->composing(),
("include-path,I",
po::value< vector<string> >()->composing(),
"include path")
;

Expand All @@ -58,7 +58,7 @@ int main(int ac, char* av[])
("input-file", po::value< vector<string> >(), "input file")
;


po::options_description cmdline_options;
cmdline_options.add(generic).add(config).add(hidden);

Expand All @@ -67,15 +67,15 @@ int main(int ac, char* av[])

po::options_description visible("Allowed options");
visible.add(generic).add(config);

po::positional_options_description p;
p.add("input-file", -1);

po::variables_map vm;
store(po::command_line_parser(ac, av).
options(cmdline_options).positional(p).run(), vm);
notify(vm);

ifstream ifs(config_file.c_str());
if (!ifs)
{
Expand All @@ -87,7 +87,7 @@ int main(int ac, char* av[])
store(parse_config_file(ifs, config_file_options), vm);
notify(vm);
}

if (vm.count("help")) {
cout << visible << "\n";
return 0;
Expand All @@ -100,22 +100,22 @@ int main(int ac, char* av[])

if (vm.count("include-path"))
{
cout << "Include paths are: "
cout << "Include paths are: "
<< vm["include-path"].as< vector<string> >() << "\n";
}

if (vm.count("input-file"))
{
cout << "Input files are: "
cout << "Input files are: "
<< vm["input-file"].as< vector<string> >() << "\n";
}

cout << "Optimization level is " << opt << "\n";
cout << "Optimization level is " << opt << "\n";
}
catch(exception& e)
{
cout << e.what() << "\n";
return 1;
}
}
return 0;
}
12 changes: 6 additions & 6 deletions example/option_groups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ int main(int ac, char* av[])
backend.add_options()
("num-threads", value<int>(), "the initial number of threads")
;

// Declare an options description instance which will include
// all the options
options_description all("Allowed options");
Expand All @@ -63,12 +63,12 @@ int main(int ac, char* av[])
// to the user
options_description visible("Allowed options");
visible.add(general).add(gui);


variables_map vm;
store(parse_command_line(ac, av, all), vm);

if (vm.count("help"))
if (vm.count("help"))
{
cout << visible;
return 0;
Expand All @@ -80,16 +80,16 @@ int main(int ac, char* av[])
} else if (s == "backend") {
cout << backend;
} else {
cout << "Unknown module '"
cout << "Unknown module '"
<< s << "' in the --help-module option\n";
return 1;
}
return 0;
}
if (vm.count("num-threads")) {
cout << "The 'num-threads' options was set to "
<< vm["num-threads"].as<int>() << "\n";
}
<< vm["num-threads"].as<int>() << "\n";
}
}
catch(std::exception& e) {
cout << e.what() << "\n";
Expand Down
46 changes: 24 additions & 22 deletions example/options_heirarchy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
// (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)

//
//
// This is an example of a program that uses multiple facets of the boost
// program_options library. It will go through different types of config
// program_options library. It will go through different types of config
// options in a heirarchal manner:
// 1. Default options are set.
// 2. Command line options are set (they override defaults).
Expand All @@ -16,17 +16,19 @@
// other steps).
// 5. Default config file (default.cfg) is read, if present (it overrides
// defaults but not options from the other steps).
//
//
// See the bottom of this file for full usage examples
//

#include <boost/program_options.hpp>
namespace po = boost::program_options;
#include <string>
#include <iostream>
#include <map>
#include <stdexcept>
#include <fstream>
#include <boost/bind/bind.hpp>

namespace po = boost::program_options;

const std::string version("1.0");

Expand Down Expand Up @@ -215,13 +217,13 @@ class OptionsHeirarchy
std::cout << "Program Options Example " << version << std::endl;
throw OptionsExitsProgram();
}
void ParseEnvironment()
void ParseEnvironment()
{
store(po::parse_environment(common_options,
// The next two lines are the crazy syntax to use EnvironmentMapper as
// the lookup function for env->config name conversions
boost::function1<std::string, std::string>(
std::bind1st(std::mem_fun(&OptionsHeirarchy::EnvironmentMapper), this))),
boost::bind(&OptionsHeirarchy::EnvironmentMapper, this))),
results);
notify(results);
}
Expand Down Expand Up @@ -331,16 +333,16 @@ int main(int ac, char* av[])
return 0;
}

/*
/*
Full Usage Examples
===================

These were run on windows, so some results may show that environment, but
These were run on windows, so some results may show that environment, but
results should be similar on POSIX platforms.

Help
----
To see the help screen, with the available options just pass the --help (or -h)
To see the help screen, with the available options just pass the --help (or -h)
parameter. The program will then exit.

> example.exe --help
Expand All @@ -365,10 +367,10 @@ Version is similar to help (--version or -v).

Basics
------
Running without any options will get the default values (path is set from the
Running without any options will get the default values (path is set from the
environment):

> example.exe
> example.exe
First 75 chars of the system path:
C:\Program Files (x86)\MSBuild\14.0\bin;C:\Perl\site\bin;C:\Perl\bin;C:\Pro
Verbosity: INFO
Expand Down Expand Up @@ -434,8 +436,8 @@ Or you can put the option immediately after it:
Network Address: 127.0.0.1
Network Port: 12345

The include path (--include-path or -I) option allows for multiple paths to be
specified (both on the command line and in config files) and combined into a
The include path (--include-path or -I) option allows for multiple paths to be
specified (both on the command line and in config files) and combined into a
vector for use by the program.

> example.exe --include-path=a/b/c --include-path d/e/f -I g/h/i -Ij/k/l
Expand All @@ -453,7 +455,7 @@ vector for use by the program.
Network Address: 127.0.0.1
Network Port: 12345

There are also the option of flags that do not take parameters and just set a
There are also the option of flags that do not take parameters and just set a
boolean value to true. In this case, running the gui also causes default values
for the gui to be output to the screen.

Expand Down Expand Up @@ -489,7 +491,7 @@ one specifies the "master" file the others are additional files.

Environment Variables
---------------------
In addition to the PATH environment variable, it also knows how to read the
In addition to the PATH environment variable, it also knows how to read the
EXAMPLE_VERBOSE environmental variable and use that to set the verbosity
option/

Expand All @@ -507,7 +509,7 @@ option/

However, if the --verboseity flag is also set, it will override the env
variable. This illustrates an important example, the way program_options works,
is that a parser will not override a value that has previously been set by
is that a parser will not override a value that has previously been set by
another parser. Thus the env parser doesn't override the command line parser.
(We will see this again in config files.) Default values are seperate from this
heirarcy, they only apply if no parser has set the value and it is being read.
Expand All @@ -525,7 +527,7 @@ heirarcy, they only apply if no parser has set the value and it is being read.
Network Port: 12345

(You can unset an environmental variable with an empty set command)

> set EXAMPLE_VERBOSE=
> example.exe
First 75 chars of the system path:
Expand All @@ -542,7 +544,7 @@ heirarcy, they only apply if no parser has set the value and it is being read.
Config Files
------------
Config files generally follow the [INI file format]
(https://en.wikipedia.org/wiki/INI_file) with a few exceptions.
(https://en.wikipedia.org/wiki/INI_file) with a few exceptions.

Values can be simply added tp options with an equal sign. Here are two include
paths added via the default config file (default.cfg), you can have optional
Expand Down Expand Up @@ -659,7 +661,7 @@ Results in a combination of all three config files:
Network Address: 5.6.7.8
Network Port: 3000

Incidently the boolean run-gui option could have been set a number of ways
Incidently the boolean run-gui option could have been set a number of ways
that all result in the C++ boolean value of true:

run-gui=true
Expand All @@ -670,10 +672,10 @@ that all result in the C++ boolean value of true:

Since run-gui is an option that was set with the bool_switch type, which
forces its use on the command line without a parameter (i.e. --run-gui instead
of --run-gui=true) it can't be given a "false" option, bool_switch values can
of --run-gui=true) it can't be given a "false" option, bool_switch values can
only be turned true. If instead we had a value ("my-switch", po::value<bool>())
that could be set at the command line --my-switch=true or --my-switch=false, or
any of the other types of boolean keywords true: true, on, 1, yes;
that could be set at the command line --my-switch=true or --my-switch=false, or
any of the other types of boolean keywords true: true, on, 1, yes;
false: false, off, 0, no. In a config file this could look like:

my-switch=true
Expand Down
Loading