• 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/multiple_sources.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
/* Shows how to use both command line and config file. */
8

9
#include <hpx/modules/program_options.hpp>
10

11
#include <algorithm>
12
#include <exception>
13
#include <fstream>
14
#include <iostream>
15
#include <iterator>
16
#include <string>
17
#include <vector>
18

19
#include <hpx/config/warnings_prefix.hpp>
20

21
namespace po = hpx::program_options;
22
using namespace std;
23

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

32
int main(int ac, char* av[])
33
{
34
    try
35
    {
36
        int opt;
37
        string config_file;
38

39
        // Declare a group of options that will be
×
40
        // allowed only on command line
41
        po::options_description generic("Generic options");
×
42
        // clang-format off
×
43
        generic.add_options()
×
44
            ("version,v","print version string")
×
45
            ("help", "produce help message")
×
46
            ("config,c",
47
                po::value<string>(&config_file)->default_value(
48
                    "multiple_sources.cfg"),
49
              "name of a file of a configuration.")
50
            ;
51
        // clang-format on
52

53
        // Declare a group of options that will be
54
        // allowed both on command line and in
×
55
        // config file
56
        po::options_description config("Configuration");
×
57
        // clang-format off
×
58
        config.add_options()
59
            ("optimization", po::value<int>(&opt)->default_value(10),
×
60
                "optimization level")
61
            ("include-path,I", po::value<vector<string>>()->composing(),
62
                "include path")
63
            ;
64
        // clang-format on
65

66
        // Hidden options, will be allowed both on command line and
×
67
        // in config file, but will not be shown to the user.
68
        po::options_description hidden("Hidden options");
×
69
        // clang-format off
×
70
        hidden.add_options()
71
            ("input-file", po::value<vector<string>>(), "input file")
72
            ;
73
        // clang-format on
×
74

×
75
        po::options_description cmdline_options;
76
        cmdline_options.add(generic).add(config).add(hidden);
×
77

×
78
        po::options_description config_file_options;
79
        config_file_options.add(config).add(hidden);
×
80

×
81
        po::options_description visible("Allowed options");
82
        visible.add(generic).add(config);
83

×
84
        po::positional_options_description p;
85
        p.add("input-file", -1);
×
86

×
87
        po::variables_map vm;
88
        store(po::command_line_parser(ac, av)
89
                  .allow_unregistered()
90
                  .options(cmdline_options)
×
91
                  .positional(p)
92
                  .run(),
×
93
            vm);
94
        notify(vm);
×
95

×
96
        ifstream ifs(config_file.c_str());
97
        if (!ifs)
×
98
        {
99
            cout << "can not open config file: " << config_file << "\n";
100
            return 0;
101
        }
102
        else
×
103
        {
×
104
            store(parse_config_file(ifs, config_file_options), vm);
105
            notify(vm);
106
        }
×
107

108
        if (vm.count("help"))
×
109
        {
110
            cout << visible << "\n";
111
            return 0;
112
        }
×
113

114
        if (vm.count("version"))
×
115
        {
116
            cout << "Multiple sources example, version 1.0\n";
117
            return 0;
118
        }
×
119

120
        if (vm.count("include-path"))
121
        {
×
122
            cout << "Include paths are: "
123
                 << vm["include-path"].as<vector<string>>() << "\n";
124
        }
×
125

126
        if (vm.count("input-file"))
×
127
        {
×
128
            cout << "Input files are: " << vm["input-file"].as<vector<string>>()
129
                 << "\n";
130
        }
×
131

×
132
        cout << "Optimization level is " << opt << "\n";
×
133
    }
134
    catch (exception const& e)
×
135
    {
136
        cout << e.what() << "\n";
×
137
        return 1;
×
138
    }
139
    return 0;
140
}
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