• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

STEllAR-GROUP / hpx / #882

31 Aug 2023 07:44PM UTC coverage: 41.798% (-44.7%) from 86.546%
#882

push

19442 of 46514 relevant lines covered (41.8%)

126375.38 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/libs/core/program_options/examples/options_description.cpp
1
// Copyright Vladimir Prus 2002-2004.
2
//  SPDX-License-Identifier: BSL-1.0
3
// Distributed under the Boost Software License, Version 1.0.
4
// (See accompanying file LICENSE_1_0.txt
5
// or copy at http://www.boost.org/LICENSE_1_0.txt)
6

7
#include <hpx/modules/program_options.hpp>
8

9
#include <algorithm>
10
#include <exception>
11
#include <iostream>
12
#include <iterator>
13
#include <string>
14
#include <vector>
15

16
#include <hpx/config/warnings_prefix.hpp>
17

18
namespace po = hpx::program_options;
19
using namespace std;
20

21
// A helper function to simplify the main part.
22
template <class T>
23
ostream& operator<<(ostream& os, vector<T> const& v)
24
{
25
    copy(v.begin(), v.end(), ostream_iterator<T>(os, " "));
26
    return os;
27
}
×
28

29
int main(int ac, char* av[])
30
{
31
    try
32
    {
33
        int opt;
×
34
        int portnum;
35
        po::options_description desc("Allowed options");
×
36
        // clang-format off
×
37
        desc.add_options()
×
38
            ("help", "produce help message")
39
            ("optimization", po::value<int>(&opt)->default_value(10),
×
40
                  "optimization level")
41
            ("verbose,v", po::value<int>()->implicit_value(1),
×
42
                  "enable verbosity (optionally specify level)")
×
43
            ("listen,l", po::value<int>(&portnum)->implicit_value(1001)
44
                  ->default_value(0,"no"),
×
45
                  "listen on a port.")
46
            ("include-path,I", po::value< vector<string> >(),
×
47
                  "include path")
48
            ("input-file", po::value< vector<string> >(), "input file")
49
        ;
50
        // clang-format on
51

×
52
        po::positional_options_description p;
53
        p.add("input-file", -1);
×
54

×
55
        po::variables_map vm;
56
        po::store(po::command_line_parser(ac, av)
57
                      .allow_unregistered()
58
                      .options(desc)
×
59
                      .positional(p)
60
                      .run(),
×
61
            vm);
62
        po::notify(vm);
×
63

64
        if (vm.count("help"))
×
65
        {
×
66
            cout << "Usage: options_description [options]\n";
67
            cout << desc;
68
            return 0;
69
        }
×
70

71
        if (vm.count("include-path"))
72
        {
×
73
            cout << "Include paths are: "
74
                 << vm["include-path"].as<vector<string>>() << "\n";
75
        }
×
76

77
        if (vm.count("input-file"))
×
78
        {
×
79
            cout << "Input files are: " << vm["input-file"].as<vector<string>>()
80
                 << "\n";
81
        }
×
82

83
        if (vm.count("verbose"))
×
84
        {
×
85
            cout << "Verbosity enabled.  Level is " << vm["verbose"].as<int>()
86
                 << "\n";
87
        }
×
88

×
89
        cout << "Optimization level is " << opt << "\n";
×
90
        cout << "Listen port is " << portnum << "\n";
×
91
    }
92
    catch (std::exception const& e)
×
93
    {
94
        cout << e.what() << "\n";
×
95
        return 1;
×
96
    }
97
    return 0;
98
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc