Nix 2.26.3
Nix, the purely functional package manager; unstable internal interfaces
 
Loading...
Searching...
No Matches
types.hh
Go to the documentation of this file.
1#pragma once
3
4
5#include <list>
6#include <set>
7#include <string>
8#include <map>
9#include <variant>
10#include <vector>
11
12namespace nix {
13
14typedef std::list<std::string> Strings;
15typedef std::set<std::string> StringSet;
16typedef std::map<std::string, std::string> StringMap;
17typedef std::map<std::string, std::string> StringPairs;
18
22typedef std::string Path;
23typedef std::string_view PathView;
24typedef std::list<Path> Paths;
25typedef std::set<Path> PathSet;
26
27typedef std::vector<std::pair<std::string, std::string>> Headers;
28
32template<typename T>
33struct OnStartup
34{
35 OnStartup(T && t) { t(); }
36};
37
42template<typename T>
43struct Explicit {
44 T t;
45
46 bool operator ==(const Explicit<T> & other) const = default;
47
48 bool operator <(const Explicit<T> & other) const
49 {
50 return t < other.t;
51 }
52};
53
54
65class BackedStringView {
66private:
67 std::variant<std::string, std::string_view> data;
68
74 class Ptr {
75 private:
76 std::string_view view;
77 public:
78 Ptr(std::string_view view): view(view) {}
79 const std::string_view * operator->() const { return &view; }
80 };
81
82public:
83 BackedStringView(std::string && s): data(std::move(s)) {}
84 BackedStringView(std::string_view sv): data(sv) {}
85 template<size_t N>
86 BackedStringView(const char (& lit)[N]): data(std::string_view(lit)) {}
87
88 BackedStringView(const BackedStringView &) = delete;
89 BackedStringView & operator=(const BackedStringView &) = delete;
90
95 BackedStringView(BackedStringView && other) = default;
96 BackedStringView & operator=(BackedStringView && other) = default;
97
98 bool isOwned() const
99 {
100 return std::holds_alternative<std::string>(data);
101 }
102
103 std::string toOwned() &&
104 {
105 return isOwned()
106 ? std::move(std::get<std::string>(data))
107 : std::string(std::get<std::string_view>(data));
108 }
109
110 std::string_view operator*() const
111 {
112 return isOwned()
113 ? std::get<std::string>(data)
114 : std::get<std::string_view>(data);
115 }
116 Ptr operator->() const { return Ptr(**this); }
117};
118
119}
BackedStringView(BackedStringView &&other)=default
return s
Definition lexer.l:459
OsStringView string_view
Definition lexer.l:3789
std::variant< std::string, std::string_view > data
Definition lexer.l:177
T t
Definition lexer.l:154
Definition types.hh:43
std::string Path
Definition types.hh:22