From f3d9a26fe6b921ae45b6a4c38713b4ba20754f43 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Tue, 7 Sep 2021 19:10:52 +0300 Subject: Add string-parsing constructors to dependency, requirement_alternatives, and test_dependency classes --- libbpkg/manifest.hxx | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'libbpkg/manifest.hxx') diff --git a/libbpkg/manifest.hxx b/libbpkg/manifest.hxx index 1b62512..b6b9217 100644 --- a/libbpkg/manifest.hxx +++ b/libbpkg/manifest.hxx @@ -395,6 +395,17 @@ namespace bpkg package_name name; butl::optional constraint; + dependency () = default; + dependency (package_name n, butl::optional c) + : name (std::move (n)), constraint (std::move (c)) {} + + // Parse the dependency string representation in the + // ` []` form. Throw std::invalid_argument if + // the value is invalid. + // + explicit + dependency (std::string); + std::string string () const; }; @@ -434,8 +445,24 @@ namespace bpkg requirement_alternatives () = default; requirement_alternatives (bool d, bool b, std::string c) : conditional (d), buildtime (b), comment (std::move (c)) {} + + // Parse the requirement alternatives string representation in the + // `[?] [ [ '|' ]*] [; ]` form. Throw + // std::invalid_argument if the value is invalid. + // + explicit LIBBPKG_EXPORT + requirement_alternatives (const std::string&); + + LIBBPKG_EXPORT std::string + string () const; }; + inline std::ostream& + operator<< (std::ostream& os, const requirement_alternatives& ra) + { + return os << ra.string (); + } + class build_constraint { public: @@ -691,7 +718,7 @@ namespace bpkg return os << to_string (t); } - struct test_dependency: dependency + struct LIBBPKG_EXPORT test_dependency: dependency { test_dependency_type type; bool buildtime; @@ -703,6 +730,12 @@ namespace bpkg butl::optional c) : dependency {std::move (n), std::move (c)}, type (t), buildtime (b) {} + // Parse the test dependency string representation in the + // `[*] []` form. Throw std::invalid_argument + // if the value is invalid. + // + test_dependency (std::string, test_dependency_type); + inline std::string string () const { -- cgit v1.1