]> git.proxmox.com Git - ceph.git/blob - ceph/src/seastar/include/seastar/util/program-options.hh
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / seastar / include / seastar / util / 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) 2017 ScyllaDB
20 */
21
22 #pragma once
23
24 #include <seastar/core/sstring.hh>
25
26 #include <boost/any.hpp>
27 #include <boost/program_options.hpp>
28
29 #include <string>
30 #include <unordered_map>
31 #include <vector>
32
33 namespace seastar {
34
35 namespace program_options {
36
37 ///
38 /// \brief Wrapper for command-line options with arbitrary string associations.
39 ///
40 /// This type, to be used with Boost.Program_options, will result in an option that stores an arbitrary number of
41 /// string associations.
42 ///
43 /// Values are specified in the form "key0=value0:[key1=value1:...]". Options of this type can be specified multiple
44 /// times, and the values will be merged (with the last-provided value for a key taking precedence).
45 ///
46 /// \note We need a distinct type (rather than a simple type alias) for overload resolution in the implementation, but
47 /// advertizing our inheritance of \c std::unordered_map would introduce the possibility of memory leaks since STL
48 /// containers do not declare virtual destructors.
49 ///
50 class string_map final : private std::unordered_map<sstring, sstring> {
51 private:
52 using base = std::unordered_map<sstring, sstring>;
53 public:
54 using base::value_type;
55 using base::key_type;
56 using base::mapped_type;
57
58 using base::base;
59 using base::at;
60 using base::find;
61 using base::count;
62 using base::emplace;
63 using base::clear;
64 using base::operator[];
65 using base::begin;
66 using base::end;
67
68 friend bool operator==(const string_map&, const string_map&);
69 friend bool operator!=(const string_map&, const string_map&);
70 };
71
72 inline bool operator==(const string_map& lhs, const string_map& rhs) {
73 return static_cast<const string_map::base&>(lhs) == static_cast<const string_map::base&>(rhs);
74 }
75
76 inline bool operator!=(const string_map& lhs, const string_map& rhs) {
77 return !(lhs == rhs);
78 }
79
80 ///
81 /// \brief Query the value of a key in a \c string_map, or a default value if the key doesn't exist.
82 ///
83 sstring get_or_default(const string_map&, const sstring& key, const sstring& def = sstring());
84
85 std::istream& operator>>(std::istream& is, string_map&);
86 std::ostream& operator<<(std::ostream& os, const string_map&);
87
88 /// \cond internal
89
90 //
91 // Required implementation hook for Boost.Program_options.
92 //
93 void validate(boost::any& out, const std::vector<std::string>& in, string_map*, int);
94
95 /// \endcond
96
97 }
98
99 }