Arbiter
Dependency manager library that supports decentralization
Dependency.h
Go to the documentation of this file.
1 #pragma once
2 
3 #ifndef __cplusplus
4 #error "This file must be compiled as C++."
5 #endif
6 
7 #include <arbiter/Dependency.h>
8 
9 #include "Optional.h"
10 #include "Requirement.h"
11 #include "Types.h"
12 #include "Value.h"
13 #include "Version.h"
14 
15 #include <functional>
16 #include <memory>
17 #include <ostream>
18 #include <set>
19 #include <unordered_set>
20 #include <unordered_map>
21 #include <vector>
22 
23 struct ArbiterProjectIdentifier final : public Arbiter::Base
24 {
25  public:
26  using Value = Arbiter::SharedUserValue<ArbiterProjectIdentifier>;
27 
28  Value _value;
29 
31  {}
32 
33  explicit ArbiterProjectIdentifier (Value value)
34  : _value(std::move(value))
35  {}
36 
37  std::unique_ptr<Arbiter::Base> clone () const override;
38  std::ostream &describe (std::ostream &os) const override;
39  bool operator== (const Arbiter::Base &other) const override;
40 
41  bool operator< (const ArbiterProjectIdentifier &other) const
42  {
43  return _value < other._value;
44  }
45 };
46 
47 struct ArbiterDependency final : public Arbiter::Base
48 {
49  public:
50  ArbiterProjectIdentifier _projectIdentifier;
51 
52  ArbiterDependency (ArbiterProjectIdentifier projectIdentifier, const ArbiterRequirement &requirement);
53 
56  {}
57 
59 
60  const ArbiterRequirement &requirement() const noexcept
61  {
62  return *_requirement;
63  }
64 
66  std::ostream &describe (std::ostream &os) const override;
67  bool operator== (const Arbiter::Base &other) const override;
68 
69  bool operator< (const ArbiterDependency &other) const
70  {
71  return _projectIdentifier < other._projectIdentifier;
72  }
73 
74  private:
75  std::unique_ptr<ArbiterRequirement> _requirement;
76 };
77 
78 struct ArbiterDependencyList final : public Arbiter::Base
79 {
80  public:
81  std::vector<ArbiterDependency> _dependencies;
82 
83  ArbiterDependencyList () = default;
84 
85  explicit ArbiterDependencyList (std::vector<ArbiterDependency> dependencies)
86  : _dependencies(std::move(dependencies))
87  {}
88 
89  ArbiterDependencyList (const ArbiterDependencyList &) = default;
90  ArbiterDependencyList &operator= (const ArbiterDependencyList &) = default;
91 
92  ArbiterDependencyList (ArbiterDependencyList &&) = default;
93  ArbiterDependencyList &operator= (ArbiterDependencyList &&) = default;
94 
95  std::unique_ptr<Arbiter::Base> clone () const override;
96  std::ostream &describe (std::ostream &os) const override;
97  bool operator== (const Arbiter::Base &other) const override;
98 };
99 
100 struct ArbiterResolvedDependency final : public Arbiter::Base
101 {
102  public:
103  ArbiterProjectIdentifier _project;
104  ArbiterSelectedVersion _version;
105 
106  ArbiterResolvedDependency (ArbiterProjectIdentifier project, ArbiterSelectedVersion version)
107  : _project(std::move(project))
108  , _version(std::move(version))
109  {}
110 
111  std::unique_ptr<Arbiter::Base> clone () const override;
112  std::ostream &describe (std::ostream &os) const override;
113  bool operator== (const Arbiter::Base &other) const override;
114 
115  bool operator< (const ArbiterResolvedDependency &other) const;
116 };
117 
118 namespace std {
119 
120 template<>
121 struct hash<ArbiterProjectIdentifier> final
122 {
123  public:
124  size_t operator() (const ArbiterProjectIdentifier &project) const;
125 };
126 
127 template<>
128 struct hash<ArbiterDependency> final
129 {
130  public:
131  size_t operator() (const ArbiterDependency &dependency) const;
132 };
133 
134 template<>
135 struct hash<ArbiterResolvedDependency> final
136 {
137  public:
138  size_t operator() (const ArbiterResolvedDependency &dependency) const;
139 };
140 
141 } // namespace std
std::unique_ptr< Arbiter::Base > clone() const override
ArbiterDependencyList & operator=(const ArbiterDependencyList &)=default
const ArbiterRequirement & requirement() const noexcept
Definition: Dependency.h:60
ArbiterDependency(ArbiterProjectIdentifier projectIdentifier, const ArbiterRequirement &requirement)
auto makeIteratorRange(const Collection &collection)
Creates an IteratorRange encompassing the entirety of the given read-only collection.
Definition: Iterator.h:45
ArbiterProjectIdentifier(Value value)
Definition: Dependency.h:33
ArbiterDependency(const ArbiterDependency &other)
Definition: Dependency.h:54
std::unique_ptr< Arbiter::Base > clone() const override
bool operator==(const Arbiter::Base &other) const override
std::unique_ptr< Arbiter::Base > clone() const override
std::vector< ArbiterDependency > _dependencies
Definition: Dependency.h:81
ArbiterDependencyList & operator=(ArbiterDependencyList &&)=default
size_t operator()(const ArbiterProjectIdentifier &project) const
std::ostream & describe(std::ostream &os) const override
ArbiterDependencyList(std::vector< ArbiterDependency > dependencies)
Definition: Dependency.h:85
size_t operator()(const ArbiterResolvedDependency &dependency) const
ArbiterResolvedDependency(ArbiterProjectIdentifier project, ArbiterSelectedVersion version)
Definition: Dependency.h:106
std::ostream & describe(std::ostream &os) const override
std::ostream & describe(std::ostream &os) const override
bool operator==(const Arbiter::Base &other) const override
ArbiterDependencyList()=default
ArbiterDependencyList(ArbiterDependencyList &&)=default
ArbiterDependency & operator=(const ArbiterDependency &other)
ArbiterProjectIdentifier _projectIdentifier
Definition: Dependency.h:50
ArbiterDependencyList(const ArbiterDependencyList &)=default
bool operator==(const Arbiter::Base &other) const override
ArbiterSelectedVersion _version
Definition: Dependency.h:104
bool operator==(const Arbiter::Base &other) const override
size_t operator()(const ArbiterDependency &dependency) const
std::ostream & describe(std::ostream &os) const override
virtual std::unique_ptr< Base > clone() const =0
std::unique_ptr< Arbiter::Base > clone() const override
ArbiterProjectIdentifier _project
Definition: Dependency.h:103
size_t hash() const
Definition: Value.h:96