aboutsummaryrefslogtreecommitdiff
path: root/bpkg/manifest.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-10-01 11:42:15 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-10-01 11:42:15 +0200
commit28caabebc778daa242eb8f188351c42edb93b5cb (patch)
tree710c598a54a88d4ae02718839b51ae100223b0ca /bpkg/manifest.cxx
parent2f80e1bebe371b2b71cc8f1fee4bb9f561e19eb2 (diff)
Minor refactoring/renaming
Diffstat (limited to 'bpkg/manifest.cxx')
-rw-r--r--bpkg/manifest.cxx58
1 files changed, 40 insertions, 18 deletions
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));
}
}