/
show_args.cc
88 lines (66 loc) · 2.13 KB
/
show_args.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "show_args.hpp"
#include <iostream>
#include <vector>
#include <boost/program_options.hpp>
using namespace std;
namespace po = boost::program_options;
show_args
process_show_args(int argc, char *argv[])
{
show_args result;
try
{
po::options_description opts("Show options");
opts.add_options()
("help,h", "produce help message")
("overload-mean", "show the overload mean")
("overload-sdev", "show the overload standard deviation")
("load-mean", "show the load mean")
("load-sdev", "show the load standard deviation")
("plp-mean", "show the packet loss probability mean")
("plp-sdev", "show the packet loss probability standard deviation")
("file-name", po::value<string>(), "input file");
po::positional_options_description p;
p.add("file-name", -1);
po::variables_map vm;
po::store(po::command_line_parser(argc, argv).
options(opts).positional(p).run(), vm);
po::notify(vm);
if (vm.count("help"))
{
cout << opts << "\n";
exit(0);
}
// True if any of the below was set.
bool any = false;
// Overload
any |= result.overload_mean = vm.count("overload-mean");
any |= result.overload_sdev = vm.count("overload-sdev");
// Load
any |= result.load_mean = vm.count("load-mean");
any |= result.load_sdev = vm.count("load-sdev");
// PLP
any |= result.plp_mean = vm.count("plp-mean");
any |= result.plp_sdev = vm.count("plp-sdev");
// Don't show others is any above was selected.
result.show_others = !any;
// Show all if nothing was selected.
if (!any)
{
result.overload_mean = true;
result.overload_sdev = true;
result.load_mean = true;
result.load_sdev = true;
result.plp_mean = true;
result.plp_sdev = true;
}
if (vm.count("file-name"))
result.file_name = vm["file-name"].as<string>();
}
catch(const std::exception& e)
{
cerr << e.what() << std::endl;
exit(1);
}
return result;
}