.. _program_listing_file_include_depthai_utility_Path.hpp: Program Listing for File Path.hpp ================================= |exhale_lsh| :ref:`Return to documentation for file ` (``include/depthai/utility/Path.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #pragma once #if(__cplusplus >= 201703L) || (_MSVC_LANG >= 201703L) #define DEPTHAI_NODISCARD [[nodiscard]] #if(defined(_MSC_VER)) || (defined(__has_include) && __has_include()) || (__cplusplus >= 202002L) #include #endif #else #define DEPTHAI_NODISCARD #endif #include namespace dai { // TODO C++20 char8_t // TODO test if caller works when replace "dai::Path" -> "std::filesystem::path" // TODO test if can `using dai::Path = std::filesystem::path` on C++17 to completely use STL class Path { public: #if defined(_WIN32) && defined(_MSC_VER) using value_type = wchar_t; #else using value_type = char; #endif using string_type = std::basic_string; Path() = default; ~Path() = default; Path(const Path&) = default; Path(Path&&) = default; Path& operator=(const Path&) = default; Path& operator=(Path&&) = default; Path(string_type&& source) noexcept : _nativePath(std::move(source)) {} Path(const string_type& source) : _nativePath(source) {} Path(const value_type* source) : _nativePath(string_type(source)) {} #if defined(__cpp_lib_filesystem) Path(const std::filesystem::path& source) : _nativePath(source) {} #if defined(__cpp_lib_char8_t) Path(const std::u8string& source) : Path(std::filesystem::path(source)) {} Path(const char8_t* source) : Path(std::filesystem::path(source)) {} #endif #endif #if defined(_WIN32) && defined(_MSC_VER) private: static std::wstring convert_utf8_to_wide(const std::string& utf8string); public: Path(const std::string& source) : _nativePath(convert_utf8_to_wide(source)) {} Path(const char* source) : _nativePath(convert_utf8_to_wide(std::string(source))) {} std::string string() const; #if defined(__cpp_lib_char8_t) std::u8string u8string() const { return std::filesystem::path(_nativePath).u8string(); } #else std::string u8string() const; #endif #else std::string string() const { return _nativePath; } #if defined(__cpp_lib_char8_t) std::u8string u8string() const { return std::filesystem::path(_nativePath).u8string(); } #else std::string u8string() const { return _nativePath; } #endif #endif operator string_type() const noexcept { return _nativePath; } const string_type& native() const noexcept { return _nativePath; } // TODO add back DEPTHAI_NODISCARD once sphinx fixes are in place bool empty() const noexcept { return _nativePath.empty(); } private: string_type _nativePath; }; } // namespace dai