Nix
2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Toggle main menu visibility
Loading...
Searching...
No Matches
os-filename.hh
Go to the documentation of this file.
1
#pragma once
3
4
#include <filesystem>
5
6
namespace
nix {
7
21
class
OsFilename
22
{
23
std::filesystem::path name;
24
25
void
validateAssert()
const
noexcept
;
26
27
static
void
validateThrow(
const
std::filesystem::path & p);
28
33
OsFilename(std::filesystem::path p)
34
: name(std::move(p))
35
{
36
}
37
45
static
const
OsFilename & refFromPathUnchecked(
const
std::filesystem::path & p)
46
{
47
static_assert
(
sizeof
(OsFilename) ==
sizeof
(std::filesystem::path));
48
static_assert
(
alignof
(OsFilename) ==
alignof
(std::filesystem::path));
49
return
reinterpret_cast<
const
OsFilename &
>
(p);
50
}
51
52
/* `OsCanonPath::Iterator` uses `refFromPathUnchecked`: every
53
component of an `OsCanonPath` is already a valid filename. */
54
friend
class
OsCanonPath;
55
56
public
:
65
static
OsFilename
fromPathAsserting
(std::filesystem::path p)
66
{
67
auto
ret = OsFilename{std::move(p)};
68
ret.validateAssert();
69
return
ret;
70
}
71
79
static
OsFilename
fromPathThrowing
(std::filesystem::path p);
80
81
const
std::filesystem::path & path() const noexcept
82
{
83
return
name;
84
}
85
86
const
std::filesystem::path::value_type * c_str() const noexcept
87
{
88
return
name.c_str();
89
}
90
91
auto
operator<=>(
const
OsFilename &)
const
=
default
;
92
};
93
94
}
// namespace nix
nix::OsFilename
Definition
os-filename.hh:22
nix::OsFilename::fromPathAsserting
static OsFilename fromPathAsserting(std::filesystem::path p)
Definition
os-filename.hh:65
nix::OsFilename::fromPathThrowing
static OsFilename fromPathThrowing(std::filesystem::path p)
Definition
os-filename.cc:28
libutil
include
nix
util
os-filename.hh
Generated by
1.18.0