crawlserv++  [under development]
Application for crawling and analyzing textual content of websites.
filesystem.h
Go to the documentation of this file.
1 /*
2  * ---
3  *
4  * Copyright (C) 2018 Yannick Schinko (aka BrainStone)
5  *
6  * See https://stackoverflow.com/a/53365539 .
7  *
8  * ---
9  *
10  * filesystem.h
11  *
12  * Selects the right head for std::filesystem and aliases it to the namespace "stdfs"
13  *
14  * Created on: Apr 18, 2020
15  * Author: ans
16  */
17 
18 #ifndef HELPER_PORTABILITY_FILESYSTEM_H_
19 #define HELPER_PORTABILITY_FILESYSTEM_H_
20 
21 // We haven't checked which filesystem to include yet
22 #ifndef INCLUDE_STD_FILESYSTEM_EXPERIMENTAL
23 
24 // Check for feature test macro for <filesystem>
25 # if defined(__cpp_lib_filesystem)
26 # define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 0
27 
28 // added by Ans: Check for clang-tidy
29 # elif defined(__clang_analyzer__)
30 # define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 1
31 // End of added by Ans
32 
33 // Check for feature test macro for <experimental/filesystem>
34 # elif defined(__cpp_lib_experimental_filesystem)
35 # define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 1
36 
37 // We can't check if headers exist...
38 // Let's assume experimental to be safe
39 # elif !defined(__has_include)
40 # define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 1
41 
42 // Check if the header "<filesystem>" exists
43 # elif __has_include(<filesystem>)
44 
45 // If we're compiling on Visual Studio and are not compiling with C++17, we need to use experimental
46 # ifdef _MSC_VER
47 
48 // Check and include header that defines "_HAS_CXX17"
49 # if __has_include(<yvals_core.h>)
50 # include <yvals_core.h>
51 
52 // Check for enabled C++17 support
53 # if defined(_HAS_CXX17) && _HAS_CXX17
54 // We're using C++17, so let's use the normal version
55 # define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 0
56 # endif
57 # endif
58 
59 // If the marco isn't defined yet, that means any of the other VS specific checks failed, so we need to use experimental
60 # ifndef INCLUDE_STD_FILESYSTEM_EXPERIMENTAL
61 # define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 1
62 # endif
63 
64 // Not on Visual Studio. Let's use the normal version
65 # else // #ifdef _MSC_VER
66 # define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 0
67 # endif
68 
69 // Check if the header "<filesystem>" exists
70 # elif __has_include(<experimental/filesystem>)
71 # define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 1
72 
73 // Fail if neither header is available with a nice error message
74 # else
75 # error Could not find system header "<filesystem>" or "<experimental/filesystem>"
76 # endif
77 
78 // We priously determined that we need the exprimental version
79 # if INCLUDE_STD_FILESYSTEM_EXPERIMENTAL
80 // Include it
81 # include <experimental/filesystem>
82 
83 // Alias it
84  namespace stdfs = std::experimental::filesystem;
85 
86 // We have a decent compiler and can use the normal version
87 # else
88 // Include it
89 # include <filesystem>
90 
91 // Alias it
92  namespace stdfs = std::filesystem;
93 # endif
94 
95 #endif // #ifndef INCLUDE_STD_FILESYSTEM_EXPERIMENTAL
96 
97 #endif /* HELPER_PORTABILITY_FILESYSTEM_H_ */