diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
commit | 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch) | |
tree | e5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/boost/libs/program_options/example/options_description.cpp | |
parent | Initial commit. (diff) | |
download | ceph-upstream.tar.xz ceph-upstream.zip |
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/program_options/example/options_description.cpp')
-rw-r--r-- | src/boost/libs/program_options/example/options_description.cpp | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/src/boost/libs/program_options/example/options_description.cpp b/src/boost/libs/program_options/example/options_description.cpp new file mode 100644 index 00000000..e9ad2a67 --- /dev/null +++ b/src/boost/libs/program_options/example/options_description.cpp @@ -0,0 +1,86 @@ +// Copyright Vladimir Prus 2002-2004. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/program_options.hpp> + +using namespace boost; +namespace po = boost::program_options; + +#include <iostream> +#include <algorithm> +#include <iterator> +using namespace std; + + +// A helper function to simplify the main part. +template<class T> +ostream& operator<<(ostream& os, const vector<T>& v) +{ + copy(v.begin(), v.end(), ostream_iterator<T>(os, " ")); + return os; +} + +int main(int ac, char* av[]) +{ + try { + int opt; + int portnum; + po::options_description desc("Allowed options"); + desc.add_options() + ("help", "produce help message") + ("optimization", po::value<int>(&opt)->default_value(10), + "optimization level") + ("verbose,v", po::value<int>()->implicit_value(1), + "enable verbosity (optionally specify level)") + ("listen,l", po::value<int>(&portnum)->implicit_value(1001) + ->default_value(0,"no"), + "listen on a port.") + ("include-path,I", po::value< vector<string> >(), + "include path") + ("input-file", po::value< vector<string> >(), "input file") + ; + + po::positional_options_description p; + p.add("input-file", -1); + + po::variables_map vm; + po::store(po::command_line_parser(ac, av). + options(desc).positional(p).run(), vm); + po::notify(vm); + + if (vm.count("help")) { + cout << "Usage: options_description [options]\n"; + cout << desc; + return 0; + } + + if (vm.count("include-path")) + { + cout << "Include paths are: " + << vm["include-path"].as< vector<string> >() << "\n"; + } + + if (vm.count("input-file")) + { + cout << "Input files are: " + << vm["input-file"].as< vector<string> >() << "\n"; + } + + if (vm.count("verbose")) { + cout << "Verbosity enabled. Level is " << vm["verbose"].as<int>() + << "\n"; + } + + cout << "Optimization level is " << opt << "\n"; + + cout << "Listen port is " << portnum << "\n"; + } + catch(std::exception& e) + { + cout << e.what() << "\n"; + return 1; + } + return 0; +} |