1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
// file : bpkg/options-types.hxx -*- C++ -*-
// license : MIT; see accompanying LICENSE file
#ifndef BPKG_OPTIONS_TYPES_HXX
#define BPKG_OPTIONS_TYPES_HXX
#include <map>
#include <cassert>
#include <utility> // move()
#include <bpkg/types.hxx>
namespace bpkg
{
using uuid_type = uuid;
enum class auth
{
none,
remote,
all
};
// Qualified options.
//
// An option that uses this type can have its values qualified using the
// <qualifier>:<value> form, for example, '--option foo:bar'. An unqualified
// value that contains a colon can be specified as qualified with an empty
// qualifier, for example, '--option :http://example.org'. Unqualified
// values apply to all the qualifiers in the order specified.
//
// The second template argument is a NULL-terminated list of valid qualifier
// strings, for example:
//
// const char* option_qualifiers[] = {"foo", "bar", nullptr};
//
template <const char* const* Q, typename V>
class qualified_option: public std::map<string, V>
{
public:
using base_type = std::map<string, V>;
template <typename T>
explicit
qualified_option (T v) {this->emplace (string (), V (std::move (v)));}
qualified_option (): qualified_option (V ()) {}
using base_type::operator[];
const V&
operator[] (const string& q) const
{
auto verify = [&q] ()
{
for (const char* const* p (Q); *p != nullptr; ++p)
{
if (q == *p)
return true;
}
return q.empty ();
};
assert (verify ());
typename base_type::const_iterator i (this->find (q));
if (i == this->end ())
i = this->find ("");
assert (i != this->end ());
return i->second;
}
};
extern const char* openssl_commands[3]; // Clang bug requres explicit size.
}
#endif // BPKG_OPTIONS_TYPES_HXX
|