aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2021-12-09 13:10:10 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2021-12-09 13:10:10 +0300
commitfd1818e7cc30a928859a82e910f7c2825e585352 (patch)
tree1986fb7310586b0a54bee7de89e4bc275bfa94f9
parentf01e037f65f4896d65979c5f25a7169ba3d696f9 (diff)
Adjust types for future support of multiple requirements in an alternative
-rw-r--r--libbpkg/manifest.cxx33
-rw-r--r--libbpkg/manifest.hxx23
2 files changed, 49 insertions, 7 deletions
diff --git a/libbpkg/manifest.cxx b/libbpkg/manifest.cxx
index d605176..bbe8749 100644
--- a/libbpkg/manifest.cxx
+++ b/libbpkg/manifest.cxx
@@ -1188,6 +1188,21 @@ namespace bpkg
return serializer::merge_comment (r, comment);
}
+ // requirement_alternative
+ //
+ requirement_alternative::
+ requirement_alternative (const std::string& s)
+ {
+ push_back (s); // @@ DEP
+ }
+
+ string requirement_alternative::
+ string () const
+ {
+ assert (size () == 1); // @@ DEP
+ return front ();
+ }
+
// requirement_alternatives
//
requirement_alternatives::
@@ -1220,7 +1235,7 @@ namespace bpkg
list_parser lp (b, e, '|');
for (string lv (lp.next ()); !lv.empty (); lv = lp.next ())
- push_back (move (lv));
+ push_back (requirement_alternative (lv));
if (empty () && comment.empty ())
throw invalid_argument ("empty package requirement specification");
@@ -1229,10 +1244,18 @@ namespace bpkg
std::string requirement_alternatives::
string () const
{
- return (conditional
- ? (buildtime ? "?* " : "? ")
- : (buildtime ? "* " : "")) +
- serializer::merge_comment (concatenate (*this, " | "), comment);
+ std::string r (conditional
+ ? (buildtime ? "?* " : "? ")
+ : (buildtime ? "* " : ""));
+
+ bool f (true);
+ for (const requirement_alternative& ra: *this)
+ {
+ r += (f ? (f = false, "") : " | ");
+ r += ra.string ();
+ }
+
+ return serializer::merge_comment (r, comment);
}
// build_class_term
diff --git a/libbpkg/manifest.hxx b/libbpkg/manifest.hxx
index ef44fcb..08f8a8e 100644
--- a/libbpkg/manifest.hxx
+++ b/libbpkg/manifest.hxx
@@ -504,7 +504,26 @@ namespace bpkg
// requires
//
- class requirement_alternatives: public butl::small_vector<std::string, 1>
+ class requirement_alternative: public butl::small_vector<std::string, 1>
+ {
+ public:
+ butl::optional<std::string> enable;
+
+ requirement_alternative () = default;
+ requirement_alternative (butl::optional<std::string> e)
+ : enable (std::move (e)) {}
+
+ // Parse the requirement alternative string representation.
+ //
+ explicit LIBBPKG_EXPORT
+ requirement_alternative (const std::string&);
+
+ LIBBPKG_EXPORT std::string
+ string () const;
+ };
+
+ class requirement_alternatives:
+ public butl::small_vector<requirement_alternative, 1>
{
public:
bool conditional;
@@ -517,7 +536,7 @@ namespace bpkg
// Parse the requirement alternatives string representation in the
// `[?] [<requirement> [ '|' <requirement>]*] [; <comment>]` form. Throw
- // std::invalid_argument if the value is invalid.
+ // std::invalid_argument if the value is invalid. @@ DEP @@ TMP update.
//
explicit LIBBPKG_EXPORT
requirement_alternatives (const std::string&);