aboutsummaryrefslogtreecommitdiff
path: root/bpkg/manifest.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-06-16 16:40:31 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-06-16 16:40:31 +0200
commit95c4c20586a56fd8b8d32043d85c20f2c164474d (patch)
tree87a3b8e5dcf312677c3bc89e7eb688f975d8d242 /bpkg/manifest.cxx
parentfc76d626cc9d43f899f46bcf62e6d047abd1f362 (diff)
Rename manifest to package_manifest, add repository_manifest
Diffstat (limited to 'bpkg/manifest.cxx')
-rw-r--r--bpkg/manifest.cxx102
1 files changed, 90 insertions, 12 deletions
diff --git a/bpkg/manifest.cxx b/bpkg/manifest.cxx
index befd3c0..85e4296 100644
--- a/bpkg/manifest.cxx
+++ b/bpkg/manifest.cxx
@@ -16,29 +16,31 @@ namespace bpkg
using parser = manifest_parser;
using parsing = manifest_parsing;
using serializer = manifest_serializer;
+ using serialization = manifest_serialization;
using name_value = manifest_name_value;
- // manifest
+ // package_manifest
//
- manifest::
- manifest (parser& p): manifest (p, p.next ()) // Delegate.
+ package_manifest::
+ package_manifest (parser& p)
+ : package_manifest (p, p.next ()) // Delegate
{
// Make sure this is the end.
//
name_value nv (p.next ());
if (!nv.empty ())
throw parsing (p.name (), nv.name_line, nv.name_column,
- "single manifest expected");
+ "single package manifest expected");
}
- manifest::
- manifest (parser& p, const name_value& s)
+ package_manifest::
+ package_manifest (parser& p, const name_value& s)
{
// Make sure this is the start and we support the version.
//
if (!s.name.empty ())
throw parsing (p.name (), s.name_line, s.name_column,
- "start of manifest expected");
+ "start of package manifest expected");
if (s.value != "1")
throw parsing (p.name (), s.value_line, s.value_column,
@@ -54,14 +56,14 @@ namespace bpkg
// ...
else
throw parsing (p.name (), nv.value_line, nv.value_column,
- "unknown name " + n);
+ "unknown name '" + n + "' in package manifest");
}
// Verify all non-optional values were specified.
//
}
- void manifest::
+ void package_manifest::
serialize (serializer& s) const
{
s.next ("", "1"); // Start of manifest.
@@ -70,20 +72,96 @@ namespace bpkg
s.next ("", ""); // End of manifest.
}
+ // repository_manifest
+ //
+ repository_manifest::
+ repository_manifest (parser& p)
+ : repository_manifest (p, p.next ()) // Delegate
+ {
+ // Make sure this is the end.
+ //
+ name_value nv (p.next ());
+ if (!nv.empty ())
+ throw parsing (p.name (), nv.name_line, nv.name_column,
+ "single repository manifest expected");
+ }
+
+ repository_manifest::
+ repository_manifest (parser& p, const name_value& s)
+ {
+ // Make sure this is the start and we support the version.
+ //
+ if (!s.name.empty ())
+ throw parsing (p.name (), s.name_line, s.name_column,
+ "start of repository manifest expected");
+
+ if (s.value != "1")
+ throw parsing (p.name (), s.value_line, s.value_column,
+ "unsupported format version");
+
+ for (name_value nv (p.next ()); !nv.empty (); nv = p.next ())
+ {
+ string& n (nv.name);
+ string& v (nv.value);
+
+ if (n == "location")
+ location = move (v);
+ else
+ throw parsing (p.name (), nv.value_line, nv.value_column,
+ "unknown name '" + n + "' in repository manifest");
+ }
+
+ // Verify all non-optional values were specified.
+ //
+ // - location can be omitted
+ }
+
+ void repository_manifest::
+ serialize (serializer& s) const
+ {
+ s.next ("", "1"); // Start of manifest.
+
+ if (!location.empty ())
+ s.next ("location", location);
+
+ s.next ("", ""); // End of manifest.
+ }
+
// manifests
//
manifests::
manifests (parser& p)
{
+ bool rep (true); // Parsing repository list.
+
for (name_value nv (p.next ()); !nv.empty (); nv = p.next ())
- push_back (manifest (p, nv));
+ {
+ if (rep)
+ {
+ repositories.push_back (repository_manifest (p, nv));
+
+ // Manifest for local repository signals the end of the
+ // repository list.
+ //
+ if (repositories.back ().location.empty ())
+ rep = false;
+ }
+ else
+ packages.push_back (package_manifest (p, nv));
+ }
}
void manifests::
serialize (serializer& s) const
{
- for (const manifest& m: *this)
- m.serialize (s);
+ if (repositories.empty () || !repositories.back ().location.empty ())
+ throw serialization (s.name (), "local repository manifest expected");
+
+ for (const repository_manifest& r: repositories)
+ r.serialize (s);
+
+ for (const package_manifest& p: packages)
+ p.serialize (s);
s.next ("", ""); // End of stream.
}