Arbiter
Dependency manager library that supports decentralization
Resolver.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/Resolver.h>
8 
9 #include "Dependency.h"
10 #include "Graph.h"
11 #include "Types.h"
12 #include "Version.h"
13 
14 #include <memory>
15 #include <unordered_map>
16 #include <vector>
17 
18 struct ArbiterResolver final : public Arbiter::Base
19 {
20  public:
21  std::shared_ptr<const void> _context;
22 
23  ArbiterResolver (ArbiterResolverBehaviors behaviors, ArbiterDependencyList dependencyList, std::shared_ptr<const void> context)
24  : _context(std::move(context))
25  , _behaviors(std::move(behaviors))
26  , _dependencyList(std::move(dependencyList))
27  {
28  assert(_behaviors.createDependencyList);
29  assert(_behaviors.createAvailableVersionsList);
30  }
31 
32  ArbiterResolver (const ArbiterResolver &) = delete;
33  ArbiterResolver &operator= (const ArbiterResolver &) = delete;
34 
35  /**
36  * Fetches the list of dependencies for the given project and version.
37  *
38  * Returns the dependency list or throws an exception.
39  */
40  ArbiterDependencyList fetchDependencies (const ArbiterProjectIdentifier &project, const ArbiterSelectedVersion &version) noexcept(false);
41 
42  /**
43  * Fetches the list of available versions for the given project.
44  *
45  * Returns the version list or throws an exception.
46  */
47  ArbiterSelectedVersionList fetchAvailableVersions (const ArbiterProjectIdentifier &project) noexcept(false);
48 
49  /**
50  * Fetches a selected version for the given metadata string.
51  *
52  * Returns the selected version if found, or else None.
53  */
54  Arbiter::Optional<ArbiterSelectedVersion> fetchSelectedVersionForMetadata (const Arbiter::SharedUserValue<ArbiterSelectedVersion> &metadata);
55 
56  /**
57  * Computes a list of available versions for the specified project which
58  * satisfy the given requirement.
59  */
60  std::vector<ArbiterSelectedVersion> availableVersionsSatisfying (const ArbiterProjectIdentifier &project, const ArbiterRequirement &requirement) noexcept(false);
61 
62  /**
63  * Attempts to resolve all dependencies.
64  */
65  ArbiterResolvedDependencyGraph resolve () noexcept(false);
66 
67  std::unique_ptr<Arbiter::Base> clone () const override;
68  std::ostream &describe (std::ostream &os) const override;
69  bool operator== (const Arbiter::Base &other) const override;
70 
71  private:
72  const ArbiterResolverBehaviors _behaviors;
73  const ArbiterDependencyList _dependencyList;
74 
75  std::unordered_map<ArbiterResolvedDependency, ArbiterDependencyList> _cachedDependencies;
76  std::unordered_map<ArbiterProjectIdentifier, ArbiterSelectedVersionList> _cachedAvailableVersions;
77 };
ArbiterResolver(const ArbiterResolver &)=delete
auto makeIteratorRange(const Collection &collection)
Creates an IteratorRange encompassing the entirety of the given read-only collection.
Definition: Iterator.h:45
ArbiterResolver(ArbiterResolverBehaviors behaviors, ArbiterDependencyList dependencyList, std::shared_ptr< const void > context)
Definition: Resolver.h:23
std::ostream & describe(std::ostream &os) const override
Arbiter::Optional< ArbiterSelectedVersion > fetchSelectedVersionForMetadata(const Arbiter::SharedUserValue< ArbiterSelectedVersion > &metadata)
Fetches a selected version for the given metadata string.
ArbiterDependencyList fetchDependencies(const ArbiterProjectIdentifier &project, const ArbiterSelectedVersion &version) noexcept(false)
Fetches the list of dependencies for the given project and version.
ArbiterResolver & operator=(const ArbiterResolver &)=delete
std::vector< ArbiterSelectedVersion > availableVersionsSatisfying(const ArbiterProjectIdentifier &project, const ArbiterRequirement &requirement) noexcept(false)
Computes a list of available versions for the specified project which satisfy the given requirement...
ArbiterResolvedDependencyGraph resolve() noexcept(false)
Attempts to resolve all dependencies.
std::unique_ptr< Arbiter::Base > clone() const override
ArbiterDependencyList(const ArbiterDependencyList &)=default
bool operator==(const Arbiter::Base &other) const override
std::shared_ptr< const void > _context
Definition: Resolver.h:21
ArbiterSelectedVersionList fetchAvailableVersions(const ArbiterProjectIdentifier &project) noexcept(false)
Fetches the list of available versions for the given project.
virtual std::unique_ptr< Base > clone() const =0
size_t hash() const
Definition: Value.h:96