diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2021-09-07 19:10:52 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2021-09-24 12:39:33 +0300 |
commit | f3d9a26fe6b921ae45b6a4c38713b4ba20754f43 (patch) | |
tree | 92cc95d757589644cfa4e7bf9946469950b210e8 /libbpkg/manifest.hxx | |
parent | d98e538a1b4e9eaa3b8412db59ff4a1c200f3df6 (diff) |
Add string-parsing constructors to dependency, requirement_alternatives, and test_dependency classes
Diffstat (limited to 'libbpkg/manifest.hxx')
-rw-r--r-- | libbpkg/manifest.hxx | 35 |
1 files changed, 34 insertions, 1 deletions
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<version_constraint> constraint; + dependency () = default; + dependency (package_name n, butl::optional<version_constraint> c) + : name (std::move (n)), constraint (std::move (c)) {} + + // Parse the dependency string representation in the + // `<name> [<version-constraint>]` 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 + // `[?] [<requirement> [ '|' <requirement>]*] [; <comment>]` 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<version_constraint> c) : dependency {std::move (n), std::move (c)}, type (t), buildtime (b) {} + // Parse the test dependency string representation in the + // `[*] <name> [<version-constraint>]` form. Throw std::invalid_argument + // if the value is invalid. + // + test_dependency (std::string, test_dependency_type); + inline std::string string () const { |