Nix 2.26.3
Nix, the purely functional package manager; unstable internal interfaces
 
Loading...
Searching...
No Matches
path.hh
Go to the documentation of this file.
1#pragma once
3
4#include <string_view>
5
6#include "types.hh"
7
8namespace nix {
9
10struct Hash;
11
17void checkName(std::string_view name);
18
26class StorePath
27{
28 std::string baseName;
29
30public:
31
35 constexpr static size_t HashLen = 32; // i.e. 160 bits
36
37 constexpr static size_t MaxPathLen = 211;
38
39 StorePath() = delete;
40
42 StorePath(std::string_view baseName);
43
45 StorePath(const Hash & hash, std::string_view name);
46
47 std::string_view to_string() const noexcept
48 {
49 return baseName;
50 }
51
52 bool operator == (const StorePath & other) const noexcept = default;
53 auto operator <=> (const StorePath & other) const noexcept = default;
54
58 bool isDerivation() const noexcept;
59
63 void requireDerivation() const;
64
65 std::string_view name() const
66 {
67 return std::string_view(baseName).substr(HashLen + 1);
68 }
69
70 std::string_view hashPart() const
71 {
72 return std::string_view(baseName).substr(0, HashLen);
73 }
74
75 static StorePath dummy;
76
77 static StorePath random(std::string_view name);
78};
79
80typedef std::set<StorePath> StorePathSet;
81typedef std::vector<StorePath> StorePaths;
82
87constexpr std::string_view drvExtension = ".drv";
88
89}
90
91namespace std {
92
93template<> struct hash<nix::StorePath> {
94 std::size_t operator()(const nix::StorePath & path) const noexcept
95 {
96 return * (std::size_t *) path.to_string().data();
97 }
98};
99
100}
Definition path.hh:27
bool isDerivation() const noexcept
Definition path.cc:60
static constexpr size_t HashLen
Definition path.hh:35
void requireDerivation() const
Definition path.cc:65
const std::string_view & name
Definition lexer.l:1709
OsStringView string_view
Definition lexer.l:3789
std::string path
Definition lexer.l:1399
constexpr std::string_view drvExtension
Definition path.hh:87
Definition hash.hh:45