aboutsummaryrefslogtreecommitdiff
path: root/bpkg
diff options
context:
space:
mode:
Diffstat (limited to 'bpkg')
-rw-r--r--bpkg/manifest20
-rw-r--r--bpkg/manifest.cxx58
2 files changed, 56 insertions, 22 deletions
diff --git a/bpkg/manifest b/bpkg/manifest
index 17d3190..aab1c91 100644
--- a/bpkg/manifest
+++ b/bpkg/manifest
@@ -227,18 +227,30 @@ namespace bpkg
//
enum class comparison {eq, lt, gt, le, ge};
- struct version_comparison
+ std::string
+ to_string (comparison);
+
+ comparison
+ to_comparison (const std::string&); // May throw invalid_argument.
+
+ inline std::ostream&
+ operator<< (std::ostream& os, comparison c) {return os << to_string (c);}
+
+ struct dependency_condition
{
- version value;
comparison operation;
+ bpkg::version version;
};
struct dependency
{
- std::string package;
- butl::optional<version_comparison> version;
+ std::string name;
+ butl::optional<dependency_condition> condition;
};
+ std::ostream&
+ operator<< (std::ostream&, const dependency&);
+
class dependency_alternatives: public std::vector<dependency>
{
public:
diff --git a/bpkg/manifest.cxx b/bpkg/manifest.cxx
index 5a3357e..122f781 100644
--- a/bpkg/manifest.cxx
+++ b/bpkg/manifest.cxx
@@ -27,6 +27,8 @@ using namespace butl;
namespace bpkg
{
+ using std::to_string; // Add to bpkg::to_string().
+
using parser = manifest_parser;
using parsing = manifest_parsing;
using serializer = manifest_serializer;
@@ -68,22 +70,6 @@ namespace bpkg
return c >= 'A' && c <='Z' ? c + shift : c;
}
- static ostream&
- operator<< (ostream& o, const dependency& d)
- {
- o << d.package;
-
- if (d.version)
- {
- static const char* operations[] = {"==", "<", ">", "<=", ">="};
-
- o << " " << operations[static_cast<size_t> (d.version->operation)]
- << " " << d.version->value.string ();
- }
-
- return o;
- }
-
// Resize v up to ';', return what goes after ';'.
//
inline static string
@@ -345,6 +331,38 @@ namespace bpkg
return v;
}
+ // depends
+ //
+ static const char* comparison_str[] = {"==", "<", ">", "<=", ">="};
+
+ string
+ to_string (comparison c)
+ {
+ return comparison_str[static_cast<size_t> (c)];
+ }
+
+ comparison
+ to_comparison (const string& s)
+ {
+ if (s == "==") return comparison::eq;
+ else if (s == ">" ) return comparison::gt;
+ else if (s == "<" ) return comparison::lt;
+ else if (s == ">=") return comparison::ge;
+ else if (s == "<=") return comparison::le;
+ else throw invalid_argument ("invalid comparion operator '" + s + "'");
+ }
+
+ ostream&
+ operator<< (ostream& o, const dependency& d)
+ {
+ o << d.name;
+
+ if (d.condition)
+ o << " " << d.condition->operation << " " << d.condition->version;
+
+ return o;
+ }
+
// package_manifest
//
package_manifest::
@@ -614,7 +632,7 @@ namespace bpkg
}
if (i == e)
- da.push_back (dependency {lv, optional<version_comparison> ()});
+ da.push_back (dependency {lv, nullopt});
else
{
string nm (b, ne);
@@ -627,6 +645,9 @@ namespace bpkg
const char* op (&*i);
comparison operation;
+ // While we have to_comparison(), using it in this situation
+ // won't save us anything.
+ //
if (strncmp (op, "==", 2) == 0)
{
operation = comparison::eq;
@@ -672,7 +693,8 @@ namespace bpkg
string ("invalid prerequisite package version: ") + e.what ());
}
- dependency d{move (nm), version_comparison {move (v), operation}};
+ dependency d {move (nm),
+ dependency_condition {operation, move (v)}};
da.push_back (move (d));
}
}