]> git.proxmox.com Git - ceph.git/blob - ceph/src/seastar/src/core/program_options.hh
import quincy beta 17.1.0
[ceph.git] / ceph / src / seastar / src / core / program_options.hh
1 /*
2 * This file is open source software, licensed to you under the terms
3 * of the Apache License, Version 2.0 (the "License"). See the NOTICE file
4 * distributed with this work for additional information regarding copyright
5 * ownership. You may not use this file except in compliance with the License.
6 *
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
16 * under the License.
17 */
18 /*
19 * Copyright (C) 2021 Cloudius Systems, Ltd.
20 */
21
22 #include <seastar/util/program-options.hh>
23
24 #include <stack>
25
26 namespace bpo = boost::program_options;
27
28 namespace seastar::program_options {
29
30 /// \cond internal
31
32 class options_description_building_visitor : public options_descriptor {
33 public:
34 struct group_metadata {
35 const std::string& name;
36 bpo::options_description description;
37 bool used;
38 size_t values = 0;
39 };
40 struct value_metadata {
41 const std::string& name;
42 const std::string& description;
43 };
44
45 private:
46 std::stack<group_metadata> _groups;
47 std::optional<value_metadata> _current_metadata;
48
49 public:
50 virtual bool visit_group_start(const std::string& name, bool used) override;
51 virtual void visit_group_end() override;
52
53 virtual bool visit_value_metadata(const std::string& name, const std::string& description, bool used) override;
54
55 virtual void visit_value() override;
56 virtual void visit_value(const bool* default_value) override;
57 virtual void visit_value(const int* default_value) override;
58 virtual void visit_value(const unsigned* default_value) override;
59 virtual void visit_value(const float* default_value) override;
60 virtual void visit_value(const double* default_value) override;
61 virtual void visit_value(const std::string* default_value) override;
62 virtual void visit_value(const std::set<unsigned>*) override;
63 virtual void visit_value(const memory::alloc_failure_kind* default_value) override;
64 virtual void visit_value(const log_level* default_value) override;
65 virtual void visit_value(const logger_timestamp_style* default_value) override;
66 virtual void visit_value(const logger_ostream_type* default_value) override;
67 virtual void visit_value(const std::unordered_map<sstring, log_level>*) override;
68 virtual void visit_selection_value(const std::vector<std::string>&, const std::size_t*) override;
69
70 bpo::options_description get_options_description() && { return std::move(_groups.top().description); }
71 };
72
73 class variables_map_extracting_visitor : public options_mutator {
74 const bpo::variables_map& _values;
75 const std::string* _current_name = nullptr;
76 public:
77 explicit variables_map_extracting_visitor(const bpo::variables_map& values);
78
79 virtual bool visit_group_start(const std::string& name, bool used) override;
80 virtual void visit_group_end() override;
81
82 virtual bool visit_value_metadata(const std::string& name, bool used) override;
83
84 virtual bool visit_value() override;
85 virtual bool visit_value(bool&) override;
86 virtual bool visit_value(int&) override;
87 virtual bool visit_value(unsigned&) override;
88 virtual bool visit_value(float&) override;
89 virtual bool visit_value(double&) override;
90 virtual bool visit_value(std::string&) override;
91 virtual bool visit_value(std::set<unsigned>&) override;
92 virtual bool visit_value(log_level&) override;
93 virtual bool visit_value(logger_timestamp_style&) override;
94 virtual bool visit_value(logger_ostream_type&) override;
95 virtual bool visit_value(memory::alloc_failure_kind&) override;
96 virtual bool visit_value(std::unordered_map<sstring, log_level>&) override;
97
98 virtual bool visit_selection_value(const std::vector<std::string>&, std::size_t& selected_candidate) override;
99 };
100
101 /// \endcond
102
103 } // namespace seastar::program_options