aboutsummaryrefslogtreecommitdiff
path: root/bpkg/manifest.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-06-11 18:12:09 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-06-11 18:12:09 +0200
commitc552070230c4ad9c92b516c28658b5c74c57e46b (patch)
treebc78a4c9c5c9bfb21539e3e65f713a7f0daa766b /bpkg/manifest.cxx
parent294f8e8d3abebaaa976c7d21248a1a205c869b02 (diff)
Outline of parsing and serialization for manifest object model
Diffstat (limited to 'bpkg/manifest.cxx')
-rw-r--r--bpkg/manifest.cxx79
1 files changed, 79 insertions, 0 deletions
diff --git a/bpkg/manifest.cxx b/bpkg/manifest.cxx
index 40c7a32..befd3c0 100644
--- a/bpkg/manifest.cxx
+++ b/bpkg/manifest.cxx
@@ -4,8 +4,87 @@
#include <bpkg/manifest>
+#include <utility> // move()
+
+#include <bpkg/manifest-parser>
+#include <bpkg/manifest-serializer>
+
using namespace std;
namespace bpkg
{
+ using parser = manifest_parser;
+ using parsing = manifest_parsing;
+ using serializer = manifest_serializer;
+ using name_value = manifest_name_value;
+
+ // manifest
+ //
+ manifest::
+ manifest (parser& p): 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");
+ }
+
+ manifest::
+ 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");
+
+ 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 == "name")
+ name = move (v);
+ // ...
+ else
+ throw parsing (p.name (), nv.value_line, nv.value_column,
+ "unknown name " + n);
+ }
+
+ // Verify all non-optional values were specified.
+ //
+ }
+
+ void manifest::
+ serialize (serializer& s) const
+ {
+ s.next ("", "1"); // Start of manifest.
+ s.next ("name", name);
+ // ...
+ s.next ("", ""); // End of manifest.
+ }
+
+ // manifests
+ //
+ manifests::
+ manifests (parser& p)
+ {
+ for (name_value nv (p.next ()); !nv.empty (); nv = p.next ())
+ push_back (manifest (p, nv));
+ }
+
+ void manifests::
+ serialize (serializer& s) const
+ {
+ for (const manifest& m: *this)
+ m.serialize (s);
+
+ s.next ("", ""); // End of stream.
+ }
}