From fd1818e7cc30a928859a82e910f7c2825e585352 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 9 Dec 2021 13:10:10 +0300 Subject: Adjust types for future support of multiple requirements in an alternative --- libbpkg/manifest.cxx | 33 ++++++++++++++++++++++++++++----- libbpkg/manifest.hxx | 23 +++++++++++++++++++++-- 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 + class requirement_alternative: public butl::small_vector + { + public: + butl::optional enable; + + requirement_alternative () = default; + requirement_alternative (butl::optional 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 { public: bool conditional; @@ -517,7 +536,7 @@ namespace bpkg // Parse the requirement alternatives string representation in the // `[?] [ [ '|' ]*] [; ]` 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&); -- cgit v1.1