2023-09-02 17:35:16 -04:00
|
|
|
#pragma once
|
|
|
|
///@file
|
|
|
|
|
|
|
|
#include <optional>
|
|
|
|
#include <filesystem>
|
|
|
|
|
|
|
|
#include "types.hh"
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Paths are just `std::filesystem::path`s.
|
|
|
|
*
|
|
|
|
* @todo drop `NG` suffix and replace the ones in `types.hh`.
|
|
|
|
*/
|
2024-05-08 03:58:50 +05:30
|
|
|
typedef std::list<std::filesystem::path> PathsNG;
|
|
|
|
typedef std::set<std::filesystem::path> PathSetNG;
|
2023-09-02 17:35:16 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Stop gap until `std::filesystem::path_view` from P1030R6 exists in a
|
|
|
|
* future C++ standard.
|
|
|
|
*
|
|
|
|
* @todo drop `NG` suffix and replace the one in `types.hh`.
|
|
|
|
*/
|
2024-05-08 03:58:50 +05:30
|
|
|
struct PathViewNG : std::basic_string_view<std::filesystem::path::value_type>
|
2023-09-02 17:35:16 -04:00
|
|
|
{
|
2024-05-08 03:58:50 +05:30
|
|
|
using string_view = std::basic_string_view<std::filesystem::path::value_type>;
|
2023-09-02 17:35:16 -04:00
|
|
|
|
|
|
|
using string_view::string_view;
|
|
|
|
|
2024-05-08 03:58:50 +05:30
|
|
|
PathViewNG(const std::filesystem::path & path)
|
|
|
|
: std::basic_string_view<std::filesystem::path::value_type>(path.native())
|
2023-09-02 17:35:16 -04:00
|
|
|
{ }
|
|
|
|
|
2024-05-08 03:58:50 +05:30
|
|
|
PathViewNG(const std::filesystem::path::string_type & path)
|
|
|
|
: std::basic_string_view<std::filesystem::path::value_type>(path)
|
2023-09-02 17:35:16 -04:00
|
|
|
{ }
|
|
|
|
|
|
|
|
const string_view & native() const { return *this; }
|
|
|
|
string_view & native() { return *this; }
|
|
|
|
};
|
|
|
|
|
|
|
|
std::string os_string_to_string(PathViewNG::string_view path);
|
|
|
|
|
2024-05-08 03:58:50 +05:30
|
|
|
std::filesystem::path::string_type string_to_os_string(std::string_view s);
|
2023-09-02 17:35:16 -04:00
|
|
|
|
2024-05-08 03:58:50 +05:30
|
|
|
std::optional<std::filesystem::path> maybePath(PathView path);
|
2023-09-02 17:35:16 -04:00
|
|
|
|
2024-05-08 03:58:50 +05:30
|
|
|
std::filesystem::path pathNG(PathView path);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create string literals with the native character width of paths
|
|
|
|
*/
|
|
|
|
#ifndef _WIN32
|
|
|
|
# define PATHNG_LITERAL(s) s
|
|
|
|
#else
|
|
|
|
# define PATHNG_LITERAL(s) L ## s
|
|
|
|
#endif
|
2023-09-02 17:35:16 -04:00
|
|
|
|
|
|
|
}
|