aboutsummaryrefslogtreecommitdiff
path: root/brep/package.cxx
blob: 585a0b585f7e0dbecd82c83a5cc268ea04d8721c (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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// file      : brep/package.cxx -*- C++ -*-
// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd
// license   : MIT; see accompanying LICENSE file

#include <brep/package>

#include <utility> // move()
#include <cassert>

#include <odb/database.hxx>

#include <brep/package-odb>

using namespace std;
using namespace odb::core;

namespace brep
{
  // Utility functions
  //
  static inline bool
  alpha (char c)
  {
    return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
  }

  static inline bool
  digit (char c)
  {
    return c >= '0' && c <= '9';
  }

  // package
  //
  package::
  package (string n,
           string s,
           strings t,
           optional<string> d,
           url_type u,
           optional<url_type> pu,
           email_type e,
           optional<email_type> pe)
      : name (move (n)),
        summary (move (s)),
        tags (move (t)),
        description (move (d)),
        url (move (u)),
        package_url (move (pu)),
        email (move (e)),
        package_email (move (pe))
  {
  }

  // package_version
  //
  package_version::
  package_version (lazy_shared_ptr<repository_type> rp,
                   lazy_shared_ptr<package_type> pk,
                   version_type vr,
                   priority_type pr,
                   license_alternatives_type la,
                   string ch,
                   dependencies_type dp,
                   requirements_type rq)
      : repository (move (rp)),
        package (move (pk)),
        version (move (vr)),
        priority (move (pr)),
        license_alternatives (move (la)),
        changes (move (ch)),
        dependencies (move (dp)),
        requirements (move (rq))
  {
  }

  package_version::_id_type package_version::
  _id () const
  {
    return _id_type {
      {
        repository.object_id (),
        package.object_id (),
        version.epoch (),
        version.canonical_upstream ()
      },
      version.upstream (),
      version.revision ()};
  }

  void package_version::
  _id (_id_type&& v, database& db)
  {
    repository = lazy_shared_ptr<repository_type> (db, v.data.repository);
    package = lazy_shared_ptr<package_type> (db, v.data.package);
    version = version_type (v.data.epoch, move (v.upstream), v.revision);
    assert (version.canonical_upstream () == v.data.canonical_upstream);
  }

  // max_package_version
  //
  void max_package_version::
  _id (package_version::_id_type&& v)
  {
    version = version_type (v.data.epoch, move (v.upstream), v.revision);
    assert (version.canonical_upstream () == v.data.canonical_upstream);
  }

  // repository
  //
  repository::
  repository (repository_location l, string d, dir_path p)
      : location (move (l)),
        display_name (move (d)),
        local_path (move (p)),
        internal (true)
  {
  }

  repository::_id_type repository::
  _id () const
  {
    return _id_type {location.canonical_name (), location.string ()};
  }

  void repository::
  _id (_id_type&& l)
  {
    location = repository_location (move (l.location));
    assert (location.canonical_name () == l.canonical_name);
  }
}