.. _program_listing_file_lib_utilities_filesystem.hpp: Program Listing for File filesystem.hpp ======================================= |exhale_lsh| :ref:`Return to documentation for file ` (``lib/utilities/filesystem.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp // --------------------------------------------------------------------- // This file is part of falcon-core. // // Copyright (C) 2015, 2016, 2017 Neuro-Electronics Research Flanders // // Falcon-server is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Falcon-server is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with falcon-core. If not, see . // --------------------------------------------------------------------- #pragma once #include // modified from https://stackoverflow.com/a/53365539 // We haven't checked which filesystem to include yet #ifndef INCLUDE_STD_FILESYSTEM_EXPERIMENTAL // Check for feature test macro for #if defined(__cpp_lib_filesystem) #define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 0 // Check for feature test macro for #elif defined(__cpp_lib_experimental_filesystem) #define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 1 // We can't check if headers exist... // Let's assume experimental to be safe #elif !defined(__has_include) #define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 1 // Check if the header "" exists #elif __has_include() // If we're compiling on Visual Studio and are not compiling with C++17, we need // to use experimental #ifdef _MSC_VER // Check and include header that defines "_HAS_CXX17" #if __has_include() #include // Check for enabled C++17 support #if defined(_HAS_CXX17) && _HAS_CXX17 // We're using C++17, so let's use the normal version #define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 0 #endif #endif // If the marco isn't defined yet, that means any of the other VS specific // checks failed, so we need to use experimental #ifndef INCLUDE_STD_FILESYSTEM_EXPERIMENTAL #define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 1 #endif // Not on Visual Studio. Let's use the normal version #else // #ifdef _MSC_VER #define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 0 #endif // Check if the header "" exists #elif __has_include() #define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 1 // Fail if neither header is available with a nice error message #else #error Could not find system header "" or "" #endif // We priously determined that we need the exprimental version #if INCLUDE_STD_FILESYSTEM_EXPERIMENTAL // Include it #include // We need the alias from std::experimental::filesystem to std::filesystem namespace fs = std::experimental::filesystem; // We have a decent compiler and can use the normal version #else // Include it #include namespace fs = std::filesystem; #endif #endif // #ifndef INCLUDE_STD_FILESYSTEM_EXPERIMENTAL #include std::string expand_home(const std::string &x); fs::path parse_directory(const std::string &x, bool exists = true, bool create = false); fs::path parse_file(const std::string &x, bool exists = false); std::vector getAllFilesInDir(const std::string &dirPath);