summaryrefslogtreecommitdiffstats
path: root/include/ingen/FilePath.hpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2022-12-13 01:16:41 -0500
committerDavid Robillard <d@drobilla.net>2022-12-14 18:04:27 -0500
commit4b56cdf7a925dafd5e4ac085874d2afe294ec456 (patch)
treeb0fd7ab1b58c1cc4eb4ec0f211b3221522ea2a7f /include/ingen/FilePath.hpp
parentf6ee1ce7bb45d0f6267b2dad61f6b87c79a5906c (diff)
downloadingen-4b56cdf7a925dafd5e4ac085874d2afe294ec456.tar.gz
ingen-4b56cdf7a925dafd5e4ac085874d2afe294ec456.tar.bz2
ingen-4b56cdf7a925dafd5e4ac085874d2afe294ec456.zip
Use std::filesystem and std::make_unique
Diffstat (limited to 'include/ingen/FilePath.hpp')
-rw-r--r--include/ingen/FilePath.hpp108
1 files changed, 3 insertions, 105 deletions
diff --git a/include/ingen/FilePath.hpp b/include/ingen/FilePath.hpp
index 6f0266a7..ce157d90 100644
--- a/include/ingen/FilePath.hpp
+++ b/include/ingen/FilePath.hpp
@@ -1,6 +1,6 @@
/*
This file is part of Ingen.
- Copyright 2018 David Robillard <http://drobilla.net/>
+ Copyright 2018-2020 David Robillard <http://drobilla.net/>
Ingen is free software: you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free
@@ -17,113 +17,11 @@
#ifndef INGEN_FILEPATH_HPP
#define INGEN_FILEPATH_HPP
-#include "ingen/ingen.h"
-
-#include <boost/utility/string_view.hpp> // IWYU pragma: export
-
-#include <cstddef>
-#include <ostream>
-#include <string>
-#include <utility>
-
-#ifndef USE_WINDOWS_FILE_PATHS
-# if defined(_WIN32) && !defined(__CYGWIN__)
-# define USE_WINDOWS_FILE_PATHS 1
-# else
-# define USE_WINDOWS_FILE_PATHS 0
-# endif
-#endif
+#include <filesystem>
namespace ingen {
-/** A path to a file.
- *
- * This is a minimal subset of the std::filesystem::path interface in C++17.
- * Support for Windows paths is only partial and there is no support for
- * character encoding conversion at all.
- */
-class INGEN_API FilePath
-{
-public:
-#if USE_WINDOWS_FILE_PATHS
- using value_type = wchar_t;
- static constexpr value_type preferred_separator = L'\\';
-#else
- using value_type = char;
- static constexpr value_type preferred_separator = '/';
-#endif
-
- using string_type = std::basic_string<value_type>;
-
- FilePath() = default;
- FilePath(const FilePath&) = default;
- FilePath(FilePath&&) = default;
-
- FilePath(string_type str) : _str(std::move(str)) {}
- FilePath(const value_type* str) : _str(str) {}
- FilePath(const boost::basic_string_view<value_type>& sv)
- : _str(sv.data(), sv.length())
- {}
-
- ~FilePath() = default;
-
- FilePath& operator=(const FilePath& path) = default;
- FilePath& operator=(FilePath&& path) noexcept;
- FilePath& operator=(string_type&& str);
-
- FilePath& operator/=(const FilePath& path);
-
- FilePath& operator+=(const FilePath& path);
- FilePath& operator+=(const string_type& str);
- FilePath& operator+=(const value_type* str);
- FilePath& operator+=(value_type chr);
- FilePath& operator+=(boost::basic_string_view<value_type> sv);
-
- void clear() noexcept { _str.clear(); }
-
- const string_type& native() const noexcept { return _str; }
- const string_type& string() const noexcept { return _str; }
- const value_type* c_str() const noexcept { return _str.c_str(); }
-
- operator string_type() const { return _str; }
-
- static FilePath root_name();
-
- FilePath root_directory() const;
- FilePath root_path() const;
- FilePath relative_path() const;
- FilePath parent_path() const;
- FilePath filename() const;
- FilePath stem() const;
- FilePath extension() const;
-
- bool empty() const noexcept { return _str.empty(); }
-
- bool is_absolute() const;
- bool is_relative() const { return !is_absolute(); }
-
-private:
- std::size_t find_first_sep() const;
- std::size_t find_last_sep() const;
-
- string_type _str;
-};
-
-INGEN_API bool operator==(const FilePath& lhs, const FilePath& rhs) noexcept;
-INGEN_API bool operator!=(const FilePath& lhs, const FilePath& rhs) noexcept;
-INGEN_API bool operator<(const FilePath& lhs, const FilePath& rhs) noexcept;
-INGEN_API bool operator<=(const FilePath& lhs, const FilePath& rhs) noexcept;
-INGEN_API bool operator>(const FilePath& lhs, const FilePath& rhs) noexcept;
-INGEN_API bool operator>=(const FilePath& lhs, const FilePath& rhs) noexcept;
-
-INGEN_API FilePath operator/(const FilePath& lhs, const FilePath& rhs);
-
-template <typename Char, typename Traits>
-std::basic_ostream<Char, Traits>&
-operator<<(std::basic_ostream<Char, Traits>& os, const FilePath& path)
-{
- return os << path.string();
-}
+using FilePath = std::filesystem::path;
} // namespace ingen