Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
outputs-spec.hh
Go to the documentation of this file.
1#pragma once
3
4#include <cassert>
5#include <optional>
6#include <set>
7#include <variant>
8
11
12namespace nix {
13
18typedef std::string OutputName;
19
24typedef std::string_view OutputNameView;
25
27{
31 struct Names : std::set<OutputName, std::less<>>
32 {
33 private:
34 using BaseType = std::set<OutputName, std::less<>>;
35
36 public:
37 using BaseType::BaseType;
38
39 /* These need to be "inherited manually" */
40
41 Names(const BaseType & s)
42 : BaseType(s)
43 {
44 assert(!empty());
45 }
46
50 Names(BaseType && s)
51 : BaseType(std::move(s))
52 {
53 assert(!empty());
54 }
55
56 /* This set should always be non-empty, so we delete this
57 constructor in order make creating empty ones by mistake harder.
58 */
59 Names() = delete;
60 };
61
65 struct All : std::monostate
66 {};
67
68 typedef std::variant<All, Names> Raw;
69
70 Raw raw;
71
72 bool operator==(const OutputsSpec &) const = default;
73
74 // TODO libc++ 16 (used by darwin) missing `std::set::operator <=>`, can't do yet.
75 bool operator<(const OutputsSpec & other) const
76 {
77 return raw < other.raw;
78 }
79
81
85 OutputsSpec() = delete;
86
87 bool contains(const OutputName & output) const;
88
92 OutputsSpec union_(const OutputsSpec & that) const;
93
97 bool isSubsetOf(const OutputsSpec & outputs) const;
98
103 static OutputsSpec parse(std::string_view s);
104 static std::optional<OutputsSpec> parseOpt(std::string_view s);
105
106 std::string to_string() const;
107};
108
110{
111 struct Default : std::monostate
112 {};
113
114 using Explicit = OutputsSpec;
115
116 typedef std::variant<Default, Explicit> Raw;
117
118 Raw raw;
119
120 bool operator==(const ExtendedOutputsSpec &) const = default;
121 // TODO libc++ 16 (used by darwin) missing `std::set::operator <=>`, can't do yet.
122 bool operator<(const ExtendedOutputsSpec &) const;
123
124 MAKE_WRAPPER_CONSTRUCTOR(ExtendedOutputsSpec);
125
130
135 static std::pair<std::string_view, ExtendedOutputsSpec> parse(std::string_view s);
136 static std::optional<std::pair<std::string_view, ExtendedOutputsSpec>> parseOpt(std::string_view s);
137
138 std::string to_string() const;
139};
140
141} // namespace nix
142
143JSON_IMPL(nix::OutputsSpec)
std::string_view OutputNameView
Definition outputs-spec.hh:24
std::string OutputName
Definition outputs-spec.hh:18
Definition outputs-spec.hh:112
Definition outputs-spec.hh:110
static std::pair< std::string_view, ExtendedOutputsSpec > parse(std::string_view s)
Definition outputs-spec.cc:58
Definition outputs-spec.hh:66
Definition outputs-spec.hh:32
Names(BaseType &&s)
Definition outputs-spec.hh:50
Definition outputs-spec.hh:27
bool isSubsetOf(const OutputsSpec &outputs) const
Definition outputs-spec.cc:109
OutputsSpec union_(const OutputsSpec &that) const
Definition outputs-spec.cc:88
OutputsSpec()=delete
static OutputsSpec parse(std::string_view s)
Definition outputs-spec.cc:31
#define MAKE_WRAPPER_CONSTRUCTOR(CLASS_NAME)
Definition variant-wrapper.hh:49