DART 6.13.2
Loading...
Searching...
No Matches
Filesystem.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011-2022, The DART development contributors:
3 * https://github.com/dartsim/dart/blob/main/LICENSE
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#ifndef DART_COMMON_FILESYSTEM_HPP_
29#define DART_COMMON_FILESYSTEM_HPP_
30
32
33#if !defined(DART_INCLUDE_STD_FILESYSTEM_EXPERIMENTAL)
34
35 // Check for feature test macro for <filesystem>
36 #if defined(__cpp_lib_filesystem)
37 #define DART_INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 0
38
39 // Check for feature test macro for <experimental/filesystem>
40 #elif defined(__cpp_lib_experimental_filesystem)
41 #define DART_INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 1
42
43 // We can't check if headers exist...
44 // Let's assume experimental to be safe
45 #elif !defined(__has_include)
46 #define DART_INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 1
47
48 // Check if the header "<filesystem>" exists
49 #elif __has_include(<filesystem>)
50
51 // If we're compiling on Visual Studio and are not compiling with C++17, we
52 // need to use experimental
53 #ifdef _MSC_VER
54
55 // Check and include header that defines "_HAS_CXX17"
56 #if __has_include(<yvals_core.h>)
57 #include <yvals_core.h>
58
59 // Check for enabled C++17 support
60 #if defined(_HAS_CXX17) && _HAS_CXX17
61 // We're using C++17, so let's use the normal version
62 #define DART_INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 0
63 #endif
64 #endif
65
66 // If the marco isn't defined yet, that means any of the other VS specific
67 // checks failed, so we need to use experimental
68 #ifndef DART_INCLUDE_STD_FILESYSTEM_EXPERIMENTAL
69 #define DART_INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 1
70 #endif
71
72 // Not on Visual Studio. Let's use the normal version
73 #else // #ifdef _MSC_VER
74 #define DART_INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 0
75 #endif
76
77 // Check if the header "<filesystem>" exists
78 #elif __has_include(<experimental/filesystem>)
79 #define DART_INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 1
80
81 // Fail if neither header is available with a nice error message
82 #else
83 #error Could not find system header "<filesystem>" or "<experimental/filesystem>"
84 #endif
85
86 // We priously determined that we need the exprimental version
87 #if DART_INCLUDE_STD_FILESYSTEM_EXPERIMENTAL
88 // Include it
89 #include <experimental/filesystem>
90
91namespace dart::common {
92
93namespace filesystem = ::std::experimental::filesystem;
94using error_code = ::std::error_code;
95
96} // namespace dart::common
97
98 // We have a decent compiler and can use the normal version
99 #else
100 // Include it
101 #include <filesystem>
102
103namespace dart::common {
104namespace filesystem = ::std::filesystem;
105using error_code = ::std::error_code;
106} // namespace dart::common
107
108 #endif
109
110#endif // #ifndef DART_INCLUDE_STD_FILESYSTEM_EXPERIMENTAL
111
112#endif // #ifndef DART_COMMON_FILESYSTEM_HPP_
Definition Aspect.cpp:42
::std::error_code error_code
Definition Filesystem.hpp:94