aboutsummaryrefslogtreecommitdiff
path: root/bpkg/options-types.hxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2018-10-08 23:01:16 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2018-10-10 23:54:18 +0300
commit61349dcf5fbfeab888ea345ebec3d887777a2782 (patch)
tree958d7f34185d987b21ae24ad137b7a2e0a1593ec /bpkg/options-types.hxx
parenteb58dc7c9ec9877c645585b7fb163d2bcc251b5d (diff)
Add support for openssl qualified options
Diffstat (limited to 'bpkg/options-types.hxx')
-rw-r--r--bpkg/options-types.hxx58
1 files changed, 58 insertions, 0 deletions
diff --git a/bpkg/options-types.hxx b/bpkg/options-types.hxx
index 373ef5e..3438be1 100644
--- a/bpkg/options-types.hxx
+++ b/bpkg/options-types.hxx
@@ -5,6 +5,10 @@
#ifndef BPKG_OPTIONS_TYPES_HXX
#define BPKG_OPTIONS_TYPES_HXX
+#include <map>
+#include <cassert>
+#include <utility> // move()
+
namespace bpkg
{
enum class auth
@@ -13,6 +17,60 @@ namespace bpkg
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* 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 ("", 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** 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[];
}
#endif // BPKG_OPTIONS_TYPES_HXX