From d3f62eb0cbdd6080a26d4e9013bf9f6671cee9d9 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 4 Sep 2015 14:09:51 +0200 Subject: Split manifests into package_manifests and repository_manifests --- bpkg/manifest | 23 ++++++++++++++++----- bpkg/manifest.cxx | 62 ++++++++++++++++++++++++++++++++++--------------------- 2 files changed, 56 insertions(+), 29 deletions(-) (limited to 'bpkg') diff --git a/bpkg/manifest b/bpkg/manifest index 0f03371..d5b036f 100644 --- a/bpkg/manifest +++ b/bpkg/manifest @@ -303,6 +303,19 @@ namespace bpkg serialize (manifest_serializer&) const; }; + class package_manifests: public std::vector + { + public: + using base_type = std::vector; + + using base_type::base_type; + + package_manifests (manifest_parser&); + + void + serialize (manifest_serializer&) const; + }; + class repository_location { public: @@ -425,14 +438,14 @@ namespace bpkg serialize (manifest_serializer&) const; }; - class manifests + class repository_manifests: public std::vector { public: - std::vector repositories; - std::vector packages; + using base_type = std::vector; - public: - manifests (manifest_parser&); + using base_type::base_type; + + repository_manifests (manifest_parser&); void serialize (manifest_serializer&) const; diff --git a/bpkg/manifest.cxx b/bpkg/manifest.cxx index d080fbb..4cbaad5 100644 --- a/bpkg/manifest.cxx +++ b/bpkg/manifest.cxx @@ -773,6 +773,24 @@ namespace bpkg s.next ("", ""); // End of manifest. } + // package_manifests + // + package_manifests:: + package_manifests (parser& p) + { + for (name_value nv (p.next ()); !nv.empty (); nv = p.next ()) + push_back (package_manifest (p, nv)); + } + + void package_manifests:: + serialize (serializer& s) const + { + for (const package_manifest& p: *this) + p.serialize (s); + + s.next ("", ""); // End of stream. + } + // repository_location // // Location parameter type is fully qualified as compiler gets confused with @@ -1089,42 +1107,38 @@ namespace bpkg s.next ("", ""); // End of manifest. } - // manifests + // repository_manifests // - manifests:: - manifests (parser& p) + repository_manifests:: + repository_manifests (parser& p) { - bool rep (true); // Parsing repository list. - - for (name_value nv (p.next ()); !nv.empty (); nv = p.next ()) + name_value nv (p.next ()); + while (!nv.empty ()) { - if (rep) - { - repositories.push_back (repository_manifest (p, nv)); + push_back (repository_manifest (p, nv)); + nv = p.next (); - // 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)); + // Make sure there is location in all except the last entry. + // + if (back ().location.empty () && !nv.empty ()) + throw parsing (p.name (), nv.name_line, nv.name_column, + "repository location expected"); } + + if (empty () || !back ().location.empty ()) + throw parsing (p.name (), nv.name_line, nv.name_column, + "base repository manifest expected"); } - void manifests:: + void repository_manifests:: serialize (serializer& s) const { - if (repositories.empty () || !repositories.back ().location.empty ()) - throw serialization (s.name (), "local repository manifest expected"); + if (empty () || !back ().location.empty ()) + throw serialization (s.name (), "base repository manifest expected"); - for (const repository_manifest& r: repositories) + for (const repository_manifest& r: *this) r.serialize (s); - for (const package_manifest& p: packages) - p.serialize (s); - s.next ("", ""); // End of stream. } } -- cgit v1.1