Doxygen
Toggle main menu visibility
Loading...
Searching...
No Matches
fswrapper.h
Go to the documentation of this file.
1
/******************************************************************************
2
*
3
* Copyright (C) 1997-2026 by Dimitri van Heesch.
4
*
5
* Permission to use, copy, modify, and distribute this software and its
6
* documentation under the terms of the GNU General Public License is hereby
7
* granted. No representations are made about the suitability of this software
8
* for any purpose. It is provided "as is" without express or implied warranty.
9
* See the GNU General Public License for more details.
10
*
11
* Documents produced by Doxygen are derivative works derived from the
12
* input used in their production; they are not affected by this license.
13
*
14
*/
15
16
#ifndef FSWRAPPER_H
17
#define FSWRAPPER_H
18
19
/** @file
20
* @brief Selects the filesystem implementation used by doxygen.
21
*
22
* The standard library's std::filesystem is used when it is available and
23
* usable without extra link libraries. Otherwise the bundled
24
* ghc::filesystem (deps/filesystem) is used as a fallback, in particular for:
25
* - GCC 8 / libstdc++ 8 (e.g. RHEL 8), where std::filesystem needs -lstdc++fs
26
* - LLVM libc++ before version 9, where it needs -lc++fs
27
* - macOS deployment targets before 10.15, which lack std::filesystem
28
*
29
* Defining DOXYGEN_USE_GHC_FILESYSTEM forces the use of ghc::filesystem.
30
*
31
* Doxygen uses UTF-8 encoded std::string paths everywhere. ghc::filesystem
32
* treats narrow strings as UTF-8 on all platforms, but std::filesystem uses
33
* the active (ANSI) code page on Windows. Always convert between strings and
34
* paths using toFsPath() and fromFsPath(), so non-ASCII file names keep
35
* working on Windows.
36
*/
37
38
#include <cstddef>
// defines _GLIBCXX_RELEASE / _LIBCPP_VERSION
39
#include <string>
40
41
#if !defined(DOXYGEN_USE_GHC_FILESYSTEM) && defined(__has_include)
42
# if __has_include(<filesystem>)
43
# if defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE < 9
44
// libstdc++ 8 (GCC 8): std::filesystem requires linking with -lstdc++fs
45
# elif defined(_LIBCPP_VERSION) && _LIBCPP_VERSION < 9000
46
// libc++ < 9: std::filesystem requires linking with -lc++fs
47
# elif defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500
48
// std::filesystem is only available from macOS 10.15 onwards
49
# else
50
# define DOXYGEN_USE_STD_FILESYSTEM 1
51
# endif
52
# endif
53
#endif
54
55
#if DOXYGEN_USE_STD_FILESYSTEM
56
# include <filesystem>
57
namespace
fs = std::filesystem;
58
#else
59
# include "filesystem.hpp"
60
namespace
fs = ghc::filesystem;
61
#endif
62
63
/** Converts a UTF-8 encoded string into a path. */
64
inline
fs::path
toFsPath
(
const
std::string &s)
65
{
66
#if DOXYGEN_USE_STD_FILESYSTEM && defined(_WIN32)
67
# if defined(__cpp_char8_t)
68
return
fs::path(std::u8string(s.begin(), s.end()));
69
# else
70
return
fs::u8path(s);
71
# endif
72
#else
73
return
fs::path(s);
74
#endif
75
}
76
77
/** Converts a path into a UTF-8 encoded string. */
78
inline
std::string
fromFsPath
(
const
fs::path &p)
79
{
80
#if DOXYGEN_USE_STD_FILESYSTEM && defined(_WIN32)
81
# if defined(__cpp_char8_t)
82
const
std::u8string s = p.u8string();
83
return
std::string(s.begin(), s.end());
84
# else
85
return
p.u8string();
86
# endif
87
#else
88
return
p.string();
89
#endif
90
}
91
92
#endif
// FSWRAPPER_H
fromFsPath
std::string fromFsPath(const fs::path &p)
Converts a path into a UTF-8 encoded string.
Definition
fswrapper.h:78
toFsPath
fs::path toFsPath(const std::string &s)
Converts a UTF-8 encoded string into a path.
Definition
fswrapper.h:64
src
fswrapper.h
Generated by
1.19.0