mimic++
v10.0.1
Toggle main menu visibility
Loading...
Searching...
No Matches
PathPrinter.hpp
Go to the documentation of this file.
1
// Copyright Dominic (DNKpp) Koepke 2024 - 2025.
2
// Distributed under the Boost Software License, Version 1.0.
3
// (See accompanying file LICENSE_1_0.txt or copy at
4
// https://www.boost.org/LICENSE_1_0.txt)
5
6
#ifndef MIMICPP_PRINTING_PATH_PRINTER_HPP
7
#define MIMICPP_PRINTING_PATH_PRINTER_HPP
8
9
#pragma once
10
11
#include "
mimic++/Fwd.hpp
"
12
#include "
mimic++/config/Config.hpp
"
13
#include "
mimic++/printing/Format.hpp
"
14
15
#ifndef MIMICPP_DETAIL_IS_MODULE
16
#include <algorithm>
17
#include <filesystem>
18
#include <functional>
19
#include <utility>
20
#endif
21
22
namespace
mimicpp::printing::detail
23
{
24
constexpr
int
maxPathElements{3};
25
26
class
PathPrinterFn
27
{
28
public
:
29
template
<pr
int
_iterator OutIter>
30
OutIter operator()(OutIter out, std::filesystem::path
const
& path)
const
31
{
32
static
constexpr
CharT
separator{std::filesystem::path::preferred_separator};
33
34
auto
const
pathString = path.lexically_normal().string();
35
auto
const
rend = pathString.crend();
36
auto
iter = std::ranges::find(pathString.crbegin(), rend, separator);
37
for
(
int
i = 1;
38
i < maxPathElements
39
&& iter != rend;
40
++i, iter = std::ranges::find(iter, rend, separator))
41
{
42
++iter;
43
}
44
45
return
std::ranges::copy(iter.base(), pathString.cend(), std::move(out)).out;
46
}
47
48
[[nodiscard]]
49
StringT
operator()(std::filesystem::path
const
& path)
const
50
{
51
StringStreamT
stream{};
52
std::invoke(
53
*
this
,
54
std::ostreambuf_iterator{stream},
55
path);
56
return
std::move(stream).str();
57
}
58
};
59
}
60
61
MIMICPP_DETAIL_MODULE_EXPORT
namespace
mimicpp
62
{
72
76
[[maybe_unused]]
inline
constexpr
printing::detail::PathPrinterFn
print_path
{};
77
81
}
82
83
#endif
Config.hpp
MIMICPP_DETAIL_MODULE_EXPORT
#define MIMICPP_DETAIL_MODULE_EXPORT
Definition
Config.hpp:19
Format.hpp
Fwd.hpp
mimicpp::print_path
constexpr printing::detail::PathPrinterFn print_path
Functional object that outputs paths in a specific format.
Definition
PathPrinter.hpp:76
mimicpp
Definition
Call.hpp:24
mimicpp::CharT
char CharT
Definition
Fwd.hpp:395
mimicpp::StringStreamT
std::basic_ostringstream< CharT, CharTraitsT > StringStreamT
Definition
Format.hpp:38
mimicpp::StringT
std::basic_string< CharT, CharTraitsT > StringT
Definition
Fwd.hpp:397
mimic++
printing
PathPrinter.hpp
Generated on
for mimic++ by
1.18.0