Nix 2.93.3
Lix: A modern, delicious implementation of the Nix 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#include "lix/libutil/json-fwd.hh"
13
14namespace nix {
15
20typedef std::string OutputName;
21
26typedef std::string_view OutputNameView;
27
32 struct Names : std::set<OutputName> {
33 using std::set<OutputName>::set;
34
35 /* These need to be "inherited manually" */
36
37 Names(const std::set<OutputName> & s)
38 : std::set<OutputName>(s)
39 { assert(!empty()); }
40
44 Names(std::set<OutputName> && s)
45 : std::set<OutputName>(s)
46 { assert(!empty()); }
47
48 /* This set should always be non-empty, so we delete this
49 constructor in order make creating empty ones by mistake harder.
50 */
51 Names() = delete;
52 };
53
57 struct All : std::monostate { };
58
59 typedef std::variant<All, Names> Raw;
60
61 Raw raw;
62
63 GENERATE_CMP(OutputsSpec, me->raw);
64
66
70 OutputsSpec() = delete;
71
72 bool contains(const OutputName & output) const;
73
77 OutputsSpec union_(const OutputsSpec & that) const;
78
82 bool isSubsetOf(const OutputsSpec & outputs) const;
83
88 static OutputsSpec parse(std::string_view s);
89 static std::optional<OutputsSpec> parseOpt(std::string_view s);
90
91 std::string to_string() const;
92
93 static void to_json(JSON & json, const OutputsSpec & t);
94 static OutputsSpec from_json(const JSON & json);
95};
96
98 struct Default : std::monostate { };
99 using Explicit = OutputsSpec;
100
101 typedef std::variant<Default, Explicit> Raw;
102
103 Raw raw;
104
106
108
113
118 static std::pair<std::string_view, ExtendedOutputsSpec> parse(std::string_view s);
119 static std::optional<std::pair<std::string_view, ExtendedOutputsSpec>> parseOpt(std::string_view s);
120
121 std::string to_string() const;
122
123 static void to_json(JSON & json, const ExtendedOutputsSpec & spec);
124 static ExtendedOutputsSpec from_json(const JSON & t);
125};
126
127}
#define GENERATE_CMP(args...)
Definition comparator.hh:65
std::string_view OutputNameView
Definition outputs-spec.hh:26
std::string OutputName
Definition outputs-spec.hh:20
Definition outputs-spec.hh:98
static std::pair< std::string_view, ExtendedOutputsSpec > parse(std::string_view s)
Definition outputs-spec.cc:72
Definition outputs-spec.hh:57
Definition outputs-spec.hh:32
Names(std::set< OutputName > &&s)
Definition outputs-spec.hh:44
Definition outputs-spec.hh:28
bool isSubsetOf(const OutputsSpec &outputs) const
Definition outputs-spec.cc:129
OutputsSpec union_(const OutputsSpec &that) const
Definition outputs-spec.cc:107
OutputsSpec()=delete
static OutputsSpec parse(std::string_view s)
Definition outputs-spec.cc:49
#define MAKE_WRAPPER_CONSTRUCTOR(CLASS_NAME)
Definition variant-wrapper.hh:27