aboutsummaryrefslogtreecommitdiff
path: root/bpkg/package
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-09-14 15:12:32 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-09-14 15:12:32 +0200
commitd05f9f046565f2d0d4135912103f96f0e66b454f (patch)
tree750c05a010e886de83edc30282476cc36cc1c127 /bpkg/package
parentf9b9844eabe29250298f8120fa32a3b98c718454 (diff)
Add initial database model
Diffstat (limited to 'bpkg/package')
-rw-r--r--bpkg/package94
1 files changed, 94 insertions, 0 deletions
diff --git a/bpkg/package b/bpkg/package
new file mode 100644
index 0000000..2aa7412
--- /dev/null
+++ b/bpkg/package
@@ -0,0 +1,94 @@
+// file : bpkg/package -*- C++ -*-
+// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+#ifndef BPKG_PACKAGE
+#define BPKG_PACKAGE
+
+#include <memory> // shared_ptr
+#include <cstdint> // uint16
+#include <ostream>
+#include <utility> // move()
+
+#include <odb/core.hxx>
+
+#include <bpkg/types>
+
+#pragma db model version(1, 1, open)
+
+namespace bpkg
+{
+ // Use an image type to map version to the database since there
+ // is no way to modify individual components directly.
+ //
+ #pragma db value
+ struct _version
+ {
+ std::uint16_t epoch;
+ std::string upstream;
+ std::uint16_t revision;
+ std::string canonical_upstream;
+ };
+}
+
+#include <bpkg/manifest>
+
+namespace bpkg
+{
+ // version
+ //
+ #pragma db map type(version) as(_version) \
+ to(bpkg::_version{(?).epoch (), \
+ (?).upstream (), \
+ (?).revision (), \
+ (?).canonical_upstream ()}) \
+ from(bpkg::version ((?).epoch, std::move ((?).upstream), (?).revision))
+
+ // state
+ //
+ enum class state
+ {
+ fetched,
+ unpacked,
+ configured,
+ updated,
+ broken
+ };
+
+ string
+ to_string (state);
+
+ state
+ from_string (const string&); // May throw invalid_argument.
+
+ inline std::ostream&
+ operator<< (std::ostream& os, state s) {return os << to_string (s);}
+
+ #pragma db map type(state) as(string) \
+ to(to_string (?)) \
+ from(bpkg::from_string (?))
+
+ // package
+ //
+ #pragma db object pointer(std::shared_ptr)
+ class package
+ {
+ public:
+ using version_type = bpkg::version;
+ using state_type = bpkg::state;
+
+ string name;
+ version_type version;
+ state_type state;
+
+ // Database mapping.
+ //
+ #pragma db member(name) id
+
+ private:
+ friend class odb::access;
+ package () = default;
+ };
+}
+
+#endif // BPKG_PACKAGE