Nix 2.26.3
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
9#include "json-impls.hh"
10#include "variant-wrapper.hh"
11
12namespace nix {
13
18typedef std::string OutputName;
19
24typedef std::string_view OutputNameView;
25
30 struct Names : std::set<OutputName> {
31 using std::set<OutputName>::set;
32
33 /* These need to be "inherited manually" */
34
35 Names(const std::set<OutputName> & s)
36 : std::set<OutputName>(s)
37 { assert(!empty()); }
38
42 Names(std::set<OutputName> && s)
43 : std::set<OutputName>(s)
44 { assert(!empty()); }
45
46 /* This set should always be non-empty, so we delete this
47 constructor in order make creating empty ones by mistake harder.
48 */
49 Names() = delete;
50 };
51
55 struct All : std::monostate { };
56
57 typedef std::variant<All, Names> Raw;
58
59 Raw raw;
60
61 bool operator == (const OutputsSpec &) const = default;
62 // TODO libc++ 16 (used by darwin) missing `std::set::operator <=>`, can't do yet.
63 bool operator < (const OutputsSpec & other) const {
64 return raw < other.raw;
65 }
66
67 MAKE_WRAPPER_CONSTRUCTOR(OutputsSpec);
68
72 OutputsSpec() = delete;
73
74 bool contains(const OutputName & output) const;
75
79 OutputsSpec union_(const OutputsSpec & that) const;
80
84 bool isSubsetOf(const OutputsSpec & outputs) const;
85
90 static OutputsSpec parse(std::string_view s);
91 static std::optional<OutputsSpec> parseOpt(std::string_view s);
92
93 std::string to_string() const;
94};
95
97 struct Default : std::monostate { };
98 using Explicit = OutputsSpec;
99
100 typedef std::variant<Default, Explicit> Raw;
101
102 Raw raw;
103
104 bool operator == (const ExtendedOutputsSpec &) const = default;
105 // TODO libc++ 16 (used by darwin) missing `std::set::operator <=>`, can't do yet.
106 bool operator < (const ExtendedOutputsSpec &) const;
107
108 MAKE_WRAPPER_CONSTRUCTOR(ExtendedOutputsSpec);
109
114
119 static std::pair<std::string_view, ExtendedOutputsSpec> parse(std::string_view s);
120 static std::optional<std::pair<std::string_view, ExtendedOutputsSpec>> parseOpt(std::string_view s);
121
122 std::string to_string() const;
123};
124
125}
126
127JSON_IMPL(OutputsSpec)
128JSON_IMPL(ExtendedOutputsSpec)
return s
Definition lexer.l:459
std::string_view OutputNameView
Definition outputs-spec.hh:24
std::string OutputName
Definition outputs-spec.hh:18
Definition outputs-spec.hh:97
static std::pair< std::string_view, ExtendedOutputsSpec > parse(std::string_view s)
Definition outputs-spec.cc:70
Definition outputs-spec.hh:55
Definition outputs-spec.hh:30
Names(std::set< OutputName > &&s)
Definition outputs-spec.hh:42
Definition outputs-spec.hh:26
bool isSubsetOf(const OutputsSpec &outputs) const
Definition outputs-spec.cc:127
OutputsSpec union_(const OutputsSpec &that) const
Definition outputs-spec.cc:105
OutputsSpec()=delete
static OutputsSpec parse(std::string_view s)
Definition outputs-spec.cc:47