aboutsummaryrefslogtreecommitdiff
path: root/bpkg/package
blob: 2aa7412d28415a20084a8f30f46da64fd00cac69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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