• 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/real.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 <iostream>
10
#include <stdexcept>
11
#include <string>
12

13
#include <hpx/config/warnings_prefix.hpp>
14

15
using namespace hpx::program_options;
16
using namespace std;
17

18
/* Auxiliary functions for checking input for validity. */
19

20
/* Function used to check that 'opt1' and 'opt2' are not specified
×
21
   at the same time. */
22
void conflicting_options(
23
    variables_map const& vm, char const* opt1, char const* opt2)
×
24
{
×
25
    if (vm.count(opt1) && !vm[opt1].defaulted() && vm.count(opt2) &&
26
        !vm[opt2].defaulted())
×
27
    {
×
28
        throw logic_error(
29
            string("Conflicting options '") + opt1 + "' and '" + opt2 + "'.");
×
30
    }
31
}
32

33
/* Function used to check that of 'for_what' is specified, then
×
34
   'required_option' is specified too. */
35
void option_dependency(
36
    variables_map const& vm, char const* for_what, char const* required_option)
×
37
{
38
    if (vm.count(for_what) && !vm[for_what].defaulted())
×
39
    {
40
        if (vm.count(required_option) == 0 || vm[required_option].defaulted())
×
41
        {
×
42
            throw logic_error(string("Option '") + for_what +
43
                "' requires option '" + required_option + "'.");
44
        }
×
45
    }
46
}
×
47

48
int main(int argc, char* argv[])
49
{
50
    try
51
    {
52
        string ofile;
×
53
        string macrofile, libmakfile;
×
54
        bool t_given = false;
55
        bool b_given = false;
×
56
        string mainpackage;
×
57
        string depends = "deps_file";
×
58
        string sources = "src_file";
59
        string root = ".";
×
60

61
        options_description desc("Allowed options");
×
62
        // clang-format off
63
        desc.add_options()
64
        // First parameter describes option name/short name
65
        // The second is parameter to option
×
66
        // The third is description
×
67
            ("help,h", "print usage message")
×
68
            ("output,o", value(&ofile), "pathname for output")
×
69
            ("macrofile,m", value(&macrofile), "full pathname of macro.h")
×
70
            ("two,t", bool_switch(&t_given), "preprocess both header and body")
71
            ("body,b", bool_switch(&b_given),
×
72
                "preprocess body in the header context")
73
            ("libmakfile,l", value(&libmakfile),
×
74
                "write include makefile for library")
75
            ("mainpackage,p", value(&mainpackage),
×
76
                "output dependency information")
77
            ("depends,d", value(&depends),
×
78
                "write dependencies to <pathname>")
79
            ("sources,s", value(&sources),
×
80
                "write source package list to <pathname>")
81
            ("root,r", value(&root), "treat <dirname> as project root directory")
82
        ;
83
        // clang-format on
×
84

×
85
        variables_map vm;
86
        store(parse_command_line(argc, argv, desc), vm);
×
87

88
        if (vm.count("help"))
×
89
        {
90
            cout << desc << "\n";
91
            return 0;
92
        }
×
93

×
94
        conflicting_options(vm, "output", "two");
×
95
        conflicting_options(vm, "output", "body");
×
96
        conflicting_options(vm, "output", "mainpackage");
×
97
        conflicting_options(vm, "two", "mainpackage");
98
        conflicting_options(vm, "body", "mainpackage");
×
99

×
100
        conflicting_options(vm, "two", "body");
×
101
        conflicting_options(vm, "libmakfile", "mainpackage");
102
        conflicting_options(vm, "libmakfile", "mainpackage");
×
103

×
104
        option_dependency(vm, "depends", "mainpackage");
×
105
        option_dependency(vm, "sources", "mainpackage");
106
        option_dependency(vm, "root", "mainpackage");
×
107

×
108
        cout << "two = " << vm["two"].as<bool>() << "\n";
×
109
    }
110
    catch (exception const& e)
×
111
    {
×
112
        cerr << e.what() << "\n";
113
    }
114
    return 0;
115
}
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