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

STEllAR-GROUP / hpx / #856

28 Dec 2022 02:00AM UTC coverage: 86.602% (+0.05%) from 86.55%
#856

push

StellarBot
Merge #6119

6119: Update CMakeLists.txt r=hkaiser a=khuck

updating the default APEX version


Co-authored-by: Kevin Huck <khuck@cs.uoregon.edu>

174566 of 201573 relevant lines covered (86.6%)

1876093.78 hits per line

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

93.83
/libs/core/program_options/src/parsers.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/program_options/config.hpp>
8
#include <hpx/debugging/environ.hpp>
9
#include <hpx/program_options/detail/cmdline.hpp>
10
#include <hpx/program_options/detail/config_file.hpp>
11
#include <hpx/program_options/detail/convert.hpp>
12
#include <hpx/program_options/environment_iterator.hpp>
13
#include <hpx/program_options/options_description.hpp>
14
#include <hpx/program_options/parsers.hpp>
15
#include <hpx/program_options/positional_options.hpp>
16

17
#include <algorithm>
18
#include <cctype>
19
#include <fstream>
20
#include <functional>
21
#include <memory>
22
#include <set>
23
#include <string>
24
#include <utility>
25
#include <vector>
26

27
#ifdef _WIN32
28
#include <stdlib.h>
29
#else
30
#include <unistd.h>
31
#endif
32

33
namespace hpx::program_options {
34

35
    namespace {
36

37
        inline woption woption_from_option(option const& opt)
8✔
38
        {
39
            woption result;
8✔
40
            result.string_key = opt.string_key;
8✔
41
            result.position_key = opt.position_key;
8✔
42
            result.unregistered = opt.unregistered;
8✔
43

44
            std::transform(opt.value.begin(), opt.value.end(),
16✔
45
                back_inserter(result.value),
8✔
46
                std::bind(from_utf8, std::placeholders::_1));
8✔
47

48
            std::transform(opt.original_tokens.begin(),
16✔
49
                opt.original_tokens.end(),
8✔
50
                back_inserter(result.original_tokens),
8✔
51
                std::bind(from_utf8, std::placeholders::_1));
8✔
52
            return result;
8✔
53
        }
8✔
54
    }    // namespace
55

56
    basic_parsed_options<wchar_t>::basic_parsed_options(
4✔
57
        parsed_options const& po)
58
      : description(po.description)
4✔
59
      , utf8_encoded_options(po)
4✔
60
      , m_options_prefix(po.m_options_prefix)
4✔
61
    {
62
        for (auto const& option : po.options)
12✔
63
            options.push_back(woption_from_option(option));
8✔
64
    }
4✔
65

66
    template <typename Char>
67
    basic_parsed_options<Char> parse_config_file(std::basic_istream<Char>& is,
7✔
68
        options_description const& desc, bool allow_unregistered)
69
    {
70
        std::set<std::string> allowed_options;
7✔
71

72
        std::vector<std::shared_ptr<option_description>> const& options =
7✔
73
            desc.options();
7✔
74
        for (auto const& option : options)
57✔
75
        {
76
            option_description const& d = *option;
50✔
77

78
            if (d.long_name().empty())
50✔
79
                throw error("abbreviated option names are not permitted in "
×
80
                            "options configuration files");
81

82
            allowed_options.insert(d.long_name());
50✔
83
        }
84

85
        // Parser return char strings
86
        parsed_options result(&desc);
7✔
87
        std::copy(detail::basic_config_file_iterator<Char>(
14✔
88
                      is, allowed_options, allow_unregistered),
7✔
89
            detail::basic_config_file_iterator<Char>(),
7✔
90
            back_inserter(result.options));
7✔
91

92
        // Convert char strings into desired type.
93
        return basic_parsed_options<Char>(result);
7✔
94
    }
7✔
95

96
    template HPX_CORE_EXPORT basic_parsed_options<char> parse_config_file(
97
        std::basic_istream<char>& is, options_description const& desc,
98
        bool allow_unregistered);
99

100
    template HPX_CORE_EXPORT basic_parsed_options<wchar_t> parse_config_file(
101
        std::basic_istream<wchar_t>& is, options_description const& desc,
102
        bool allow_unregistered);
103

104
    template <typename Char>
105
    basic_parsed_options<Char> parse_config_file(char const* filename,
2✔
106
        options_description const& desc, bool allow_unregistered)
107
    {
108
        // Parser return char strings
109
        std::basic_ifstream<Char> strm(filename);
2✔
110
        if (!strm)
2✔
111
        {
112
            throw reading_file(filename);
×
113
        }
114

115
        basic_parsed_options<Char> result =
2✔
116
            parse_config_file(strm, desc, allow_unregistered);
2✔
117

118
        if (strm.bad())
2✔
119
        {
120
            throw reading_file(filename);
×
121
        }
122

123
        return result;
2✔
124
    }
2✔
125

126
    template HPX_CORE_EXPORT basic_parsed_options<char> parse_config_file(
127
        char const* filename, options_description const& desc,
128
        bool allow_unregistered);
129

130
    template HPX_CORE_EXPORT basic_parsed_options<wchar_t> parse_config_file(
131
        char const* filename, options_description const& desc,
132
        bool allow_unregistered);
133

134
    parsed_options parse_environment(options_description const& desc,
3✔
135
        std::function<std::string(std::string)> const& name_mapper)
136
    {
137
        parsed_options result(&desc);
3✔
138

139
#if defined(__FreeBSD__)
140
        char** env = freebsd_environ;
141
#else
142
        char** env = environ;
3✔
143
#endif
144
        for (environment_iterator i(env), e; i != e; ++i)
1,132✔
145
        {
146
            std::string option_name = name_mapper(i->first);
1,129✔
147

148
            if (!option_name.empty())
1,129✔
149
            {
150
                option n;
3✔
151
                n.string_key = HPX_MOVE(option_name);
3✔
152
                n.value.push_back(i->second);
3✔
153
                result.options.push_back(n);
3✔
154
            }
3✔
155
        }
1,129✔
156

157
        return result;
3✔
158
    }
3✔
159

160
    namespace detail {
161

162
        class prefix_name_mapper
3✔
163
        {
164
        public:
165
            explicit prefix_name_mapper(std::string const& prefix)
1✔
166
              : prefix(prefix)
1✔
167
            {
168
            }
1✔
169

170
            std::string operator()(std::string const& s)
377✔
171
            {
172
                std::string result;
377✔
173
                if (s.find(prefix) == 0)
377✔
174
                {
175
                    for (std::string::size_type n = prefix.size(); n < s.size();
4✔
176
                         ++n)
3✔
177
                    {
178
                        // Intel-Win-7.1 does not understand
179
                        // push_back on string.
180
                        result += static_cast<char>(tolower(s[n]));
3✔
181
                    }
3✔
182
                }
1✔
183
                return result;
377✔
184
            }
377✔
185

186
        private:
187
            std::string prefix;
188
        };
189
    }    // namespace detail
190

191
    parsed_options parse_environment(
1✔
192
        options_description const& desc, std::string const& prefix)
193
    {
194
        return parse_environment(desc, detail::prefix_name_mapper(prefix));
1✔
195
    }
×
196

197
    parsed_options parse_environment(
1✔
198
        options_description const& desc, char const* prefix)
199
    {
200
        return parse_environment(desc, std::string(prefix));
1✔
201
    }
×
202
}    // namespace hpx::program_options
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